HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / PitrCfgCustomizerTest.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.mockito.Matchers.any;
21 import static org.mockito.Mockito.mock;
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 java.util.concurrent.ExecutionException;
29 import org.junit.Test;
30 import org.mockito.ArgumentCaptor;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.pitr.cfg.grouping.PitrCfg;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.pitr.cfg.grouping.PitrCfgBuilder;
33 import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSet;
34 import io.fd.vpp.jvpp.core.dto.LispPitrSetLocatorSetReply;
35
36
37 public class PitrCfgCustomizerTest extends WriterCustomizerTest {
38
39     private PitrCfgCustomizer customizer;
40
41     @Override
42     public void setUp() {
43         customizer = new PitrCfgCustomizer(api);
44     }
45
46     private void whenLispPitrSetLocatorSetThenSuccess() {
47         when(api.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(future(new LispPitrSetLocatorSetReply()));
48     }
49
50     @Test(expected = NullPointerException.class)
51     public void testWriteCurrentAttributesNullData() throws WriteFailedException {
52         customizer.writeCurrentAttributes(null, null, null);
53     }
54
55     @Test(expected = NullPointerException.class)
56     public void testWriteCurrentAttributesBadData() throws WriteFailedException {
57         customizer.writeCurrentAttributes(null, mock(PitrCfg.class), null);
58     }
59
60     @Test
61     public void testWriteCurrentAttributes() throws WriteFailedException {
62         PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
63
64         whenLispPitrSetLocatorSetThenSuccess();
65         customizer.writeCurrentAttributes(null, cfg, null);
66
67         ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
68         verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
69
70         LispPitrSetLocatorSet request = cfgCaptor.getValue();
71         assertEquals(1, request.isAdd);
72         assertEquals("Locator", new String(request.lsName));
73     }
74
75     @Test
76     public void testUpdateCurrentAttributes() throws WriteFailedException {
77         PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
78
79         whenLispPitrSetLocatorSetThenSuccess();
80
81         customizer.writeCurrentAttributes(null, cfg, null);
82
83         ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
84         verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
85
86         LispPitrSetLocatorSet request = cfgCaptor.getValue();
87         assertEquals(1, request.isAdd);
88         assertEquals("Locator", new String(request.lsName));
89     }
90
91     @Test(expected = NullPointerException.class)
92     public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
93         customizer.deleteCurrentAttributes(null, null, null);
94     }
95
96     @Test(expected = NullPointerException.class)
97     public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
98         customizer.deleteCurrentAttributes(null, mock(PitrCfg.class), null);
99     }
100
101     @Test
102     public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
103         PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
104
105         whenLispPitrSetLocatorSetThenSuccess();
106
107         customizer.deleteCurrentAttributes(null, cfg, null);
108
109         ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
110         verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
111
112         LispPitrSetLocatorSet request = cfgCaptor.getValue();
113         assertEquals(0, request.isAdd);
114         assertEquals("Locator", new String(request.lsName));
115     }
116
117 }