Committed by
Gerrit Code Review
Split one single test file into multiple files
Change-Id: I699bd3df001eab704afc4aaa8b8a5514e4b175f8
Showing
4 changed files
with
185 additions
and
53 deletions
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 | +package org.onosproject.net.newresource; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onlab.util.Bandwidth; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.PortNumber; | ||
23 | + | ||
24 | +/** | ||
25 | + * Unit test for ContinuousResourceId. | ||
26 | + */ | ||
27 | +public class ContinuousResourceIdTest { | ||
28 | + | ||
29 | + private static final DeviceId D1 = DeviceId.deviceId("of:001"); | ||
30 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
31 | + private static final Bandwidth BW1 = Bandwidth.gbps(2); | ||
32 | + private static final Bandwidth BW2 = Bandwidth.gbps(1); | ||
33 | + | ||
34 | + @Test | ||
35 | + public void testEquality() { | ||
36 | + ContinuousResourceId id1 = Resources.continuous(D1, P1, Bandwidth.class) | ||
37 | + .resource(BW1.bps()).id(); | ||
38 | + // intentionally set a different value | ||
39 | + ContinuousResourceId sameAsId1 = Resources.continuous(D1, P1, Bandwidth.class) | ||
40 | + .resource(BW2.bps()).id(); | ||
41 | + | ||
42 | + new EqualsTester() | ||
43 | + .addEqualityGroup(id1, sameAsId1); | ||
44 | + } | ||
45 | +} |
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 | +package org.onosproject.net.newresource; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onlab.packet.VlanId; | ||
21 | +import org.onlab.util.Bandwidth; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.PortNumber; | ||
24 | + | ||
25 | +import java.util.Optional; | ||
26 | + | ||
27 | +import static org.hamcrest.Matchers.is; | ||
28 | +import static org.junit.Assert.*; | ||
29 | + | ||
30 | +/** | ||
31 | + * Unit test for ContinuousResource. | ||
32 | + */ | ||
33 | +public class ContinuousResourceTest { | ||
34 | + | ||
35 | + private static final DeviceId D1 = DeviceId.deviceId("of:001"); | ||
36 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
37 | + private static final Bandwidth BW1 = Bandwidth.gbps(2); | ||
38 | + | ||
39 | + @Test | ||
40 | + public void testEquals() { | ||
41 | + ContinuousResource resource1 = Resources.continuous(D1, P1, Bandwidth.class) | ||
42 | + .resource(BW1.bps()); | ||
43 | + ContinuousResource sameAsResource1 = Resources.continuous(D1, P1, Bandwidth.class) | ||
44 | + .resource(BW1.bps()); | ||
45 | + | ||
46 | + new EqualsTester() | ||
47 | + .addEqualityGroup(resource1, sameAsResource1) | ||
48 | + .testEquals(); | ||
49 | + } | ||
50 | + | ||
51 | + @Test | ||
52 | + public void testTypeOf() { | ||
53 | + ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class) | ||
54 | + .resource(BW1.bps()); | ||
55 | + assertThat(continuous.isTypeOf(DeviceId.class), is(false)); | ||
56 | + assertThat(continuous.isTypeOf(PortNumber.class), is(false)); | ||
57 | + assertThat(continuous.isTypeOf(Bandwidth.class), is(true)); | ||
58 | + } | ||
59 | + | ||
60 | + @Test | ||
61 | + public void testSubTypeOf() { | ||
62 | + ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class) | ||
63 | + .resource(BW1.bps()); | ||
64 | + assertThat(continuous.isSubTypeOf(DeviceId.class), is(true)); | ||
65 | + assertThat(continuous.isSubTypeOf(PortNumber.class), is(true)); | ||
66 | + assertThat(continuous.isSubTypeOf(Bandwidth.class), is(true)); | ||
67 | + assertThat(continuous.isSubTypeOf(VlanId.class), is(false)); | ||
68 | + } | ||
69 | + | ||
70 | + @Test | ||
71 | + public void testValueAs() { | ||
72 | + ContinuousResource resource = Resources.continuous(D1, P1, Bandwidth.class) | ||
73 | + .resource(BW1.bps()); | ||
74 | + | ||
75 | + Optional<Double> volume = resource.valueAs(double.class); | ||
76 | + assertThat(volume.get(), is(BW1.bps())); | ||
77 | + } | ||
78 | +} |
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 | +package org.onosproject.net.newresource; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onlab.packet.VlanId; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.PortNumber; | ||
23 | + | ||
24 | +/** | ||
25 | + * Unit test for DiscreteResourceId. | ||
26 | + */ | ||
27 | +public class DiscreteResourceIdTest { | ||
28 | + | ||
29 | + private static final DeviceId D1 = DeviceId.deviceId("of:001"); | ||
30 | + private static final DeviceId D2 = DeviceId.deviceId("of:002"); | ||
31 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
32 | + private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | ||
33 | + | ||
34 | + @Test | ||
35 | + public void testEquality() { | ||
36 | + DiscreteResourceId id1 = Resources.discrete(D1, P1, VLAN1).id(); | ||
37 | + DiscreteResourceId sameAsId1 = Resources.discrete(D1, P1, VLAN1).id(); | ||
38 | + DiscreteResourceId id2 = Resources.discrete(D2, P1, VLAN1).id(); | ||
39 | + | ||
40 | + new EqualsTester() | ||
41 | + .addEqualityGroup(id1, sameAsId1) | ||
42 | + .addEqualityGroup(id2); | ||
43 | + } | ||
44 | +} |
1 | /* | 1 | /* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -25,66 +25,50 @@ import org.onosproject.net.PortNumber; | ... | @@ -25,66 +25,50 @@ import org.onosproject.net.PortNumber; |
25 | import java.util.Optional; | 25 | import java.util.Optional; |
26 | 26 | ||
27 | import static org.hamcrest.Matchers.is; | 27 | import static org.hamcrest.Matchers.is; |
28 | -import static org.junit.Assert.assertThat; | 28 | +import static org.junit.Assert.*; |
29 | 29 | ||
30 | -public class ResourceTest { | 30 | +/** |
31 | + * Unit test for DiscreteResource. | ||
32 | + */ | ||
33 | +public class DiscreteResourceTest { | ||
31 | 34 | ||
32 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); | 35 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); |
33 | private static final DeviceId D2 = DeviceId.deviceId("of:002"); | 36 | private static final DeviceId D2 = DeviceId.deviceId("of:002"); |
34 | private static final PortNumber P1 = PortNumber.portNumber(1); | 37 | private static final PortNumber P1 = PortNumber.portNumber(1); |
35 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | 38 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
36 | private static final Bandwidth BW1 = Bandwidth.gbps(2); | 39 | private static final Bandwidth BW1 = Bandwidth.gbps(2); |
37 | - private static final Bandwidth BW2 = Bandwidth.gbps(1); | ||
38 | 40 | ||
39 | @Test | 41 | @Test |
40 | public void testEquals() { | 42 | public void testEquals() { |
41 | - Resource resource1 = Resources.discrete(D1, P1, VLAN1).resource(); | 43 | + DiscreteResource resource1 = Resources.discrete(D1, P1, VLAN1).resource(); |
42 | - Resource sameAsResource1 = Resources.discrete(D1, P1, VLAN1).resource(); | 44 | + DiscreteResource sameAsResource1 = Resources.discrete(D1, P1, VLAN1).resource(); |
43 | - Resource resource2 = Resources.discrete(D2, P1, VLAN1).resource(); | 45 | + DiscreteResource resource2 = Resources.discrete(D2, P1, VLAN1).resource(); |
44 | - Resource resource3 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); | ||
45 | - Resource sameAsResource3 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); | ||
46 | 46 | ||
47 | new EqualsTester() | 47 | new EqualsTester() |
48 | .addEqualityGroup(resource1, sameAsResource1) | 48 | .addEqualityGroup(resource1, sameAsResource1) |
49 | .addEqualityGroup(resource2) | 49 | .addEqualityGroup(resource2) |
50 | - .addEqualityGroup(resource3, sameAsResource3) | ||
51 | .testEquals(); | 50 | .testEquals(); |
52 | } | 51 | } |
53 | 52 | ||
54 | @Test | 53 | @Test |
55 | - public void testIdEquality() { | ||
56 | - ResourceId id1 = Resources.discrete(D1, P1, VLAN1).id(); | ||
57 | - ResourceId sameAsId1 = Resources.discrete(D1, P1, VLAN1).id(); | ||
58 | - ResourceId id2 = Resources.discrete(D2, P1, VLAN1).id(); | ||
59 | - ResourceId id3 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()).id(); | ||
60 | - // intentionally set a different value | ||
61 | - ResourceId sameAsId3 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW2.bps()).id(); | ||
62 | - | ||
63 | - new EqualsTester() | ||
64 | - .addEqualityGroup(id1, sameAsId1) | ||
65 | - .addEqualityGroup(id2) | ||
66 | - .addEqualityGroup(id3, sameAsId3); | ||
67 | - } | ||
68 | - | ||
69 | - @Test | ||
70 | public void testChild() { | 54 | public void testChild() { |
71 | - Resource r1 = Resources.discrete(D1).resource().child(P1); | 55 | + DiscreteResource r1 = Resources.discrete(D1).resource().child(P1); |
72 | - Resource sameAsR2 = Resources.discrete(D1, P1).resource(); | 56 | + DiscreteResource sameAsR2 = Resources.discrete(D1, P1).resource(); |
73 | 57 | ||
74 | assertThat(r1, is(sameAsR2)); | 58 | assertThat(r1, is(sameAsR2)); |
75 | } | 59 | } |
76 | 60 | ||
77 | @Test | 61 | @Test |
78 | public void testThereIsParent() { | 62 | public void testThereIsParent() { |
79 | - Resource resource = Resources.discrete(D1, P1, VLAN1).resource(); | 63 | + DiscreteResource resource = Resources.discrete(D1, P1, VLAN1).resource(); |
80 | - Resource parent = Resources.discrete(D1, P1).resource(); | 64 | + DiscreteResource parent = Resources.discrete(D1, P1).resource(); |
81 | 65 | ||
82 | assertThat(resource.parent(), is(Optional.of(parent))); | 66 | assertThat(resource.parent(), is(Optional.of(parent))); |
83 | } | 67 | } |
84 | 68 | ||
85 | @Test | 69 | @Test |
86 | public void testNoParent() { | 70 | public void testNoParent() { |
87 | - Resource resource = Resources.discrete(D1).resource(); | 71 | + DiscreteResource resource = Resources.discrete(D1).resource(); |
88 | 72 | ||
89 | assertThat(resource.parent(), is(Optional.of(Resource.ROOT))); | 73 | assertThat(resource.parent(), is(Optional.of(Resource.ROOT))); |
90 | } | 74 | } |
... | @@ -95,11 +79,6 @@ public class ResourceTest { | ... | @@ -95,11 +79,6 @@ public class ResourceTest { |
95 | assertThat(discrete.isTypeOf(DeviceId.class), is(false)); | 79 | assertThat(discrete.isTypeOf(DeviceId.class), is(false)); |
96 | assertThat(discrete.isTypeOf(PortNumber.class), is(false)); | 80 | assertThat(discrete.isTypeOf(PortNumber.class), is(false)); |
97 | assertThat(discrete.isTypeOf(VlanId.class), is(true)); | 81 | assertThat(discrete.isTypeOf(VlanId.class), is(true)); |
98 | - | ||
99 | - ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); | ||
100 | - assertThat(continuous.isTypeOf(DeviceId.class), is(false)); | ||
101 | - assertThat(continuous.isTypeOf(PortNumber.class), is(false)); | ||
102 | - assertThat(continuous.isTypeOf(Bandwidth.class), is(true)); | ||
103 | } | 82 | } |
104 | 83 | ||
105 | @Test | 84 | @Test |
... | @@ -109,25 +88,19 @@ public class ResourceTest { | ... | @@ -109,25 +88,19 @@ public class ResourceTest { |
109 | assertThat(discrete.isSubTypeOf(PortNumber.class), is(true)); | 88 | assertThat(discrete.isSubTypeOf(PortNumber.class), is(true)); |
110 | assertThat(discrete.isSubTypeOf(VlanId.class), is(true)); | 89 | assertThat(discrete.isSubTypeOf(VlanId.class), is(true)); |
111 | assertThat(discrete.isSubTypeOf(Bandwidth.class), is(false)); | 90 | assertThat(discrete.isSubTypeOf(Bandwidth.class), is(false)); |
112 | - | ||
113 | - ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); | ||
114 | - assertThat(continuous.isSubTypeOf(DeviceId.class), is(true)); | ||
115 | - assertThat(continuous.isSubTypeOf(PortNumber.class), is(true)); | ||
116 | - assertThat(continuous.isSubTypeOf(Bandwidth.class), is(true)); | ||
117 | - assertThat(continuous.isSubTypeOf(VlanId.class), is(false)); | ||
118 | } | 91 | } |
119 | 92 | ||
120 | @Test | 93 | @Test |
121 | public void testBase() { | 94 | public void testBase() { |
122 | - Resource resource = Resources.discrete(D1).resource(); | 95 | + DiscreteResource resource = Resources.discrete(D1).resource(); |
123 | 96 | ||
124 | DeviceId child = (DeviceId) resource.last(); | 97 | DeviceId child = (DeviceId) resource.last(); |
125 | assertThat(child, is(D1)); | 98 | assertThat(child, is(D1)); |
126 | } | 99 | } |
127 | 100 | ||
128 | @Test | 101 | @Test |
129 | - public void testValueOfDiscrete() { | 102 | + public void testValueAs() { |
130 | - Resource resource = Resources.discrete(D1).resource(); | 103 | + DiscreteResource resource = Resources.discrete(D1).resource(); |
131 | 104 | ||
132 | Optional<DeviceId> volume = resource.valueAs(DeviceId.class); | 105 | Optional<DeviceId> volume = resource.valueAs(DeviceId.class); |
133 | assertThat(volume.get(), is(D1)); | 106 | assertThat(volume.get(), is(D1)); |
... | @@ -135,16 +108,8 @@ public class ResourceTest { | ... | @@ -135,16 +108,8 @@ public class ResourceTest { |
135 | 108 | ||
136 | @Test | 109 | @Test |
137 | public void testValueOfRoot() { | 110 | public void testValueOfRoot() { |
138 | - Resource resource = Resource.ROOT; | 111 | + DiscreteResource resource = Resource.ROOT; |
139 | 112 | ||
140 | assertThat(resource.valueAs(Object.class), is(Optional.empty())); | 113 | assertThat(resource.valueAs(Object.class), is(Optional.empty())); |
141 | } | 114 | } |
142 | - | ||
143 | - @Test | ||
144 | - public void testValueOfContinuous() { | ||
145 | - Resource resource = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); | ||
146 | - | ||
147 | - Optional<Double> volume = resource.valueAs(double.class); | ||
148 | - assertThat(volume.get(), is(BW1.bps())); | ||
149 | - } | ||
150 | } | 115 | } | ... | ... |
-
Please register or login to post a comment