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.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;
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;
36 public class LispCustomizerTest extends WriterCustomizerTest {
38 private LispCustomizer customizer;
42 customizer = new LispCustomizer(api);
45 private void whenlispEnableDisableThenSuccess() {
46 when(api.lispEnableDisable(any(LispEnableDisable.class))).thenReturn(future(new LispEnableDisableReply()));
49 @Test(expected = NullPointerException.class)
50 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
51 customizer.writeCurrentAttributes(null, null, null);
55 public void testWriteCurrentAttributes() throws WriteFailedException {
56 Lisp intf = new LispBuilder().setEnable(true).build();
58 whenlispEnableDisableThenSuccess();
59 customizer.writeCurrentAttributes(null, intf, null);
61 ArgumentCaptor<LispEnableDisable> mappingCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
62 verify(api, times(1)).lispEnableDisable(mappingCaptor.capture());
64 LispEnableDisable request = mappingCaptor.getValue();
66 assertNotNull(request);
67 assertEquals(1, request.isEn);
70 @Test(expected = NullPointerException.class)
71 public void testUpdateCurrentAttributesNullData() throws WriteFailedException {
72 customizer.updateCurrentAttributes(null, null, null, null);
76 public void testUpdateCurrentAttributes() throws WriteFailedException {
77 Lisp lisp = new LispBuilder().setEnable(true).build();
79 whenlispEnableDisableThenSuccess();
80 customizer.updateCurrentAttributes(null, null, lisp, null);
82 ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
83 verify(api, times(1)).lispEnableDisable(lispCaptor.capture());
85 LispEnableDisable request = lispCaptor.getValue();
87 assertNotNull(request);
88 assertEquals(1, request.isEn);
91 @Test(expected = NullPointerException.class)
92 public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
93 customizer.deleteCurrentAttributes(null, null, null);
97 public void testDeleteCurrentAttributes() throws WriteFailedException {
98 Lisp lisp = new LispBuilder().setEnable(true).build();
100 whenlispEnableDisableThenSuccess();
101 customizer.deleteCurrentAttributes(null, lisp, null);
103 ArgumentCaptor<LispEnableDisable> lispCaptor = ArgumentCaptor.forClass(LispEnableDisable.class);
104 verify(api, times(1)).lispEnableDisable(lispCaptor.capture());
106 LispEnableDisable request = lispCaptor.getValue();
108 assertNotNull(request);
109 assertEquals(0, request.isEn);