HONEYCOMB-154: update revison of models that changed since 16.09
[honeycomb.git] / lisp / lisp2vpp / src / test / java / io / fd / honeycomb / lisp / translate / write / LocatorSetCustomizerTest.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.mock;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26
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.rev161214.locator.sets.grouping.LocatorSets;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSet;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.locator.sets.grouping.locator.sets.LocatorSetKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.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;
47
48 public class LocatorSetCustomizerTest extends WriterCustomizerTest {
49
50     private LocatorSetCustomizer customizer;
51
52     @Override
53     public void setUp() {
54         customizer = new LocatorSetCustomizer(api, new NamingContext("locator-set", "instance"));
55     }
56
57     @Test(expected = NullPointerException.class)
58     public void testWriteCurrentAttributesNullData() throws WriteFailedException {
59         customizer.writeCurrentAttributes(null, null, null);
60     }
61
62     @Test(expected = NullPointerException.class)
63     public void testWriteCurrentAttributesBadData() throws WriteFailedException {
64         customizer.writeCurrentAttributes(null, mock(LocatorSet.class), null);
65     }
66
67     @Test
68     public void testWriteCurrentAttributes() throws WriteFailedException, InterruptedException, ExecutionException {
69         LocatorSet locatorSet = new LocatorSetBuilder()
70                 .setName("Locator")
71                 .setInterface(Arrays.asList(new InterfaceBuilder().build()))
72                 .build();
73
74         InstanceIdentifier<LocatorSet> validId =
75                 InstanceIdentifier.create(LocatorSets.class).child(LocatorSet.class, new LocatorSetKey("Locator"));
76
77
78         ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
79
80         when(api.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class))).thenReturn(future(new LispAddDelLocatorSetReply()));
81         when(writeContext.readAfter(validId)).thenReturn(Optional.of(locatorSet));
82
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);
87
88         cache.put(io.fd.honeycomb.lisp.translate.read.LocatorSetCustomizer.LOCATOR_SETS_CACHE_ID, reply);
89
90         customizer.writeCurrentAttributes(validId, locatorSet, writeContext);
91
92         verify(api, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
93
94         LispAddDelLocatorSet request = locatorSetCaptor.getValue();
95
96         assertNotNull(request);
97         assertEquals("Locator", new String(request.locatorSetName));
98         assertEquals(1, request.isAdd);
99     }
100
101     @Test(expected = UnsupportedOperationException.class)
102     public void testUpdateCurrentAttributes() throws WriteFailedException {
103         customizer.updateCurrentAttributes(null, null, null, null);
104     }
105
106     @Test(expected = NullPointerException.class)
107     public void testDeleteCurrentAttributesNullData() throws WriteFailedException {
108         customizer.deleteCurrentAttributes(null, null, null);
109     }
110
111     @Test(expected = NullPointerException.class)
112     public void testDeleteCurrentAttributesBadData() throws WriteFailedException {
113         customizer.deleteCurrentAttributes(null, mock(LocatorSet.class), null);
114     }
115
116     @Test
117     public void testDeleteCurrentAttributes() throws InterruptedException, ExecutionException, WriteFailedException {
118         LocatorSet locatorSet = new LocatorSetBuilder()
119                 .setName("Locator")
120                 .build();
121
122         ArgumentCaptor<LispAddDelLocatorSet> locatorSetCaptor = ArgumentCaptor.forClass(LispAddDelLocatorSet.class);
123
124         when(api.lispAddDelLocatorSet(any(LispAddDelLocatorSet.class))).thenReturn(future(new LispAddDelLocatorSetReply()));
125
126         customizer.deleteCurrentAttributes(null, locatorSet, writeContext);
127
128         verify(api, times(1)).lispAddDelLocatorSet(locatorSetCaptor.capture());
129
130         LispAddDelLocatorSet request = locatorSetCaptor.getValue();
131
132         assertNotNull(request);
133         assertEquals("Locator", new String(request.locatorSetName));
134         assertEquals(0, request.isAdd);
135     }
136 }