summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src/test
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-05-16 12:42:01 +0200
committerMarek Gradzki <mgradzki@cisco.com>2018-05-17 05:20:09 +0000
commit6971c996c4056952c6f4ec48d5985e1a0333d97a (patch)
tree9c975199ef6482148263ce5c320377d4f2a104d1 /nat/nat2vpp/src/test
parentf031dcade0a8a9b8b7d6af4f4afe0d690e9246bc (diff)
HC2VPP-320: ensure at most one policy is configured per NAT instance
ReflexiveListReaderCustomizer is not used due to HONEYCOMB-437 Change-Id: I62755aaedd6e179b349ec47e4a304399c4fa18cd Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'nat/nat2vpp/src/test')
-rw-r--r--nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/PolicyCustomizerTest.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/PolicyCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/PolicyCustomizerTest.java
new file mode 100644
index 000000000..f1fe82ce1
--- /dev/null
+++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/PolicyCustomizerTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018 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.hc2vpp.nat.read;
+
+import static io.fd.hc2vpp.nat.read.PolicyCustomizer.DEFAULT_POLICY_ID;
+import static org.hamcrest.core.IsCollectionContaining.hasItems;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.hc2vpp.nat.NatIds;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.Instances;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.Policy;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class PolicyCustomizerTest extends ListReaderCustomizerTest<Policy, PolicyKey, PolicyBuilder> {
+
+ private static final InstanceIdentifier<Instance> INSTANCE_ID = InstanceIdentifier.create(Instances.class)
+ .child(Instance.class, new InstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID));
+
+ public PolicyCustomizerTest() {
+ super(Policy.class, InstanceBuilder.class);
+ }
+
+ @Override
+ protected ReaderCustomizer<Policy, PolicyBuilder> initCustomizer() {
+ return new PolicyCustomizer();
+ }
+
+ @Test
+ public void testGetAllIds() throws ReadFailedException {
+ assertThat(getCustomizer().getAllIds(NatIds.POLICY_ID, ctx), hasItems(new PolicyKey(0L)));
+ }
+
+ @Test
+ public void testReadDefault() throws ReadFailedException {
+ final PolicyBuilder builder = mock(PolicyBuilder.class);
+ getCustomizer().readCurrentAttributes(getId(DEFAULT_POLICY_ID), builder, ctx);
+ verify(builder).setId(DEFAULT_POLICY_ID);
+ }
+
+ @Test
+ public void testReadNonDefault() throws ReadFailedException {
+ final PolicyBuilder builder = mock(PolicyBuilder.class);
+ getCustomizer().readCurrentAttributes(getId(1L), builder, ctx);
+ verifyZeroInteractions(builder);
+ }
+
+ private static InstanceIdentifier<Policy> getId(final long id) {
+ return INSTANCE_ID.child(Policy.class, new PolicyKey(id));
+ }
+} \ No newline at end of file