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.mock;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
27 import com.google.common.base.Optional;
28 import com.google.common.collect.ImmutableList;
29 import io.fd.honeycomb.translate.vpp.util.NamingContext;
30 import io.fd.honeycomb.translate.write.WriteFailedException;
31 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
32 import java.nio.charset.StandardCharsets;
33 import java.util.Arrays;
34 import java.util.concurrent.ExecutionException;
35 import org.junit.Test;
36 import org.mockito.ArgumentCaptor;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSets;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.locator.set.InterfaceBuilder;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSet;
44 import io.fd.vpp.jvpp.core.dto.LispAddDelLocatorSetReply;
45 import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetails;
46 import io.fd.vpp.jvpp.core.dto.LispLocatorSetDetailsReplyDump;
48 public class LocatorSetCustomizerTest extends WriterCustomizerTest {
50 private LocatorSetCustomizer customizer;
54 customizer = new LocatorSetCustomizer(api, new NamingContext("locator-set", "instance"));
57 @Test(expected = NullPointerException.class)
58 public void testWriteCurrentAttributesNullData() throws WriteFailedException {
59 customizer.writeCurrentAttributes(null, null, null);
62 @Test(expected = NullPointerException.class)
63 public void testWriteCurrentAttributesBadData() throws WriteFailedException {
64 customizer.writeCurrentAttributes(null, mock(LocatorSet.class), null);
68 public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
69 LocatorSet locatorSet = new LocatorSetBuilder()
71 .setInterface(Arrays.asList(new InterfaceBuilder().build()))
74 InstanceIdentifier<LocatorSet> validId =
75 InstanceIdentifier.create(LocatorSets.class).child(LocatorSet.class, new LocatorSetKey("Locator"));
78 ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
80 when(api.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class))).thenReturn(future(new LispAddDelLocatorSetReply()));
81 when(writeContext.readAfter(validId)).thenReturn(Optional.of(locatorSet));
83 final LispLocatorSetDetailsReplyDump reply = new LispLocatorSetDetailsReplyDump();
84 LispLocatorSetDetails details = new LispLocatorSetDetails();
85 details.lsName = "Locator".getBytes(StandardCharsets.UTF_8);
86 reply.lispLocatorSetDetails = ImmutableList.of(details);
88 cache.put(io.fd.honeycomb.lisp.translate.read.LocatorSetCustomizer.LOCATOR_SETS_CACHE_ID, reply);
90 customizer.writeCurrentAttributes(validId, locatorSet, writeContext);
92 verify(api, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
94 LispAddDelLocatorSet request = locatorSetCaptor.getValue();
96 assertNotNull(request);
97 assertEquals("Locator", new String(request.locatorSetName));
98 assertEquals(1, request.isAdd);
101 @Test(expected = UnsupportedOperationException.class)
102 public void testUpdateCurrentAttributes() throws WriteFailedException {
103 customizer.updateCurrentAttributes(null, null, null, null);
106 @Test(expected = NullPointerException.class)
107 public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
108 customizer.deleteCurrentAttributes(null, null, null);
111 @Test(expected = NullPointerException.class)
112 public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
113 customizer.deleteCurrentAttributes(null, mock(LocatorSet.class), null);
117 public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
118 LocatorSet locatorSet = new LocatorSetBuilder()
122 ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
124 when(api.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class))).thenReturn(future(new LispAddDelLocatorSetReply()));
126 customizer.deleteCurrentAttributes(null, locatorSet, writeContext);
128 verify(api, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
130 LispAddDelLocatorSet request = locatorSetCaptor.getValue();
132 assertNotNull(request);
133 assertEquals("Locator", new String(request.locatorSetName));
134 assertEquals(0, request.isAdd);