de491e40b1091e1259103e499860affb90af6890
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / LispCustomizerTest.java
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.lisp.translate.write;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Mockito.times;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
25
26 import io.fd.honeycomb.translate.write.WriteFailedException;
27 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
28 import org.junit.Test;
29 import org.mockito.ArgumentCaptor;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispBuilder;
32 import io.fd.vpp.jvpp.core.dto.LispEnableDisable;
33 import io.fd.vpp.jvpp.core.dto.LispEnableDisableReply;
34
35
36 public class LispCustomizerTest extends WriterCustomizerTest {
37
38     private LispCustomizer customizer;
39
40     @Override
41     public void setUp() {
42         customizer = new LispCustomizer(api);
43     }
44
45     private void whenlispEnableDisableThenSuccess() {
46         when(api.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(future(new LispEnableDisableReply()));
47     }
48
49     @Test(expected = NullPointerException.class)
50     public void testWriteCurrentAttributesNullData() throws WriteFailedException {
51         customizer.writeCurrentAttributes(null, null, null);
52     }
53
54     @Test
55     public void testWriteCurrentAttributes() throws WriteFailedException {
56         Lisp intf = new LispBuilder().setEnable(true).build();
57
58         whenlispEnableDisableThenSuccess();
59         customizer.writeCurrentAttributes(null, intf, null);
60
61         ArgumentCaptor<LispEnableDisable> mappingCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
62         verify(api, times(1)).lispEnableDisable(mappingCaptor.capture());
63
64         LispEnableDisable request = mappingCaptor.getValue();
65
66         assertNotNull(request);
67         assertEquals(1, request.isEn);
68     }
69
70     @Test(expected = NullPointerException.class)
71     public void testUpdateCurrentAttributesNullData() throws WriteFailedException {
72         customizer.updateCurrentAttributes(null, null, null, null);
73     }
74
75     @Test
76     public void testUpdateCurrentAttributes() throws WriteFailedException {
77         Lisp lisp = new LispBuilder().setEnable(true).build();
78
79         whenlispEnableDisableThenSuccess();
80         customizer.updateCurrentAttributes(null, null, lisp, null);
81
82         ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
83         verify(api, times(1)).lispEnableDisable(lispCaptor.capture());
84
85         LispEnableDisable request = lispCaptor.getValue();
86
87         assertNotNull(request);
88         assertEquals(1, request.isEn);
89     }
90
91     @Test(expected = NullPointerException.class)
92     public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
93         customizer.deleteCurrentAttributes(null, null, null);
94     }
95
96     @Test
97     public void testDeleteCurrentAttributes() throws WriteFailedException {
98         Lisp lisp = new LispBuilder().setEnable(true).build();
99
100         whenlispEnableDisableThenSuccess();
101         customizer.deleteCurrentAttributes(null, lisp, null);
102
103         ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
104         verify(api, times(1)).lispEnableDisable(lispCaptor.capture());
105
106         LispEnableDisable request = lispCaptor.getValue();
107
108         assertNotNull(request);
109         assertEquals(0, request.isEn);
110     }
111 }