Ray Milkey

Basic equality and creation tests for Constraint objects

Change-Id: Ibcd125ce3070cfbf23c8349dbf950a3352fac44d
1 +/*
2 + * Copyright 2014 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.onlab.onos.net.intent.constraint;
17 +
18 +import org.junit.Test;
19 +import org.onlab.onos.net.Link;
20 +import org.onlab.onos.net.resource.Bandwidth;
21 +import org.onlab.onos.net.resource.Lambda;
22 +
23 +import com.google.common.testing.EqualsTester;
24 +
25 +import static org.hamcrest.MatcherAssert.assertThat;
26 +import static org.hamcrest.Matchers.contains;
27 +import static org.hamcrest.Matchers.equalTo;
28 +import static org.hamcrest.Matchers.is;
29 +
30 +/**
31 + * Unit tests for Constraint objects.
32 + */
33 +public class ConstraintObjectsTest {
34 +
35 + // Bandwidth Constraint
36 +
37 + final BandwidthConstraint bandwidthConstraint1 =
38 + new BandwidthConstraint(Bandwidth.valueOf(100.0));
39 + final BandwidthConstraint bandwidthConstraintSameAs1 =
40 + new BandwidthConstraint(Bandwidth.valueOf(100.0));
41 + final BandwidthConstraint bandwidthConstraint2 =
42 + new BandwidthConstraint(Bandwidth.valueOf(200.0));
43 +
44 + /**
45 + * Checks that the objects were created properly.
46 + */
47 + @Test
48 + public void testBandwidthConstraintCreation() {
49 + assertThat(bandwidthConstraint1.bandwidth().toDouble(), is(equalTo(100.0)));
50 + assertThat(bandwidthConstraintSameAs1.bandwidth().toDouble(), is(equalTo(100.0)));
51 + assertThat(bandwidthConstraint2.bandwidth().toDouble(), is(equalTo(200.0)));
52 + }
53 +
54 + /**
55 + * Checks the correctness of the equals() method.
56 + */
57 + @Test
58 + public void testBandwidthConstraintEquals() {
59 + new EqualsTester()
60 + .addEqualityGroup(bandwidthConstraint1, bandwidthConstraintSameAs1)
61 + .addEqualityGroup(bandwidthConstraint2)
62 + .testEquals();
63 + }
64 +
65 + // Lambda Constraint
66 +
67 + final LambdaConstraint lambdaConstraint1 =
68 + new LambdaConstraint(Lambda.valueOf(100));
69 + final LambdaConstraint lambdaConstraintSameAs1 =
70 + new LambdaConstraint(Lambda.valueOf(100));
71 + final LambdaConstraint lambdaConstraint2 =
72 + new LambdaConstraint(Lambda.valueOf(200));
73 +
74 + /**
75 + * Checks that the objects were created properly.
76 + */
77 + @Test
78 + public void testLambdaConstraintCreation() {
79 + assertThat(lambdaConstraint1.lambda().toInt(), is(equalTo(100)));
80 + assertThat(lambdaConstraintSameAs1.lambda().toInt(), is(equalTo(100)));
81 + assertThat(lambdaConstraint2.lambda().toInt(), is(equalTo(200)));
82 + }
83 +
84 + /**
85 + * Checks the correctness of the equals() method.
86 + */
87 + @Test
88 + public void testLambdaConstraintEquals() {
89 + new EqualsTester()
90 + .addEqualityGroup(lambdaConstraint1, lambdaConstraintSameAs1)
91 + .addEqualityGroup(lambdaConstraint2)
92 + .testEquals();
93 + }
94 +
95 + // LinkType Constraint
96 +
97 + final LinkTypeConstraint linkTypeConstraint1 =
98 + new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL);
99 + final LinkTypeConstraint linkTypeConstraintSameAs1 =
100 + new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL);
101 + final LinkTypeConstraint linkTypeConstraint2 =
102 + new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.DIRECT);
103 +
104 + /**
105 + * Checks that the objects were created properly.
106 + */
107 + @Test
108 + public void testLinkTypeConstraintCreation() {
109 + assertThat(linkTypeConstraint1.isInclusive(), is(true));
110 + assertThat(linkTypeConstraint1.types(),
111 + contains(Link.Type.OPTICAL, Link.Type.TUNNEL));
112 + assertThat(linkTypeConstraintSameAs1.isInclusive(), is(true));
113 + assertThat(linkTypeConstraintSameAs1.types(),
114 + contains(Link.Type.OPTICAL, Link.Type.TUNNEL));
115 + assertThat(linkTypeConstraint2.isInclusive(), is(true));
116 + assertThat(linkTypeConstraint2.types(),
117 + contains(Link.Type.OPTICAL, Link.Type.DIRECT));
118 + }
119 +
120 + /**
121 + * Checks the correctness of the equals() method.
122 + */
123 + @Test
124 + public void testLinkTypeConstraintEquals() {
125 + new EqualsTester()
126 + .addEqualityGroup(linkTypeConstraint1, linkTypeConstraintSameAs1)
127 + .addEqualityGroup(linkTypeConstraint2)
128 + .testEquals();
129 + }
130 +}