Naoki Shiota
Committed by Yuta HIGUCHI

Added unit tests for newoptical package.

Change-Id: I23d7b0ec4241ee620dccb605b529d50288242eb8
...@@ -4,8 +4,13 @@ COMPILE_DEPS = [ ...@@ -4,8 +4,13 @@ COMPILE_DEPS = [
4 '//cli:onos-cli', 4 '//cli:onos-cli',
5 ] 5 ]
6 6
7 +TEST_DEPS = [
8 + '//lib:TEST_ADAPTERS',
9 +]
10 +
7 osgi_jar_with_tests ( 11 osgi_jar_with_tests (
8 deps = COMPILE_DEPS, 12 deps = COMPILE_DEPS,
13 + test_deps = TEST_DEPS,
9 ) 14 )
10 15
11 onos_app ( 16 onos_app (
......
...@@ -89,6 +89,18 @@ ...@@ -89,6 +89,18 @@
89 <version>${project.version}</version> 89 <version>${project.version}</version>
90 </dependency> 90 </dependency>
91 91
92 + <dependency>
93 + <groupId>com.google.guava</groupId>
94 + <artifactId>guava-testlib</artifactId>
95 + <scope>test</scope>
96 + </dependency>
97 +
98 + <dependency>
99 + <groupId>org.onosproject</groupId>
100 + <artifactId>onlab-junit</artifactId>
101 + <scope>test</scope>
102 + </dependency>
103 +
92 </dependencies> 104 </dependencies>
93 105
94 <build> 106 <build>
......
...@@ -151,11 +151,7 @@ public class OpticalPathProvisioner ...@@ -151,11 +151,7 @@ public class OpticalPathProvisioner
151 deviceService = opticalView(deviceService); 151 deviceService = opticalView(deviceService);
152 appId = coreService.registerApplication("org.onosproject.newoptical"); 152 appId = coreService.registerApplication("org.onosproject.newoptical");
153 153
154 - idCounter = storageService.atomicCounterBuilder() 154 + idCounter = storageService.getAtomicCounter(OPTICAL_CONNECTIVITY_ID_COUNTER);
155 - .withName(OPTICAL_CONNECTIVITY_ID_COUNTER)
156 - .withMeteringDisabled()
157 - .build()
158 - .asAtomicCounter();
159 155
160 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry); 156 eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry);
161 157
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
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
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
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.
15 + */
16 +
17 +package org.onosproject.newoptical;
18 +
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onlab.util.Bandwidth;
23 +import org.onosproject.core.ApplicationId;
24 +import org.onosproject.core.DefaultApplicationId;
25 +import org.onosproject.core.IdGenerator;
26 +import org.onosproject.net.CltSignalType;
27 +import org.onosproject.net.ConnectPoint;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.OduSignalType;
30 +import org.onosproject.net.PortNumber;
31 +import org.onosproject.net.intent.Intent;
32 +import org.onosproject.net.intent.Key;
33 +import org.onosproject.net.intent.OpticalCircuitIntent;
34 +import org.onosproject.net.intent.OpticalConnectivityIntent;
35 +
36 +import static org.junit.Assert.*;
37 +
38 +/**
39 + * Test class for PacketLinkRealizedByOptical class.
40 + */
41 +public class PacketLinkRealizedByOpticalTest {
42 +
43 + private final ApplicationId appId = new DefaultApplicationId(0, "PacketLinkRealizedByOpticalTest");
44 + private IdGenerator idGenerator;
45 +
46 + @Before
47 + public void setUp() {
48 + idGenerator = new IdGenerator() {
49 + int counter = 1;
50 +
51 + @Override
52 + public long getNewId() {
53 + return counter++;
54 + }
55 + };
56 +
57 + Intent.bindIdGenerator(idGenerator);
58 + }
59 +
60 + @After
61 + public void tearDown() {
62 + Intent.unbindIdGenerator(idGenerator);
63 + }
64 +
65 + /**
66 + * Checks the construction of PacketLinkRealizedByOptical object with all parameters specified.
67 + */
68 + @Test
69 + public void testCreate() {
70 + ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
71 + ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
72 + Key key = Key.of(10L, appId);
73 + Bandwidth bandwidth = Bandwidth.bps(100L);
74 +
75 + PacketLinkRealizedByOptical plink = new PacketLinkRealizedByOptical(cp1, cp2, key, bandwidth);
76 +
77 + assertNotNull(plink);
78 + assertEquals(plink.src(), cp1);
79 + assertEquals(plink.dst(), cp2);
80 + assertEquals((long) plink.bandwidth().bps(), 100L);
81 + }
82 +
83 + /**
84 + * Checks the construction of OpticalConnectivityId object with OpticalCircuitIntent.
85 + */
86 + @Test
87 + public void testCreateWithCircuitIntent() {
88 + ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
89 + ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
90 + OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder()
91 + .appId(appId)
92 + .src(cp1)
93 + .dst(cp2)
94 + .bidirectional(true)
95 + .key(Key.of(0, appId))
96 + .signalType(CltSignalType.CLT_1GBE)
97 + .build();
98 +
99 + PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, circuitIntent);
100 +
101 + assertNotNull(plink);
102 + assertEquals(plink.src(), cp1);
103 + assertEquals(plink.dst(), cp2);
104 + assertEquals((long) plink.bandwidth().bps(), CltSignalType.CLT_1GBE.bitRate());
105 + }
106 +
107 + /**
108 + * Checks the construction of OpticalConnectivityId object with OpticalConnectivityIntent.
109 + */
110 + @Test
111 + public void testCreateWithConnectivityIntent() {
112 + ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
113 + ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
114 + OpticalConnectivityIntent connIntent = OpticalConnectivityIntent.builder()
115 + .appId(appId)
116 + .src(cp1)
117 + .dst(cp2)
118 + .bidirectional(true)
119 + .key(Key.of(0, appId))
120 + .signalType(OduSignalType.ODU4)
121 + .build();
122 +
123 + PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, connIntent);
124 +
125 + assertNotNull(plink);
126 + assertEquals(plink.src(), cp1);
127 + assertEquals(plink.dst(), cp2);
128 + assertEquals((long) plink.bandwidth().bps(), OduSignalType.ODU4.bitRate());
129 + }
130 +
131 + /**
132 + * Checks that isBetween() method works.
133 + */
134 + @Test
135 + public void testIsBetween() {
136 + ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
137 + ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
138 + ConnectPoint cp3 = new ConnectPoint(DeviceId.deviceId("of:0000000000000003"), PortNumber.portNumber(3L));
139 + OpticalCircuitIntent ochIntent = OpticalCircuitIntent.builder()
140 + .appId(appId)
141 + .src(cp1)
142 + .dst(cp2)
143 + .bidirectional(true)
144 + .key(Key.of(0, appId))
145 + .signalType(CltSignalType.CLT_1GBE)
146 + .build();
147 +
148 + PacketLinkRealizedByOptical plink = PacketLinkRealizedByOptical.create(cp1, cp2, ochIntent);
149 +
150 + assertTrue(plink.isBetween(cp1, cp2));
151 + assertFalse(plink.isBetween(cp1, cp3));
152 + }
153 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
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
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
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.
15 + */
16 +
17 +package org.onosproject.newoptical.api;
18 +
19 +import org.junit.Test;
20 +import com.google.common.testing.EqualsTester;
21 +
22 +import static org.junit.Assert.assertEquals;
23 +import static org.junit.Assert.assertNotNull;
24 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25 +
26 +/**
27 + * Test class for OpticalConnectivityId.
28 + */
29 +public class OpticalConnectivityIdTest {
30 +
31 + /**
32 + * Checks that OpticalConnectivityId class is immutable.
33 + */
34 + @Test
35 + public void testImmutability() {
36 + assertThatClassIsImmutable(OpticalConnectivityId.class);
37 + }
38 +
39 + /**
40 + * Checks the construction of OpticalConnectivityId object.
41 + */
42 + @Test
43 + public void testConstruction() {
44 + OpticalConnectivityId tid = OpticalConnectivityId.of(1L);
45 + assertNotNull(tid);
46 + assertEquals(tid.id().longValue(), 1L);
47 + }
48 +
49 + /**
50 + * Checks the equality of OpticalConnectivityId objects.
51 + */
52 + @Test
53 + public void testEquality() {
54 + OpticalConnectivityId tid1 = OpticalConnectivityId.of(1L);
55 + OpticalConnectivityId tid2 = OpticalConnectivityId.of(1L);
56 + OpticalConnectivityId tid3 = OpticalConnectivityId.of(2L);
57 +
58 + new EqualsTester()
59 + .addEqualityGroup(tid1, tid2)
60 + .addEqualityGroup(tid3)
61 + .testEquals();
62 + }
63 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
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
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
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.
15 + */
16 +
17 +package org.onosproject.newoptical.api;
18 +
19 +import org.junit.Test;
20 +import org.onosproject.event.AbstractEventTest;
21 +
22 +/**
23 + * Test class for OpticalPathEvent class.
24 + */
25 +public class OpticalPathEventTest extends AbstractEventTest {
26 +
27 + @Override
28 + @Test
29 + public void withoutTime() {
30 + OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
31 + long before = System.currentTimeMillis();
32 + OpticalPathEvent event = new OpticalPathEvent(OpticalPathEvent.Type.PATH_INSTALLED, cid);
33 + long after = System.currentTimeMillis();
34 + validateEvent(event, OpticalPathEvent.Type.PATH_INSTALLED, cid, before, after);
35 + }
36 +
37 +}
...\ No newline at end of file ...\ No newline at end of file