blob: cc7f2dca37fb57109f7bc7f437d18d18cde5e860 [file] [log] [blame]
Ray Milkeya7d96ad2014-11-06 12:15:38 -08001/*
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent.constraint;
Ray Milkeya7d96ad2014-11-06 12:15:38 -080017
18import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.Link;
20import org.onosproject.net.resource.Bandwidth;
21import org.onosproject.net.resource.Lambda;
Ray Milkeya7d96ad2014-11-06 12:15:38 -080022
23import com.google.common.testing.EqualsTester;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.contains;
27import static org.hamcrest.Matchers.equalTo;
28import static org.hamcrest.Matchers.is;
29
30/**
31 * Unit tests for Constraint objects.
32 */
33public 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}