ONOS-5549 Unit tests for TE Tunnel attributes management API

Change-Id: I0631735280ce0c713c058b6a29f76e43312154d9
diff --git a/apps/tetunnel/api/src/test/java/org/onosproject/tetunnel/api/tunnel/DefaultTeTunnelTest.java b/apps/tetunnel/api/src/test/java/org/onosproject/tetunnel/api/tunnel/DefaultTeTunnelTest.java
new file mode 100644
index 0000000..5105baf
--- /dev/null
+++ b/apps/tetunnel/api/src/test/java/org/onosproject/tetunnel/api/tunnel/DefaultTeTunnelTest.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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 org.onosproject.tetunnel.api.tunnel;
+
+import com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.tetopology.management.api.TeTopologyKey;
+import org.onosproject.tetopology.management.api.node.TeNodeKey;
+import org.onosproject.tetopology.management.api.node.TtpKey;
+import org.onosproject.tetunnel.api.lsp.TeLspKey;
+import org.onosproject.tetunnel.api.tunnel.path.DefaultTePath;
+import org.onosproject.tetunnel.api.tunnel.path.TePath;
+
+import java.util.List;
+
+/**
+ * Unit tests for default TE tunnel implementation.
+ */
+public class DefaultTeTunnelTest {
+
+    /**
+     * Tests constructor of TeTunnelKey.
+     */
+    @Test
+    public void testConstructorOfTeTunnelKey() {
+        final int providerId = 1;
+        final int clientId = 2;
+        final int topologyId = 3;
+        final int teTunnelId = 4;
+
+        TeTunnelKey key = new TeTunnelKey(providerId, clientId, topologyId,
+                                          teTunnelId);
+
+        Assert.assertEquals(key.teTunnelId(), teTunnelId);
+        Assert.assertEquals(key.teTopologyKey(),
+                            new TeTopologyKey(providerId, clientId,
+                                              topologyId));
+        Assert.assertTrue(key.equals(
+                          new TeTunnelKey(providerId, clientId, topologyId,
+                                          teTunnelId)));
+    }
+
+    /**
+     * Tests constructor of TeLspKey.
+     */
+    @Test
+    public void testConstructorOfTeLspKey() {
+        final int providerId = 1;
+        final int clientId = 2;
+        final int topologyId = 3;
+        final int teLspId = 4;
+
+        TeLspKey key = new TeLspKey(providerId, clientId, topologyId,
+                                       teLspId);
+
+        Assert.assertEquals(key.teLspId(), teLspId);
+        Assert.assertEquals(key.teTopologyKey(),
+                            new TeTopologyKey(providerId, clientId,
+                                              topologyId));
+        Assert.assertTrue(key.equals(
+                new TeLspKey(providerId, clientId, topologyId,
+                                teLspId)));
+    }
+
+    /**
+     * Tests builder of the DefaultTeTunnel.
+     */
+    @Test
+    public void testDefaultTeTunnelBuilder() {
+        final int providerId = 1;
+        final int clientId = 2;
+        final int topologyId = 3;
+        final int srcNodeId = 4;
+        final int srcTtpId = 5;
+        final int dstNodeId = 6;
+        final int dstTtpId = 7;
+        final int teTunnelId = 8;
+        final String teTunnelName = "Test TE tunnel";
+        final List<TePath> paths = Lists.newArrayList(
+                new DefaultTePath(TePath.Type.DYNAMIC, null, null, null));
+        final int segTunnelId1 = 1001;
+        final int segTunnelId2 = 1002;
+        final int segTunnelId3 = 1003;
+
+        TeTunnel teTunnel = DefaultTeTunnel.builder()
+                .teTunnelKey(
+                        new TeTunnelKey(providerId, clientId, topologyId,
+                                        teTunnelId))
+                .srcNode(new TeNodeKey(providerId, clientId, topologyId,
+                                       srcNodeId))
+                .srcTp(new TtpKey(providerId, clientId, topologyId, srcNodeId,
+                                  srcTtpId))
+                .dstNode(new TeNodeKey(providerId, clientId, topologyId,
+                                       dstNodeId))
+                .dstTp(new TtpKey(providerId, clientId, topologyId, dstNodeId,
+                                  dstTtpId))
+                .name(teTunnelName)
+                .adminState(TeTunnel.State.UP)
+                .lspProtectionType(TeTunnel.LspProtectionType.LSP_PROT_REROUTE)
+                .type(TeTunnel.Type.P2P)
+                .primaryPaths(paths)
+                .build();
+
+        Assert.assertEquals(teTunnel.teTunnelKey().teTopologyKey(),
+                            new TeTopologyKey(providerId, clientId,
+                                              topologyId));
+        Assert.assertEquals(teTunnel.teTunnelKey().teTunnelId(), teTunnelId);
+        Assert.assertEquals(teTunnel.srcNode(),
+                            new TeNodeKey(providerId, clientId, topologyId,
+                                                              srcNodeId));
+        Assert.assertEquals(teTunnel.dstNode(),
+                            new TeNodeKey(providerId, clientId, topologyId,
+                                          dstNodeId));
+        Assert.assertEquals(teTunnel.srcTp(),
+                            new TtpKey(providerId, clientId, topologyId,
+                                       srcNodeId, srcTtpId));
+        Assert.assertEquals(teTunnel.dstTp(),
+                            new TtpKey(providerId, clientId, topologyId,
+                                       dstNodeId, dstTtpId));
+        Assert.assertEquals(teTunnel.name(), teTunnelName);
+        Assert.assertEquals(teTunnel.adminStatus(), TeTunnel.State.UP);
+        Assert.assertEquals(teTunnel.lspProtectionType(),
+                            TeTunnel.LspProtectionType.LSP_PROT_REROUTE);
+        Assert.assertEquals(teTunnel.type(), TeTunnel.Type.P2P);
+        Assert.assertEquals(teTunnel.primaryPaths().get(0).type(),
+                            TePath.Type.DYNAMIC);
+        Assert.assertEquals(teTunnel.primaryPaths(), paths);
+
+        TeTunnelKey segTunnel1 = new TeTunnelKey(providerId, clientId,
+                                                 topologyId, segTunnelId1);
+        TeTunnelKey segTunnel2 = new TeTunnelKey(providerId, clientId,
+                                                 topologyId, segTunnelId2);
+        TeTunnelKey segTunnel3 = new TeTunnelKey(providerId, clientId,
+                                                 topologyId, segTunnelId3);
+        List<TeTunnelKey> segTunnels = Lists.newArrayList(segTunnel1,
+                                                          segTunnel2,
+                                                          segTunnel3);
+        teTunnel.segmentTunnels(segTunnels);
+        Assert.assertEquals(teTunnel.segmentTunnels(), segTunnels);
+    }
+}
diff --git a/apps/tetunnel/api/src/test/java/org/onosproject/tetunnel/api/tunnel/path/DefaultTePathTest.java b/apps/tetunnel/api/src/test/java/org/onosproject/tetunnel/api/tunnel/path/DefaultTePathTest.java
new file mode 100644
index 0000000..f712811
--- /dev/null
+++ b/apps/tetunnel/api/src/test/java/org/onosproject/tetunnel/api/tunnel/path/DefaultTePathTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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 org.onosproject.tetunnel.api.tunnel.path;
+
+import com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.tetopology.management.api.TeTopologyKey;
+import org.onosproject.tetopology.management.api.node.TeNodeKey;
+import org.onosproject.tetopology.management.api.node.TtpKey;
+import org.onosproject.tetunnel.api.lsp.TeLspKey;
+
+import java.util.List;
+
+/**
+ * Unit tests for default TE path implementation.
+ */
+public class DefaultTePathTest {
+
+    /**
+     * Tests constructor of DefaultTePathSelection.
+     */
+    @Test
+    public void testConstructorOfDefaultTePathSelection() {
+        final int providerId = 1;
+        final int clientId = 2;
+        final int topologyId = 3;
+        final long costLimit = 4;
+        final short hopLimit = 5;
+
+        TePathSelection tePathSelection = new DefaultTePathSelection(
+                new TeTopologyKey(providerId, clientId, topologyId),
+                costLimit, hopLimit);
+        Assert.assertEquals(tePathSelection.teTopologyKey(),
+                            new TeTopologyKey(providerId, clientId, topologyId));
+        Assert.assertEquals(tePathSelection.costLimit(), costLimit);
+        Assert.assertEquals(tePathSelection.hopLimit(), hopLimit);
+    }
+
+    /**
+     * Tests constructor of DefaultTeRouteUnnumberedLink.
+     */
+    @Test
+    public void testConstructorOfDefaultTeRouteUnnumberedLink() {
+        final int providerId = 1;
+        final int clientId = 2;
+        final int topologyId = 3;
+        final int teNodeId = 4;
+        final int teTtpId = 5;
+
+        TeRouteUnnumberedLink teRouteUnnumberedLink =
+                new DefaultTeRouteUnnumberedLink(
+                        new TeNodeKey(providerId, clientId,
+                                      topologyId, teNodeId),
+                        new TtpKey(providerId, clientId,
+                                   topologyId, teNodeId, teTtpId));
+
+        Assert.assertEquals(teRouteUnnumberedLink.type(),
+                            TeRouteSubobject.Type.UNNUMBERED_LINK);
+        Assert.assertEquals(teRouteUnnumberedLink.node(),
+                            new TeNodeKey(providerId, clientId,
+                                          topologyId, teNodeId));
+        Assert.assertEquals(teRouteUnnumberedLink.ttp(),
+                            new TtpKey(providerId, clientId,
+                                       topologyId, teNodeId, teTtpId));
+    }
+
+    /**
+     * Tests constructor of DefaultTePath.
+     */
+    @Test
+    public void testConstructorOfDefaultTePath() {
+        final int providerId = 1;
+        final int clientId = 2;
+        final int topologyId = 3;
+        final int teNodeId = 4;
+        final int teTtpId = 5;
+        final int teLspId = 6;
+
+        List<TeLspKey> lspKeys = Lists.newArrayList(
+                new TeLspKey(providerId, clientId, topologyId, teLspId));
+
+        TeRouteUnnumberedLink teRouteUnnumberedLink =
+                new DefaultTeRouteUnnumberedLink(
+                        new TeNodeKey(providerId, clientId,
+                                      topologyId, teNodeId),
+                        new TtpKey(providerId, clientId,
+                                   topologyId, teNodeId, teTtpId));
+        List<TeRouteSubobject> explicitRoute = Lists.newArrayList(
+                teRouteUnnumberedLink);
+
+        List<TePath> secondaryPaths = Lists.newArrayList(
+                new DefaultTePath(TePath.Type.DYNAMIC, null, null, null)
+        );
+
+        TePath tePath = new DefaultTePath(TePath.Type.EXPLICIT, lspKeys,
+                                          explicitRoute, secondaryPaths);
+
+        Assert.assertEquals(tePath.type(), TePath.Type.EXPLICIT);
+        Assert.assertEquals(tePath.explicitRoute(), explicitRoute);
+        Assert.assertEquals(tePath.lsps(), lspKeys);
+        Assert.assertEquals(tePath.secondaryPaths(), secondaryPaths);
+    }
+}
diff --git a/apps/tetunnel/pom.xml b/apps/tetunnel/pom.xml
index 897000d..02b06f5 100644
--- a/apps/tetunnel/pom.xml
+++ b/apps/tetunnel/pom.xml
@@ -39,5 +39,11 @@
             <groupId>org.onosproject</groupId>
             <artifactId>onos-incubator-api</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-junit</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file