summaryrefslogtreecommitdiffstats
path: root/v3po/impl/src/test
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-04-12 10:13:14 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-04-12 10:13:14 +0200
commitc7ca517b00f2682987aef3ac390dfc04155a8aee (patch)
tree662791d6e857234dab467d9cddd55300060ccaca /v3po/impl/src/test
parent4a3dce3e0e59df4e091b4f8d4efc3e20831bf22f (diff)
HONEYCOMB-9: Split impl module into smaller parts
Change-Id: I9232e0adfe611cb97951080839b28a7b62ba5484 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl/src/test')
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java6
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java2
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java8
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/ReadFailedExceptionTest.java53
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationExceptionTest.java46
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistryTest.java189
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContextTest.java122
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainCustomizerTest.java269
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainTestUtils.java64
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppTest.java174
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppUtils.java62
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java259
-rw-r--r--v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java77
13 files changed, 8 insertions, 1323 deletions
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java
index 8719a5356..207a64a99 100644
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java
+++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VPPConfigDataTreeTest.java
@@ -31,9 +31,9 @@ import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
-import io.fd.honeycomb.v3po.impl.trans.VppException;
-import io.fd.honeycomb.v3po.impl.trans.w.WriteContext;
-import io.fd.honeycomb.v3po.impl.trans.w.WriterRegistry;
+import io.fd.honeycomb.v3po.vpp.facade.VppException;
+import io.fd.honeycomb.v3po.vpp.facade.write.WriteContext;
+import io.fd.honeycomb.v3po.vpp.facade.write.WriterRegistry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java
index 30cebf2f9..2c50ec92d 100644
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java
+++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java
@@ -26,7 +26,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.util.concurrent.CheckedFuture;
-import io.fd.honeycomb.v3po.impl.trans.r.ReaderRegistry;
+import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java
index 493a01912..09e70941b 100644
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java
+++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppOperationalDataTreeTest.java
@@ -34,8 +34,8 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.CheckedFuture;
-import io.fd.honeycomb.v3po.impl.trans.r.ReadContext;
-import io.fd.honeycomb.v3po.impl.trans.r.ReaderRegistry;
+import io.fd.honeycomb.v3po.vpp.facade.read.ReadContext;
+import io.fd.honeycomb.v3po.vpp.facade.read.ReaderRegistry;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
@@ -121,7 +121,7 @@ public class VppOperationalDataTreeTest {
@Test
public void testReadFailed() throws Exception{
- doThrow(io.fd.honeycomb.v3po.impl.trans.ReadFailedException.class).when(reader).readAll(any(ReadContext.class));
+ doThrow(io.fd.honeycomb.v3po.vpp.facade.read.ReadFailedException.class).when(reader).readAll(any(ReadContext.class));
final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future =
operationalData.read( YangInstanceIdentifier.EMPTY);
@@ -129,7 +129,7 @@ public class VppOperationalDataTreeTest {
try {
future.checkedGet();
} catch (ReadFailedException e) {
- assertTrue(e.getCause() instanceof io.fd.honeycomb.v3po.impl.trans.ReadFailedException);
+ assertTrue(e.getCause() instanceof io.fd.honeycomb.v3po.vpp.facade.read.ReadFailedException);
return;
}
fail("ReadFailedException was expected");
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/ReadFailedExceptionTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/ReadFailedExceptionTest.java
deleted file mode 100644
index b815434a8..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/ReadFailedExceptionTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.trans;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.Interface;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public class ReadFailedExceptionTest {
-
- @Test
- public void testInstantiation() {
- final InstanceIdentifier<BridgeDomain> id = InstanceIdentifier.create(BridgeDomain.class);
- ReadFailedException e = new ReadFailedException(id);
- assertEquals(id, e.getFailedId());
- assertNull(e.getCause());
- assertTrue(e.getMessage().contains(id.toString()));
- }
-
- @Test
- public void testInstantiationWithCause() {
- final InstanceIdentifier<Interface> id = InstanceIdentifier.create(Interface.class);
- final RuntimeException cause = new RuntimeException();
- ReadFailedException e = new ReadFailedException(id, cause);
- assertEquals(id, e.getFailedId());
- assertEquals(cause, e.getCause());
- assertTrue(e.getMessage().contains(id.toString()));
- }
-
- @Test(expected = NullPointerException.class)
- public void testInstantiationFailed() {
- new ReadFailedException(null);
- }
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationExceptionTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationExceptionTest.java
deleted file mode 100644
index fed792a3b..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/VppApiInvocationExceptionTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.trans;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Random;
-import org.junit.Test;
-
-public class VppApiInvocationExceptionTest {
-
- @Test
- public void testInstantiation() {
- final String apiMethodName = "methodName";
- final int ctxId = 1;
- final int code = -1;
- VppApiInvocationException e = new VppApiInvocationException(apiMethodName, ctxId, code);
- assertEquals(apiMethodName, e.getMethodName());
- assertEquals(ctxId, e.getCtxId());
- assertEquals(code, e.getErrorCode());
- assertTrue(e.getMessage().contains(apiMethodName));
- assertTrue(e.getMessage().contains(String.valueOf(code)));
- assertTrue(e.getMessage().contains(String.valueOf(ctxId)));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testInstantiationFailed() {
- final int code = new Random().nextInt(Integer.MAX_VALUE);
- VppApiInvocationException e = new VppApiInvocationException("apiMethodName", 1, code);
- }
-}
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistryTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistryTest.java
deleted file mode 100644
index 26f63f40f..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistryTest.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.trans.w.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
-import io.fd.honeycomb.v3po.impl.trans.VppException;
-import io.fd.honeycomb.v3po.impl.trans.w.VppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.WriteContext;
-import io.fd.honeycomb.v3po.impl.trans.w.WriterRegistry;
-import io.fd.honeycomb.v3po.impl.trans.w.impl.CompositeRootVppWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public class DelegatingWriterRegistryTest {
-
- private final InstanceIdentifier<Vpp> vppId;
- private final InstanceIdentifier<VppState> vppStateId;
- private final InstanceIdentifier<Interfaces> interfaceId;
-
- private WriteContext ctx;
- private CompositeRootVppWriter<Vpp> vppWriter;
- private CompositeRootVppWriter<VppState> vppStateWriter;
- private CompositeRootVppWriter<Interfaces> interfacesWriter;
-
- private DelegatingWriterRegistry registry;
-
- public DelegatingWriterRegistryTest() {
- vppId = InstanceIdentifier.create(Vpp.class);
- vppStateId = InstanceIdentifier.create(VppState.class);
- interfaceId = InstanceIdentifier.create(Interfaces.class);
- }
-
- @SuppressWarnings("unchecked")
- private <D extends DataObject> CompositeRootVppWriter<D> mockWriter(Class<D> clazz) {
- final CompositeRootVppWriter<D> mock = (CompositeRootVppWriter<D>) Mockito.mock(CompositeRootVppWriter.class);
- doReturn(InstanceIdentifier.create(clazz)).when(mock).getManagedDataObjectType();
- return mock;
- }
-
- private DataObject mockDataObject(final String name, final Class<? extends DataObject> classToMock) {
- final DataObject dataBefore = mock(classToMock, name);
- doReturn(classToMock).when(dataBefore).getImplementedInterface();
- return dataBefore;
- }
-
- @SuppressWarnings("unchecked")
- private static Map<InstanceIdentifier<?>, DataObject> asMap(DataObject... objects) {
- final Map<InstanceIdentifier<?>, DataObject> map = new HashMap<>();
- for (DataObject object : objects) {
- final Class<? extends DataObject> implementedInterface =
- (Class<? extends DataObject>) object.getImplementedInterface();
- final InstanceIdentifier<?> id = InstanceIdentifier.create(implementedInterface);
- map.put(id, object);
- }
- return map;
- }
-
- @Before
- public void setUp() {
- ctx = mock(WriteContext.class);
- vppWriter = mockWriter(Vpp.class);
- vppStateWriter = mockWriter(VppState.class);
- interfacesWriter = mockWriter(Interfaces.class);
-
- final List<VppWriter<? extends DataObject>> writers = new ArrayList<>();
- writers.add(vppWriter);
- writers.add(vppStateWriter);
- writers.add(interfacesWriter);
-
- registry = new DelegatingWriterRegistry(writers);
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetManagedDataObjectType() {
- registry.getManagedDataObjectType();
- }
-
- @Test
- public void testBulkUpdateRevert() throws Exception {
- // Prepare data changes:
- final DataObject dataBefore1 = mockDataObject("Vpp before", Vpp.class);
- final DataObject dataAfter1 = mockDataObject("Vpp after", Vpp.class);
-
- final DataObject dataBefore2 = mockDataObject("VppState before", VppState.class);
- final DataObject dataAfter2 = mockDataObject("VppState after", VppState.class);
-
- // Fail on update
- doThrow(new VppException("vpp failed")).when(vppStateWriter)
- .update(vppStateId, dataBefore2, dataAfter2, ctx);
-
- // Run the test
- try {
- registry.update(asMap(dataBefore1, dataBefore2), asMap(dataAfter1, dataAfter2), ctx);
- } catch (WriterRegistry.BulkUpdateException e) {
- // Check second update failed
- assertEquals(vppStateId, e.getFailedId());
- verify(vppWriter).update(vppId, dataBefore1, dataAfter1, ctx);
- verify(vppStateWriter).update(vppStateId, dataBefore2, dataAfter2, ctx);
-
- // Try to revert changes
- e.revertChanges();
-
- // Check revert was successful
- verify(vppWriter).update(vppId, dataAfter1, dataBefore1, ctx);
- verify(vppStateWriter, never()).update(vppStateId, dataAfter2, dataBefore2, ctx);
-
- return;
- }
- fail("BulkUpdateException expected");
- }
-
- @Test
- public void testBulkUpdateRevertFail() throws Exception {
- // Prepare data changes:
- final DataObject dataBefore1 = mockDataObject("Vpp before", Vpp.class);
- final DataObject dataAfter1 = mockDataObject("Vpp after", Vpp.class);
-
- final DataObject dataBefore2 = mockDataObject("VppState before", VppState.class);
- final DataObject dataAfter2 = mockDataObject("VppState after", VppState.class);
-
- final DataObject dataBefore3 = mockDataObject("Interfaces before", Interfaces.class);
- final DataObject dataAfter3 = mockDataObject("Interfaces after", Interfaces.class);
-
- // Fail on the third update
- doThrow(new VppException("vpp failed")).when(interfacesWriter)
- .update(interfaceId, dataBefore3, dataAfter3, ctx);
-
- // Fail on the second revert
- doThrow(new VppException("vpp failed again")).when(vppWriter)
- .update(vppId, dataAfter1, dataBefore1, ctx);
-
- // Run the test
- try {
- registry.update(asMap(dataBefore1, dataBefore2, dataBefore3), asMap(dataAfter1, dataAfter2, dataAfter3), ctx);
- } catch (WriterRegistry.BulkUpdateException e) {
- // Check third update failed
- assertEquals(interfaceId, e.getFailedId());
- verify(vppWriter).update(vppId, dataBefore1, dataAfter1, ctx);
- verify(vppStateWriter).update(vppStateId, dataBefore2, dataAfter2, ctx);
- verify(interfacesWriter).update(interfaceId, dataBefore3, dataAfter3, ctx);
-
- // Try to revert changes
- try {
- e.revertChanges();
- } catch (WriterRegistry.Reverter.RevertFailedException e2) {
- // Check second revert failed
- assertEquals(Collections.singletonList(vppId), e2.getNotRevertedChanges());
- verify(vppWriter).update(vppId, dataAfter1, dataBefore1, ctx);
- verify(vppStateWriter).update(vppStateId, dataAfter2, dataBefore2, ctx);
- verify(interfacesWriter, never()).update(interfaceId, dataAfter3, dataBefore3, ctx);
- return;
- }
- fail("WriterRegistry.Revert.RevertFailedException expected");
- }
- fail("BulkUpdateException expected");
- }
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContextTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContextTest.java
deleted file mode 100644
index 0f906d20c..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContextTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package io.fd.honeycomb.v3po.impl.trans.w.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-import io.fd.honeycomb.v3po.impl.trans.util.Context;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-public class TransactionWriteContextTest {
-
- @Mock
- private BindingNormalizedNodeSerializer serializer;
- @Mock
- private DOMDataReadOnlyTransaction beforeTx;
- @Mock
- private DOMDataReadOnlyTransaction afterTx;
- @Mock
- private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future;
- @Mock
- private Optional<org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode<?, ?>> optional;
- @Mock
- private Map.Entry entry;
-
- private TransactionWriteContext transactionWriteContext;
-
- @Before
- public void setUp() {
- initMocks(this);
- transactionWriteContext = new TransactionWriteContext(serializer, beforeTx, afterTx);
- }
-
- @Test
- public void testReadBeforeNoData() throws Exception {
- when(beforeTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn(future);
- when(future.checkedGet()).thenReturn(optional);
- when(optional.isPresent()).thenReturn(false);
-
- final InstanceIdentifier<BridgeDomain> instanceId =
- InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child(BridgeDomain.class);
-
- final Optional<DataObject> dataObjects = transactionWriteContext.readBefore(instanceId);
- assertNotNull(dataObjects);
- assertFalse(dataObjects.isPresent());
-
- verify(serializer).toYangInstanceIdentifier(instanceId);
- verify(serializer, never()).fromNormalizedNode(any(YangInstanceIdentifier.class), any(NormalizedNode.class));
- }
-
-
- @Test
- public void testReadBefore() throws Exception {
- when(beforeTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn(future);
- when(future.checkedGet()).thenReturn(optional);
- when(optional.isPresent()).thenReturn(true);
-
- final InstanceIdentifier<BridgeDomain> instanceId =
- InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child(BridgeDomain.class);
- final YangInstanceIdentifier yangId = YangInstanceIdentifier.builder().node(VppState.QNAME).node(
- BridgeDomains.QNAME).node(BridgeDomain.QNAME).build();
- when(serializer.toYangInstanceIdentifier(any(InstanceIdentifier.class))).thenReturn(yangId);
- when(serializer.fromNormalizedNode(eq(yangId), any(NormalizedNode.class))).thenReturn(entry);
- when(entry.getValue()).thenReturn(mock(DataObject.class));
-
- final Optional<DataObject> dataObjects = transactionWriteContext.readBefore(instanceId);
- assertNotNull(dataObjects);
- assertTrue(dataObjects.isPresent());
-
- verify(serializer).toYangInstanceIdentifier(instanceId);
- verify(serializer).fromNormalizedNode(eq(yangId), any(NormalizedNode.class));
- }
-
- @Test(expected = IllegalStateException.class)
- public void testReadBeforeFailed() throws Exception {
- when(beforeTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn(future);
- when(future.checkedGet()).thenThrow(ReadFailedException.class);
- transactionWriteContext.readBefore(mock(InstanceIdentifier.class));
- }
-
- @Test(expected = IllegalStateException.class)
- public void testReadAfterFailed() throws Exception {
- when(afterTx.read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class))).thenReturn(future);
- when(future.checkedGet()).thenThrow(ReadFailedException.class);
- transactionWriteContext.readAfter(mock(InstanceIdentifier.class));
- }
-
- @Test
- public void testGetContext() throws Exception {
- assertNotNull(transactionWriteContext.getContext());
- }
-
- @Test
- public void testClose() throws Exception {
- final Context context = transactionWriteContext.getContext();
- transactionWriteContext.close();
- // TODO verify context was closed
- }
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainCustomizerTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainCustomizerTest.java
deleted file mode 100644
index 4614b875a..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainCustomizerTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.vpp;
-
-import static io.fd.honeycomb.v3po.impl.vpp.BridgeDomainTestUtils.BD_NAME_TO_ID_ANSWER;
-import static io.fd.honeycomb.v3po.impl.vpp.BridgeDomainTestUtils.bdIdentifierForName;
-import static io.fd.honeycomb.v3po.impl.vpp.BridgeDomainTestUtils.bdNameToID;
-import static io.fd.honeycomb.v3po.impl.vpp.BridgeDomainTestUtils.booleanToByte;
-import static io.fd.honeycomb.v3po.impl.vpp.BridgeDomainTestUtils.intToBoolean;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import io.fd.honeycomb.v3po.impl.trans.util.Context;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
-public class BridgeDomainCustomizerTest {
-
- private static final int RESPONSE_NOT_READY = -77;
- private static final byte ADD_OR_UPDATE_BD = (byte) 1;
- private static final byte ZERO = 0;
- private vppApi api;
-
- @Mock
- private Context ctx;
-
- private BridgeDomainCustomizer customizer;
-
- @Before
- public void setUp() throws Exception {
- // TODO create base class for tests using vppApi
- api = PowerMockito.mock(vppApi.class);
- initMocks(this);
- customizer = new BridgeDomainCustomizer(api);
-
- PowerMockito.doAnswer(BD_NAME_TO_ID_ANSWER).when(api).findOrAddBridgeDomainId(anyString());
- PowerMockito.doAnswer(BD_NAME_TO_ID_ANSWER).when(api).bridgeDomainIdFromName(anyString());
- PowerMockito.when(api.getRetval(anyInt(), anyInt())).thenReturn(RESPONSE_NOT_READY).thenReturn(0);
- PowerMockito.doReturn(0).when(api).getRetval(anyInt(), anyInt());
- }
-
- private BridgeDomain generateBridgeDomain(final String bdName) {
- final byte arpTerm = 0;
- final byte flood = 1;
- final byte forward = 0;
- final byte learn = 1;
- final byte uuf = 0;
- return generateBridgeDomain(bdName, arpTerm, flood, forward, learn, uuf);
- }
-
- private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood,
- final int forward, final int learn, final int uuf) {
- return new BridgeDomainBuilder()
- .setName(bdName)
- .setArpTermination(intToBoolean(arpTerm))
- .setFlood(intToBoolean(flood))
- .setForward(intToBoolean(forward))
- .setLearn(intToBoolean(learn))
- .setUnknownUnicastFlood(intToBoolean(uuf))
- .build();
- }
-
- private final int verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd) {
- final int bdn1Id = bdNameToID(bd.getName());
- final byte arpTerm = booleanToByte(bd.isArpTermination());
- final byte flood = booleanToByte(bd.isFlood());
- final byte forward = booleanToByte(bd.isForward());
- final byte learn = booleanToByte(bd.isLearn());
- final byte uuf = booleanToByte(bd.isUnknownUnicastFlood());
- return verify(api).bridgeDomainAddDel(bdn1Id, flood, forward, learn, uuf, arpTerm, ADD_OR_UPDATE_BD);
- }
-
- private int verifyBridgeDomainAddOrUpdateWasNotInvoked(final BridgeDomain bd) {
- final int bdn1Id = bdNameToID(bd.getName());
- final byte arpTerm = booleanToByte(bd.isArpTermination());
- final byte flood = booleanToByte(bd.isFlood());
- final byte forward = booleanToByte(bd.isForward());
- final byte learn = booleanToByte(bd.isLearn());
- final byte uuf = booleanToByte(bd.isUnknownUnicastFlood());
- return verify(api, never()).bridgeDomainAddDel(bdn1Id, flood, forward, learn, uuf, arpTerm, ADD_OR_UPDATE_BD);
- }
-
- private int verifyBridgeDomainDeletedWasInvoked(final BridgeDomain bd) {
- final int bdn1Id = bdNameToID(bd.getName());
- return verify(api).bridgeDomainAddDel(bdn1Id, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
- }
-
- private int verifyBridgeDomainDeletedWasNotInvoked(final BridgeDomain bd) {
- final int bdn1Id = bdNameToID(bd.getName());
- return verify(api, never()).bridgeDomainAddDel(bdn1Id, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
- }
-
- @Test
- public void testAddBridgeDomain() {
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
-
- customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, ctx);
-
- verifyBridgeDomainAddOrUpdateWasInvoked(bd);
- }
-
- @Test
- public void testBridgeDomainNameCreateFailed() {
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
-
- // make vpp api fail to create id for our bd name
- PowerMockito.doReturn(-1).when(api).findOrAddBridgeDomainId(bdName);
-
- try {
- customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasNotInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
- @Test
- public void testAddBridgeDomainFailed() {
- // make any call to vpp fail
- PowerMockito.doReturn(-1).when(api).getRetval(anyInt(), anyInt());
-
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain(bdName);
-
- try {
- customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
- @Test
- public void testDeleteBridgeDomain() {
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
-
- customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, ctx);
-
- verifyBridgeDomainDeletedWasInvoked(bd);
- }
-
- @Test
- public void testDeleteUnknownBridgeDomain() {
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
-
- // make vpp api not find our bd
- PowerMockito.doReturn(-1).when(api).bridgeDomainIdFromName(bdName);
-
- try {
- customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainDeletedWasNotInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
- @Test
- public void testDeleteBridgeDomainFailed() {
- // make any call to vpp fail
- PowerMockito.doReturn(-1).when(api).getRetval(anyInt(), anyInt());
-
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain(bdName);
-
- try {
- customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainDeletedWasInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
- @Test
- public void testUpdateBridgeDomain() throws Exception {
- final String bdName = "bd1";
- final byte arpTermBefore = 1;
- final byte floodBefore = 1;
- final byte forwardBefore = 0;
- final byte learnBefore = 1;
- final byte uufBefore = 0;
-
- final BridgeDomain dataBefore =
- generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore);
- final BridgeDomain dataAfter =
- generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1,
- uufBefore ^ 1);
-
- final KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> id = bdIdentifierForName(bdName);
-
- customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx);
-
- verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter);
- }
-
- @Test
- public void testUpdateUnknownBridgeDomain() throws Exception {
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain("bd1");
-
- // make vpp api not find our bd
- PowerMockito.doReturn(-1).when(api).bridgeDomainIdFromName(bdName);
-
- try {
- customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bd, bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasNotInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
- @Test
- public void testUpdateBridgeDomainFailed() {
- // make any call to vpp fail
- PowerMockito.doReturn(-1).when(api).getRetval(anyInt(), anyInt());
-
- final String bdName = "bd1";
- final BridgeDomain bd = generateBridgeDomain(bdName);
-
- try {
- customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bd, bd, ctx);
- } catch (IllegalStateException e) {
- verifyBridgeDomainAddOrUpdateWasInvoked(bd);
- return;
- }
- fail("IllegalStateException was expected");
- }
-
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainTestUtils.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainTestUtils.java
deleted file mode 100644
index 6930493b6..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/BridgeDomainTestUtils.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.vpp;
-
-import javax.annotation.Nullable;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-final class BridgeDomainTestUtils {
-
- private BridgeDomainTestUtils() {
- throw new UnsupportedOperationException("Utility class cannot be instantiated.");
- }
-
- public static byte booleanToByte(@Nullable final Boolean value) {
- return value != null && value ? (byte) 1 : (byte) 0;
- }
-
- @Nullable
- public static Boolean intToBoolean(final int value) {
- if (value == 0) {
- return Boolean.FALSE;
- }
- if (value == 1) {
- return Boolean.TRUE;
- }
- return null;
- }
-
- public static int bdNameToID(String bName) {
- return Integer.parseInt(((Character)bName.charAt(bName.length() - 1)).toString());
- }
-
- public static KeyedInstanceIdentifier<BridgeDomain, BridgeDomainKey> bdIdentifierForName(
- final String bdName) {
- return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName));
- }
-
- public static final Answer<Integer> BD_NAME_TO_ID_ANSWER = new Answer<Integer>() {
- @Override
- public Integer answer(final InvocationOnMock invocationOnMock) throws Throwable {
- return bdNameToID((String) invocationOnMock.getArguments()[0]);
- }
- };
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppTest.java
deleted file mode 100644
index c9533a0e7..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppTest.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.vpp;
-
-import static io.fd.honeycomb.v3po.impl.vpp.BridgeDomainTestUtils.BD_NAME_TO_ID_ANSWER;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
-import com.google.common.collect.Lists;
-import io.fd.honeycomb.v3po.impl.trans.w.VppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.WriteContext;
-import io.fd.honeycomb.v3po.impl.trans.w.impl.CompositeRootVppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.util.DelegatingWriterRegistry;
-import java.util.Collections;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomainsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
-public class VppTest {
-
- private vppApi api;
- private DelegatingWriterRegistry rootRegistry;
- private CompositeRootVppWriter<Vpp> vppWriter;
- private WriteContext ctx;
-
- final byte zero = (byte) 0;
- final byte flood = (byte) 1;
- final byte forward = (byte) 0;
- final byte learn = (byte) 1;
- final byte uuf = (byte) 0;
- final byte arpTerm = (byte) 0;
- final byte add = (byte) 1;
-
- @Before
- public void setUp() throws Exception {
- api = PowerMockito.mock(vppApi.class);
- ctx = mock(WriteContext.class);
- PowerMockito.doAnswer(BD_NAME_TO_ID_ANSWER).when(api).findOrAddBridgeDomainId(anyString());
- PowerMockito.doAnswer(BD_NAME_TO_ID_ANSWER).when(api).bridgeDomainIdFromName(anyString());
- PowerMockito.doReturn(1).when(api).getRetval(anyInt(), anyInt());
- vppWriter = VppUtils.getVppWriter(api);
- rootRegistry = new DelegatingWriterRegistry(
- Collections.<VppWriter<? extends DataObject>>singletonList(vppWriter));
- }
-
- @Test
- public void writeVpp() throws Exception {
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- null,
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- ctx);
-
- verify(api).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add);
-
- vppWriter.update(InstanceIdentifier.create(Vpp.class),
- null,
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- ctx);
-
- verify(api, times(2)).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add);
- }
-
- @Test
- public void writeVppFromRoot() throws Exception {
- final Vpp vpp = new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build();
-
- rootRegistry.update(Collections.<InstanceIdentifier<?>, DataObject>emptyMap(),
- Collections.<InstanceIdentifier<?>, DataObject>singletonMap(InstanceIdentifier.create(Vpp.class),
- vpp), ctx);
-
- verify(api).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add);
- }
-
- private BridgeDomains getBridgeDomains(String... name) {
- final List<BridgeDomain> bdmns = Lists.newArrayList();
- for (String s : name) {
- bdmns.add(new BridgeDomainBuilder()
- .setName(s)
- .setArpTermination(false)
- .setFlood(true)
- .setForward(false)
- .setLearn(true)
- .build());
- }
- return new BridgeDomainsBuilder()
- .setBridgeDomain(bdmns)
- .build();
- }
-
- @Test
- public void deleteVpp() throws Exception {
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- null,
- ctx);
-
- final byte zero = (byte) 0;
-
- verify(api).bridgeDomainAddDel(1, zero, zero, zero, zero, zero, zero);
- }
-
- @Test
- public void updateVppNoActualChange() throws Exception {
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build(),
- ctx);
-
- verifyZeroInteractions(api);
- }
-
- @Test
- public void writeUpdate() throws Exception {
- final BridgeDomains domainsBefore = getBridgeDomains("bdn1");
- final BridgeDomain bdn1Before = domainsBefore.getBridgeDomain().get(0);
-
- final BridgeDomain bdn1After = new BridgeDomainBuilder(bdn1Before).setFlood(!bdn1Before.isFlood()).build();
- final BridgeDomains domainsAfter = new BridgeDomainsBuilder()
- .setBridgeDomain(Collections.singletonList(bdn1After))
- .build();
-
- rootRegistry.update(
- InstanceIdentifier.create(Vpp.class),
- new VppBuilder().setBridgeDomains(domainsBefore).build(),
- new VppBuilder().setBridgeDomains(domainsAfter).build(),
- ctx);
-
- final int bdn1Id = 1;
-
- // bdn1 is created with negated flood value
- verify(api).bridgeDomainAddDel(bdn1Id, (byte) (flood ^ 1), forward, learn, uuf, arpTerm, add);
- }
-
- // TODO test unkeyed list
- // TODO test update of a child without dedicated writer
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppUtils.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppUtils.java
deleted file mode 100644
index d73a8732c..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppUtils.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.vpp;
-
-import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils;
-import io.fd.honeycomb.v3po.impl.trans.w.ChildVppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.impl.CompositeChildVppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.impl.CompositeListVppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.impl.CompositeRootVppWriter;
-import io.fd.honeycomb.v3po.impl.trans.w.util.NoopWriterCustomizer;
-import io.fd.honeycomb.v3po.impl.trans.w.util.ReflexiveChildWriterCustomizer;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
-import org.openvpp.vppjapi.vppApi;
-
-final class VppUtils {
-
- public VppUtils() {}
-
- /**
- * Create root Vpp writer with all its children wired
- */
- static CompositeRootVppWriter<Vpp> getVppWriter(@Nonnull final vppApi vppApi) {
-
- final CompositeListVppWriter<BridgeDomain, BridgeDomainKey> bridgeDomainWriter = new CompositeListVppWriter<>(
- BridgeDomain.class,
- new io.fd.honeycomb.v3po.impl.vpp.BridgeDomainCustomizer(vppApi));
-
- final ChildVppWriter<BridgeDomains> bridgeDomainsReader = new CompositeChildVppWriter<>(
- BridgeDomains.class,
- VppRWUtils.singletonChildWriterList(bridgeDomainWriter),
- new ReflexiveChildWriterCustomizer<BridgeDomains>());
-
- final List<ChildVppWriter<? extends ChildOf<Vpp>>> childWriters = new ArrayList<>();
- childWriters.add(bridgeDomainsReader);
-
- return new CompositeRootVppWriter<>(
- Vpp.class,
- childWriters,
- new NoopWriterCustomizer<Vpp>());
- }
-}
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java
deleted file mode 100644
index 5cb678e3a..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateTest.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.vppstate;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Multimap;
-import io.fd.honeycomb.v3po.impl.trans.r.ReadContext;
-import io.fd.honeycomb.v3po.impl.trans.r.VppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeListVppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeRootVppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.util.DelegatingReaderRegistry;
-import java.util.Collections;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2Fib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2FibKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.vppjapi.vppApi;
-import org.openvpp.vppjapi.vppBridgeDomainDetails;
-import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails;
-import org.openvpp.vppjapi.vppL2Fib;
-import org.openvpp.vppjapi.vppVersion;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn")
-@PrepareForTest(vppApi.class)
-public class VppStateTest {
-
- public static final vppVersion VERSION = new vppVersion("test", "1", "2", "33");
-
- private vppApi api;
- private CompositeRootVppReader<VppState, VppStateBuilder> vppStateReader;
- private DelegatingReaderRegistry readerRegistry;
- private vppBridgeDomainDetails bdDetails;
- private vppBridgeDomainDetails bdDetails2;
- private ReadContext ctx;
-
- @Before
- public void setUp() throws Exception {
- api = PowerMockito.mock(vppApi.class);
-
- ctx = mock(ReadContext.class);
-
- bdDetails = new vppBridgeDomainDetails();
- setIfcs(bdDetails);
- setBaseAttrs(bdDetails, "bdn1", 1);
-
- bdDetails2 = new vppBridgeDomainDetails();
- setIfcs(bdDetails2);
- setBaseAttrs(bdDetails2, "bdn2", 2);
-
- final vppL2Fib[] l2Fibs = getL2Fibs();
- PowerMockito.doReturn(l2Fibs).when(api).l2FibTableDump(Matchers.anyInt());
- PowerMockito.doAnswer(new Answer<vppBridgeDomainDetails>() {
-
- @Override
- public vppBridgeDomainDetails answer(final InvocationOnMock invocationOnMock) throws Throwable {
- final Integer idx = (Integer) invocationOnMock.getArguments()[0];
- switch (idx) {
- case 1 : return bdDetails;
- case 2 : return bdDetails2;
- default: return null;
- }
- }
- }).when(api).getBridgeDomainDetails(Matchers.anyInt());
-
- PowerMockito.doAnswer(new Answer<Object>() {
- @Override
- public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
- final String name = (String) invocationOnMock.getArguments()[0];
- switch (name) {
- case "bdn1" : return 1;
- case "bdn2" : return 2;
- default: return null;
- }
- }
- }).when(api).bridgeDomainIdFromName(anyString());
- PowerMockito.doReturn(new int[] {1, 2}).when(api).bridgeDomainDump(Matchers.anyInt());
- PowerMockito.doReturn(VERSION).when(api).getVppVersion();
- vppStateReader = VppStateUtils.getVppStateReader(api);
- readerRegistry = new DelegatingReaderRegistry(Collections.<VppReader<? extends DataObject>>singletonList(vppStateReader));
- }
-
- private vppL2Fib[] getL2Fibs() {
- return new vppL2Fib[] {
- new vppL2Fib(new byte[]{1,2,3,4,5,6}, true, "ifc1", true, true),
- new vppL2Fib(new byte[]{2,2,3,4,5,6}, true, "ifc2", true, true),
- };
- }
-
- private void setIfcs(final vppBridgeDomainDetails bdDetails) {
- final vppBridgeDomainInterfaceDetails ifcDetails = new vppBridgeDomainInterfaceDetails();
- ifcDetails.interfaceName = "ifc";
- ifcDetails.splitHorizonGroup = 2;
- bdDetails.interfaces = new vppBridgeDomainInterfaceDetails[] {ifcDetails};
- }
-
- private void setBaseAttrs(final vppBridgeDomainDetails bdDetails, final String bdn, final int i) {
- bdDetails.name = bdn;
- bdDetails.arpTerm = true;
- bdDetails.bdId = i;
- bdDetails.bviInterfaceName = "ifc";
- bdDetails.flood = true;
- bdDetails.forward = true;
- bdDetails.learn = true;
- bdDetails.uuFlood = true;
- }
-
- @Test
- public void testReadAll() throws Exception {
- final Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> dataObjects = readerRegistry.readAll(ctx);
- assertEquals(dataObjects.size(), 1);
- final DataObject dataObject = Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet())));
- assertTrue(dataObject instanceof VppState);
- assertVersion((VppState) dataObject);
- assertEquals(2, ((VppState) dataObject).getBridgeDomains().getBridgeDomain().size());
- }
-
- private void assertVersion(final VppState dataObject) {
- assertEquals(
- new VersionBuilder()
- .setName("test")
- .setBuildDirectory("1")
- .setBranch("2")
- .setBuildDate("33")
- .build(),
- dataObject.getVersion());
- }
-
- @Test
- public void testReadSpecific() throws Exception {
- final Optional<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx);
- assertTrue(read.isPresent());
- assertVersion((VppState) read.get());
- }
-
- @Test
- public void testReadBridgeDomains() throws Exception {
- VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
-
- Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class), ctx);
- assertTrue(read.isPresent());
- assertEquals(readRoot.getBridgeDomains(), read.get());
- }
-
- /**
- * L2fib does not have a dedicated reader, relying on auto filtering
- */
- @Test
- public void testReadL2Fib() throws Exception {
- // Deep child without a dedicated reader with specific l2fib key
- Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class, new BridgeDomainKey("bdn1"))
- .child(L2Fib.class, new L2FibKey(new PhysAddress("01:02:03:04:05:06"))), ctx);
- assertTrue(read.isPresent());
-
- // non existing l2fib
- read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class, new BridgeDomainKey("bdn1"))
- .child(L2Fib.class, new L2FibKey(new PhysAddress("FF:FF:FF:04:05:06"))), ctx);
- assertFalse(read.isPresent());
- }
-
- @Test
- public void testReadBridgeDomainAll() throws Exception {
- VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
-
- final CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- VppStateUtils.getBridgeDomainReader(api);
-
- final List<BridgeDomain> read =
- bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class), ctx);
-
- assertEquals(readRoot.getBridgeDomains().getBridgeDomain(), read);
- }
-
- @Test
- public void testReadBridgeDomain() throws Exception {
- VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
-
- final Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class, new BridgeDomainKey("bdn1")), ctx);
-
- assertTrue(read.isPresent());
- assertEquals(Iterables.find(readRoot.getBridgeDomains().getBridgeDomain(), new Predicate<BridgeDomain>() {
- @Override
- public boolean apply(final BridgeDomain input) {
- return input.getKey().getName().equals("bdn1");
- }
- }), read.get());
- }
-
- // FIXME
- @Ignore("Bridge domain customizer does not check whether the bd exists or not and fails with NPE, add it there")
- @Test
- public void testReadBridgeDomainNotExisting() throws Exception {
- final Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child(
- BridgeDomain.class, new BridgeDomainKey("NOT EXISTING")), ctx);
- assertFalse(read.isPresent());
- }
-
- @Test
- public void testReadVersion() throws Exception {
- VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get();
-
- Optional<? extends DataObject> read =
- readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class), ctx);
- assertTrue(read.isPresent());
- assertEquals(readRoot.getVersion(), read.get());
- }
-} \ No newline at end of file
diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java
deleted file mode 100644
index 73113174c..000000000
--- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.impl.vppstate;
-
-import io.fd.honeycomb.v3po.impl.trans.r.ChildVppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeChildVppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeListVppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.impl.CompositeRootVppReader;
-import io.fd.honeycomb.v3po.impl.trans.r.util.ReflexiveChildReaderCustomizer;
-import io.fd.honeycomb.v3po.impl.trans.r.util.ReflexiveRootReaderCustomizer;
-import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.Nonnull;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey;
-import org.opendaylight.yangtools.yang.binding.ChildOf;
-import org.openvpp.vppjapi.vppApi;
-
-final class VppStateUtils {
-
- public VppStateUtils() {}
-
- /**
- * Create root VppState reader with all its children wired
- */
- static CompositeRootVppReader<VppState, VppStateBuilder> getVppStateReader(@Nonnull final vppApi vppApi) {
-
- final ChildVppReader<Version> versionReader = new CompositeChildVppReader<>(
- Version.class, new VersionCustomizer(vppApi));
-
- final CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> bridgeDomainReader =
- getBridgeDomainReader(vppApi);
-
- final ChildVppReader<BridgeDomains> bridgeDomainsReader = new CompositeChildVppReader<>(
- BridgeDomains.class,
- VppRWUtils.singletonChildReaderList(bridgeDomainReader),
- new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class));
-
- final List<ChildVppReader<? extends ChildOf<VppState>>> childVppReaders = new ArrayList<>();
- childVppReaders.add(versionReader);
- childVppReaders.add(bridgeDomainsReader);
-
- return new CompositeRootVppReader<>(
- VppState.class,
- childVppReaders,
- VppRWUtils.<VppState>emptyAugReaderList(),
- new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class));
- }
-
- static CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> getBridgeDomainReader(
- final @Nonnull vppApi vppApi) {
- return new CompositeListVppReader<>(
- BridgeDomain.class,
- new BridgeDomainCustomizer(vppApi));
- }
-}