Unit tests for some uncovered Intent types
Change-Id: I9ddd0a4f8d12222b6f5c6bc2d127d6082bc0649d
Showing
4 changed files
with
285 additions
and
5 deletions
... | @@ -15,15 +15,70 @@ | ... | @@ -15,15 +15,70 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | +import java.util.Optional; | ||
19 | + | ||
20 | +import org.junit.Before; | ||
18 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | +import org.onlab.packet.MplsLabel; | ||
23 | +import org.onosproject.net.flow.TrafficSelector; | ||
24 | +import org.onosproject.net.flow.TrafficTreatment; | ||
25 | + | ||
26 | +import com.google.common.testing.EqualsTester; | ||
19 | 27 | ||
28 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
29 | +import static org.hamcrest.Matchers.is; | ||
30 | +import static org.hamcrest.core.IsEqual.equalTo; | ||
20 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 31 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
32 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
33 | +import static org.onosproject.net.NetTestTools.connectPoint; | ||
21 | 34 | ||
22 | /** | 35 | /** |
23 | * Unit tests for the MplsIntent class. | 36 | * Unit tests for the MplsIntent class. |
24 | */ | 37 | */ |
25 | 38 | ||
26 | -public class MplsIntentTest { | 39 | +public class MplsIntentTest extends AbstractIntentTest { |
40 | + static final int PRIORITY = 22; | ||
41 | + | ||
42 | + MplsIntent intent1; | ||
43 | + MplsIntent intent2; | ||
44 | + | ||
45 | + Optional<MplsLabel> label1; | ||
46 | + Optional<MplsLabel> label2; | ||
47 | + | ||
48 | + TrafficSelector selector; | ||
49 | + TrafficTreatment treatment; | ||
50 | + | ||
51 | + @Before | ||
52 | + public void mplsIntentTestSetUp() throws Exception { | ||
53 | + | ||
54 | + label1 = Optional.of(MplsLabel.mplsLabel(1)); | ||
55 | + label2 = Optional.of(MplsLabel.mplsLabel(2)); | ||
56 | + | ||
57 | + selector = new IntentTestsMocks.MockSelector(); | ||
58 | + treatment = new IntentTestsMocks.MockTreatment(); | ||
59 | + | ||
60 | + intent1 = MplsIntent.builder() | ||
61 | + .appId(APP_ID) | ||
62 | + .ingressLabel(label1) | ||
63 | + .egressLabel(label2) | ||
64 | + .ingressPoint(connectPoint("in", 1)) | ||
65 | + .egressPoint(connectPoint("out", 1)) | ||
66 | + .selector(selector) | ||
67 | + .treatment(treatment) | ||
68 | + .priority(PRIORITY) | ||
69 | + .build(); | ||
70 | + | ||
71 | + intent2 = MplsIntent.builder() | ||
72 | + .appId(APP_ID) | ||
73 | + .ingressLabel(label1) | ||
74 | + .egressLabel(label2) | ||
75 | + .ingressPoint(connectPoint("in", 2)) | ||
76 | + .egressPoint(connectPoint("out", 2)) | ||
77 | + .selector(selector) | ||
78 | + .treatment(treatment) | ||
79 | + .priority(PRIORITY) | ||
80 | + .build(); | ||
81 | + } | ||
27 | 82 | ||
28 | /** | 83 | /** |
29 | * Checks that the MplsIntent class is immutable. | 84 | * Checks that the MplsIntent class is immutable. |
... | @@ -33,4 +88,30 @@ public class MplsIntentTest { | ... | @@ -33,4 +88,30 @@ public class MplsIntentTest { |
33 | assertThatClassIsImmutable(MplsIntent.class); | 88 | assertThatClassIsImmutable(MplsIntent.class); |
34 | } | 89 | } |
35 | 90 | ||
91 | + /** | ||
92 | + * Checks the operation of equals(), hashCode() and toString() methods. | ||
93 | + */ | ||
94 | + @Test | ||
95 | + public void testEquals() { | ||
96 | + new EqualsTester() | ||
97 | + .addEqualityGroup(intent1) | ||
98 | + .addEqualityGroup(intent2) | ||
99 | + .testEquals(); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Checks that the MplsIntent objects are created correctly. | ||
104 | + */ | ||
105 | + @Test | ||
106 | + public void testContents() { | ||
107 | + assertThat(intent1.appId(), equalTo(APP_ID)); | ||
108 | + assertThat(intent1.ingressLabel(), equalTo(label1)); | ||
109 | + assertThat(intent1.egressLabel(), equalTo(label2)); | ||
110 | + assertThat(intent1.ingressPoint(), equalTo(connectPoint("in", 1))); | ||
111 | + assertThat(intent1.egressPoint(), equalTo(connectPoint("out", 1))); | ||
112 | + assertThat(intent1.selector(), equalTo(intent2.selector())); | ||
113 | + assertThat(intent1.treatment(), equalTo(intent2.treatment())); | ||
114 | + assertThat(intent1.priority(), is(PRIORITY)); | ||
115 | + | ||
116 | + } | ||
36 | } | 117 | } | ... | ... |
... | @@ -15,14 +15,64 @@ | ... | @@ -15,14 +15,64 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | +import java.util.Optional; | ||
19 | + | ||
20 | +import org.junit.Before; | ||
18 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | +import org.onlab.packet.MplsLabel; | ||
23 | +import org.onosproject.net.Path; | ||
24 | +import org.onosproject.net.flow.TrafficSelector; | ||
25 | +import org.onosproject.net.flow.TrafficTreatment; | ||
26 | + | ||
27 | +import com.google.common.testing.EqualsTester; | ||
19 | 28 | ||
29 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
30 | +import static org.hamcrest.Matchers.is; | ||
31 | +import static org.hamcrest.core.IsEqual.equalTo; | ||
20 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 32 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
33 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
34 | +import static org.onosproject.net.NetTestTools.createPath; | ||
21 | 35 | ||
22 | /** | 36 | /** |
23 | * Unit tests for the MplsPathIntent class. | 37 | * Unit tests for the MplsPathIntent class. |
24 | */ | 38 | */ |
25 | -public class MplsPathIntentTest { | 39 | +public class MplsPathIntentTest extends AbstractIntentTest { |
40 | + | ||
41 | + static final int PRIORITY = 777; | ||
42 | + | ||
43 | + MplsPathIntent intent1; | ||
44 | + MplsPathIntent intent2; | ||
45 | + Path defaultPath; | ||
46 | + Optional<MplsLabel> label1; | ||
47 | + Optional<MplsLabel> label2; | ||
48 | + TrafficSelector selector; | ||
49 | + TrafficTreatment treatment; | ||
50 | + | ||
51 | + @Before | ||
52 | + public void mplsPathIntentTestSetUp() { | ||
53 | + defaultPath = createPath("a", "b", "c"); | ||
54 | + selector = new IntentTestsMocks.MockSelector(); | ||
55 | + treatment = new IntentTestsMocks.MockTreatment(); | ||
56 | + | ||
57 | + label1 = Optional.of(MplsLabel.mplsLabel(1)); | ||
58 | + label2 = Optional.of(MplsLabel.mplsLabel(2)); | ||
59 | + intent1 = MplsPathIntent.builder() | ||
60 | + .appId(APP_ID) | ||
61 | + .ingressLabel(label1) | ||
62 | + .egressLabel(label2) | ||
63 | + .path(defaultPath) | ||
64 | + .priority(PRIORITY) | ||
65 | + .build(); | ||
66 | + | ||
67 | + intent2 = MplsPathIntent.builder() | ||
68 | + .appId(APP_ID) | ||
69 | + .ingressLabel(label1) | ||
70 | + .egressLabel(label2) | ||
71 | + .path(defaultPath) | ||
72 | + .priority(PRIORITY) | ||
73 | + .build(); | ||
74 | + } | ||
75 | + | ||
26 | 76 | ||
27 | /** | 77 | /** |
28 | * Checks that the MplsPathIntent class is immutable. | 78 | * Checks that the MplsPathIntent class is immutable. |
... | @@ -32,4 +82,29 @@ public class MplsPathIntentTest { | ... | @@ -32,4 +82,29 @@ public class MplsPathIntentTest { |
32 | assertThatClassIsImmutable(MplsPathIntent.class); | 82 | assertThatClassIsImmutable(MplsPathIntent.class); |
33 | } | 83 | } |
34 | 84 | ||
85 | + /** | ||
86 | + * Checks the operation of equals(), hashCode() and toString() methods. | ||
87 | + */ | ||
88 | + @Test | ||
89 | + public void testEquals() { | ||
90 | + new EqualsTester() | ||
91 | + .addEqualityGroup(intent1) | ||
92 | + .addEqualityGroup(intent2) | ||
93 | + .testEquals(); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Checks that the MPLS path intent objects are created correctly. | ||
98 | + */ | ||
99 | + @Test | ||
100 | + public void testContents() { | ||
101 | + assertThat(intent1.appId(), equalTo(APP_ID)); | ||
102 | + assertThat(intent1.ingressLabel(), equalTo(label1)); | ||
103 | + assertThat(intent1.egressLabel(), equalTo(label2)); | ||
104 | + assertThat(intent1.selector(), equalTo(intent2.selector())); | ||
105 | + assertThat(intent1.treatment(), equalTo(intent2.treatment())); | ||
106 | + assertThat(intent1.priority(), is(PRIORITY)); | ||
107 | + assertThat(intent1.path(), is(defaultPath)); | ||
108 | + } | ||
109 | + | ||
35 | } | 110 | } | ... | ... |
... | @@ -15,11 +15,48 @@ | ... | @@ -15,11 +15,48 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | +import org.hamcrest.Matchers; | ||
19 | +import org.junit.Before; | ||
18 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.onosproject.net.Path; | ||
19 | 22 | ||
23 | +import com.google.common.testing.EqualsTester; | ||
24 | + | ||
25 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
26 | +import static org.hamcrest.Matchers.is; | ||
27 | +import static org.hamcrest.core.IsEqual.equalTo; | ||
20 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
29 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
30 | +import static org.onosproject.net.NetTestTools.connectPoint; | ||
31 | +import static org.onosproject.net.NetTestTools.createPath; | ||
32 | + | ||
33 | +public class OpticalPathIntentTest extends AbstractIntentTest { | ||
34 | + | ||
35 | + static final int PRIORITY = 777; | ||
36 | + | ||
37 | + OpticalPathIntent intent1; | ||
38 | + OpticalPathIntent intent2; | ||
39 | + Path defaultPath; | ||
21 | 40 | ||
22 | -public class OpticalPathIntentTest { | 41 | + @Before |
42 | + public void opticalPathIntentTestSetUp() { | ||
43 | + defaultPath = createPath("a", "b", "c"); | ||
44 | + intent1 = OpticalPathIntent.builder() | ||
45 | + .appId(APP_ID) | ||
46 | + .src(connectPoint("one", 1)) | ||
47 | + .dst(connectPoint("two", 2)) | ||
48 | + .path(defaultPath) | ||
49 | + .priority(PRIORITY) | ||
50 | + .build(); | ||
51 | + | ||
52 | + intent2 = OpticalPathIntent.builder() | ||
53 | + .appId(APP_ID) | ||
54 | + .src(connectPoint("two", 1)) | ||
55 | + .dst(connectPoint("one", 2)) | ||
56 | + .path(defaultPath) | ||
57 | + .priority(PRIORITY) | ||
58 | + .build(); | ||
59 | + } | ||
23 | 60 | ||
24 | /** | 61 | /** |
25 | * Checks that the OpticalPathIntent class is immutable. | 62 | * Checks that the OpticalPathIntent class is immutable. |
... | @@ -29,4 +66,26 @@ public class OpticalPathIntentTest { | ... | @@ -29,4 +66,26 @@ public class OpticalPathIntentTest { |
29 | assertThatClassIsImmutable(OpticalPathIntent.class); | 66 | assertThatClassIsImmutable(OpticalPathIntent.class); |
30 | } | 67 | } |
31 | 68 | ||
69 | + /** | ||
70 | + * Checks the operation of equals(), hashCode() and toString() methods. | ||
71 | + */ | ||
72 | + @Test | ||
73 | + public void testEquals() { | ||
74 | + new EqualsTester() | ||
75 | + .addEqualityGroup(intent1) | ||
76 | + .addEqualityGroup(intent2) | ||
77 | + .testEquals(); | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * Checks that the optical path ntent objects are created correctly. | ||
82 | + */ | ||
83 | + @Test | ||
84 | + public void testContents() { | ||
85 | + assertThat(intent1.appId(), equalTo(APP_ID)); | ||
86 | + assertThat(intent1.src(), Matchers.equalTo(connectPoint("one", 1))); | ||
87 | + assertThat(intent1.dst(), Matchers.equalTo(connectPoint("two", 2))); | ||
88 | + assertThat(intent1.priority(), is(PRIORITY)); | ||
89 | + assertThat(intent1.path(), is(defaultPath)); | ||
90 | + } | ||
32 | } | 91 | } | ... | ... |
... | @@ -15,14 +15,56 @@ | ... | @@ -15,14 +15,56 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | +import org.hamcrest.Matchers; | ||
19 | +import org.junit.Before; | ||
18 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.onosproject.net.flow.TrafficSelector; | ||
22 | +import org.onosproject.net.flow.TrafficTreatment; | ||
19 | 23 | ||
20 | -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | 24 | +import com.google.common.testing.EqualsTester; |
21 | 25 | ||
26 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
27 | +import static org.hamcrest.Matchers.is; | ||
28 | +import static org.hamcrest.core.IsEqual.equalTo; | ||
29 | +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; | ||
30 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
31 | +import static org.onosproject.net.NetTestTools.connectPoint; | ||
22 | /** | 32 | /** |
23 | * Unit tests for the TwoWayP2PIntent class. | 33 | * Unit tests for the TwoWayP2PIntent class. |
24 | */ | 34 | */ |
25 | -public class TwoWayP2PIntentTest { | 35 | +public class TwoWayP2PIntentTest extends AbstractIntentTest { |
36 | + | ||
37 | + TrafficSelector selector; | ||
38 | + TrafficTreatment treatment; | ||
39 | + | ||
40 | + TwoWayP2PIntent intent1; | ||
41 | + TwoWayP2PIntent intent2; | ||
42 | + | ||
43 | + static final int PRIORITY = 12; | ||
44 | + | ||
45 | + @Before | ||
46 | + public void twoWatP2PIntentTestSetUp() { | ||
47 | + selector = new IntentTestsMocks.MockSelector(); | ||
48 | + treatment = new IntentTestsMocks.MockTreatment(); | ||
49 | + | ||
50 | + intent1 = TwoWayP2PIntent.builder() | ||
51 | + .appId(APP_ID) | ||
52 | + .priority(PRIORITY) | ||
53 | + .selector(selector) | ||
54 | + .treatment(treatment) | ||
55 | + .one(connectPoint("one", 1)) | ||
56 | + .two(connectPoint("two", 2)) | ||
57 | + .build(); | ||
58 | + | ||
59 | + intent2 = TwoWayP2PIntent.builder() | ||
60 | + .appId(APP_ID) | ||
61 | + .priority(PRIORITY) | ||
62 | + .selector(selector) | ||
63 | + .treatment(treatment) | ||
64 | + .one(connectPoint("two", 2)) | ||
65 | + .two(connectPoint("three", 2)) | ||
66 | + .build(); | ||
67 | + } | ||
26 | 68 | ||
27 | /** | 69 | /** |
28 | * Checks that the TwoWayP2PIntent class is immutable. | 70 | * Checks that the TwoWayP2PIntent class is immutable. |
... | @@ -32,4 +74,27 @@ public class TwoWayP2PIntentTest { | ... | @@ -32,4 +74,27 @@ public class TwoWayP2PIntentTest { |
32 | assertThatClassIsImmutable(TwoWayP2PIntent.class); | 74 | assertThatClassIsImmutable(TwoWayP2PIntent.class); |
33 | } | 75 | } |
34 | 76 | ||
77 | + /** | ||
78 | + * Checks the operation of equals(), hashCode() and toString() methods. | ||
79 | + */ | ||
80 | + @Test | ||
81 | + public void testEquals() { | ||
82 | + new EqualsTester() | ||
83 | + .addEqualityGroup(intent1) | ||
84 | + .addEqualityGroup(intent2) | ||
85 | + .testEquals(); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Checks that the optical path ntent objects are created correctly. | ||
90 | + */ | ||
91 | + @Test | ||
92 | + public void testContents() { | ||
93 | + assertThat(intent1.appId(), equalTo(APP_ID)); | ||
94 | + assertThat(intent1.one(), Matchers.equalTo(connectPoint("one", 1))); | ||
95 | + assertThat(intent1.two(), Matchers.equalTo(connectPoint("two", 2))); | ||
96 | + assertThat(intent1.priority(), is(PRIORITY)); | ||
97 | + assertThat(intent1.selector(), is(selector)); | ||
98 | + assertThat(intent1.treatment(), is(treatment)); | ||
99 | + } | ||
35 | } | 100 | } | ... | ... |
-
Please register or login to post a comment