2 * Copyright (c) 2015 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.lisp.translate.write;
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;
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;
37 public class PitrCfgCustomizerTest extends WriterCustomizerTest {
39 private PitrCfgCustomizer customizer;
43 customizer = new PitrCfgCustomizer(api);
46 private void whenLispPitrSetLocatorSetThenSuccess() {
47 when(api.lispPitrSetLocatorSet(any(LispPitrSetLocatorSet.class))).thenReturn(future(new LispPitrSetLocatorSetReply()));
50 @Test(expected = NullPointerException.class)
51 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
52 customizer.writeCurrentAttributes(null, null, null);
55 @Test(expected = NullPointerException.class)
56 public void testWriteCurrentAttributesBadData() throws WriteFailedException {
57 customizer.writeCurrentAttributes(null, mock(PitrCfg.class), null);
61 public void testWriteCurrentAttributes() throws WriteFailedException {
62 PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
64 whenLispPitrSetLocatorSetThenSuccess();
65 customizer.writeCurrentAttributes(null, cfg, null);
67 ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
68 verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
70 LispPitrSetLocatorSet request = cfgCaptor.getValue();
71 assertEquals(1, request.isAdd);
72 assertEquals("Locator", new String(request.lsName));
76 public void testUpdateCurrentAttributes() throws WriteFailedException {
77 PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
79 whenLispPitrSetLocatorSetThenSuccess();
81 customizer.writeCurrentAttributes(null, cfg, null);
83 ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
84 verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
86 LispPitrSetLocatorSet request = cfgCaptor.getValue();
87 assertEquals(1, request.isAdd);
88 assertEquals("Locator", new String(request.lsName));
91 @Test(expected = NullPointerException.class)
92 public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
93 customizer.deleteCurrentAttributes(null, null, null);
96 @Test(expected = NullPointerException.class)
97 public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
98 customizer.deleteCurrentAttributes(null, mock(PitrCfg.class), null);
102 public void testDeleteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
103 PitrCfg cfg = new PitrCfgBuilder().setLocatorSet("Locator").build();
105 whenLispPitrSetLocatorSetThenSuccess();
107 customizer.deleteCurrentAttributes(null, cfg, null);
109 ArgumentCaptor<LispPitrSetLocatorSet> cfgCaptor = ArgumentCaptor.forClass(LispPitrSetLocatorSet.class);
110 verify(api, times(1)).lispPitrSetLocatorSet(cfgCaptor.capture());
112 LispPitrSetLocatorSet request = cfgCaptor.getValue();
113 assertEquals(0, request.isAdd);
114 assertEquals("Locator", new String(request.lsName));