2 * Copyright (c) 2016 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;
20 import static org.junit.Assert.fail;
21 import static org.mockito.Mockito.when;
22 import static org.mockito.MockitoAnnotations.initMocks;
24 import com.google.common.base.Optional;
25 import io.fd.honeycomb.translate.write.WriteFailedException;
26 import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTable;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.VniTableBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 public class VniTableCustomizerTest extends WriterCustomizerTest {
36 private VniTableCustomizer customizer;
37 private InstanceIdentifier<VniTable> validId;
38 private VniTable validData;
43 customizer = new VniTableCustomizer(api);
45 validId = InstanceIdentifier.create(VniTable.class);
46 validData = new VniTableBuilder()
47 .setVrfSubtable(new VrfSubtableBuilder()
52 public void testWriteSuccessfull() {
53 whenReadAfterReturnValid();
55 customizer.writeCurrentAttributes(validId, validData, writeContext);
56 } catch (Exception e) {
57 fail("Test should pass without exception");
61 @Test(expected = IllegalStateException.class)
62 public void testWriteFailed() throws WriteFailedException {
63 whenReadAfterReturnInvalid();
64 customizer.writeCurrentAttributes(validId, validData, writeContext);
67 @Test(expected = UnsupportedOperationException.class)
68 public void testUpdate() throws WriteFailedException {
69 customizer.updateCurrentAttributes(validId, validData, validData, writeContext);
73 public void testDeleteSuccessfull() {
74 whenReadBeforeReturnValid();
76 customizer.deleteCurrentAttributes(validId, validData, writeContext);
77 } catch (Exception e) {
78 fail("Test should pass without exception");
82 @Test(expected = IllegalStateException.class)
83 public void testDeleteFailed() throws WriteFailedException {
84 whenReadBeforeReturnInvalid();
85 customizer.deleteCurrentAttributes(validId, validData, writeContext);
88 private void whenReadBeforeReturnValid() {
89 when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData));
92 private void whenReadBeforeReturnInvalid() {
93 when(writeContext.readBefore(validId)).thenReturn(Optional.absent());
96 private void whenReadAfterReturnValid() {
97 when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData));
100 private void whenReadAfterReturnInvalid() {
101 when(writeContext.readAfter(validId)).thenReturn(Optional.absent());