diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-03-22 15:10:06 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2016-03-31 14:27:47 +0000 |
commit | 1fb7cb0596bde05c0931c43e53fba98e74005f9d (patch) | |
tree | b4443c2c321c6ad72fcb7c91bc93cd3c59a23b0c /v3po/impl/src/test/java | |
parent | db7465120b19870e3a7fb30ac8486f394c2647e9 (diff) |
Migrate Vpp/BridgeDomains config management under new writers
Change-Id: I0e5734bd54548ff78a2ec4420e4a8294401f4d46
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl/src/test/java')
-rw-r--r-- | v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppTest.java | 163 | ||||
-rw-r--r-- | v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppUtils.java | 62 |
2 files changed, 225 insertions, 0 deletions
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 new file mode 100644 index 000000000..beec76ab1 --- /dev/null +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppTest.java @@ -0,0 +1,163 @@ +/* + * 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 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.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +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(new Answer<Integer>() { + @Override + public Integer answer(final InvocationOnMock invocationOnMock) throws Throwable { + final String bName = (String) invocationOnMock.getArguments()[0]; + return Integer.parseInt(((Character)bName.charAt(bName.length() - 1)).toString()); + } + }).when(api).findOrAddBridgeDomainId(anyString()); + PowerMockito.doReturn(1).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), + Collections.<DataObject>emptyList(), + Lists.newArrayList(new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build()), + ctx); + + verify(api).bridgeDomainAddDel(1, flood, forward, learn, uuf, arpTerm, add); + + vppWriter.update(InstanceIdentifier.create(Vpp.class), + Collections.<DataObject>emptyList(), + Lists.newArrayList(new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build()), + ctx); + + verify(api, times(2)).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), + Collections.singletonList(new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build()), + Collections.<DataObject>emptyList(), + 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), + Collections.singletonList(new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build()), + Collections.singletonList(new VppBuilder().setBridgeDomains(getBridgeDomains("bdn1")).build()), + ctx); + + verifyZeroInteractions(api); + } + + @Test + public void writeBridgeDomain() throws Exception { + rootRegistry.update( + InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child(BridgeDomain.class), + getBridgeDomains("bdn1", "bdn2").getBridgeDomain(), + getBridgeDomains("bdn1", "bdn3").getBridgeDomain(), + ctx); + + // bdn1 is untouched + // bdn3 is added + verify(api).bridgeDomainAddDel(3, flood, forward, learn, uuf, arpTerm, add); + // bdn2 is deleted + verify(api).bridgeDomainAddDel(2, zero, zero, zero, zero, zero, zero); + } + + // 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 new file mode 100644 index 000000000..d73a8732c --- /dev/null +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vpp/VppUtils.java @@ -0,0 +1,62 @@ +/* + * 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>()); + } +} |