blob: 4f86adda15be5b0f51122ec0716cc1f9ef692fc1 [file] [log] [blame]
Ray Milkeya7d96ad2014-11-06 12:15:38 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Ray Milkeya7d96ad2014-11-06 12:15:38 -08003 *
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;
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070019import org.onlab.util.Bandwidth;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.Link;
Brian O'Connor6de2e202015-05-21 14:30:41 -070021import org.onosproject.net.resource.link.LambdaResource;
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
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070037 private final Bandwidth bandwidth1 = Bandwidth.bps(100.0);
38 private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0);
39 private final Bandwidth bandwidth2 = Bandwidth.bps(200.0);
40
Sho SHIMIZUa88db492015-11-23 13:21:04 -080041 final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1);
42 final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1);
43 final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2);
Ray Milkeya7d96ad2014-11-06 12:15:38 -080044
45 /**
46 * Checks that the objects were created properly.
47 */
48 @Test
49 public void testBandwidthConstraintCreation() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -080050 assertThat(bandwidthConstraint1.bandwidth().bps(), is(equalTo(100.0)));
51 assertThat(bandwidthConstraintSameAs1.bandwidth().bps(), is(equalTo(100.0)));
52 assertThat(bandwidthConstraint2.bandwidth().bps(), is(equalTo(200.0)));
Ray Milkeya7d96ad2014-11-06 12:15:38 -080053 }
54
55 /**
56 * Checks the correctness of the equals() method.
57 */
58 @Test
59 public void testBandwidthConstraintEquals() {
60 new EqualsTester()
61 .addEqualityGroup(bandwidthConstraint1, bandwidthConstraintSameAs1)
62 .addEqualityGroup(bandwidthConstraint2)
63 .testEquals();
64 }
65
66 // Lambda Constraint
67
68 final LambdaConstraint lambdaConstraint1 =
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070069 new LambdaConstraint(LambdaResource.valueOf(100));
Ray Milkeya7d96ad2014-11-06 12:15:38 -080070 final LambdaConstraint lambdaConstraintSameAs1 =
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070071 new LambdaConstraint(LambdaResource.valueOf(100));
Ray Milkeya7d96ad2014-11-06 12:15:38 -080072 final LambdaConstraint lambdaConstraint2 =
Sho SHIMIZU94b7ff42015-05-06 17:51:49 -070073 new LambdaConstraint(LambdaResource.valueOf(200));
Ray Milkeya7d96ad2014-11-06 12:15:38 -080074
75 /**
76 * Checks that the objects were created properly.
77 */
78 @Test
79 public void testLambdaConstraintCreation() {
80 assertThat(lambdaConstraint1.lambda().toInt(), is(equalTo(100)));
81 assertThat(lambdaConstraintSameAs1.lambda().toInt(), is(equalTo(100)));
82 assertThat(lambdaConstraint2.lambda().toInt(), is(equalTo(200)));
83 }
84
85 /**
86 * Checks the correctness of the equals() method.
87 */
88 @Test
89 public void testLambdaConstraintEquals() {
90 new EqualsTester()
91 .addEqualityGroup(lambdaConstraint1, lambdaConstraintSameAs1)
92 .addEqualityGroup(lambdaConstraint2)
93 .testEquals();
94 }
95
96 // LinkType Constraint
97
98 final LinkTypeConstraint linkTypeConstraint1 =
99 new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL);
100 final LinkTypeConstraint linkTypeConstraintSameAs1 =
101 new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL);
102 final LinkTypeConstraint linkTypeConstraint2 =
103 new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.DIRECT);
104
105 /**
106 * Checks that the objects were created properly.
107 */
108 @Test
109 public void testLinkTypeConstraintCreation() {
110 assertThat(linkTypeConstraint1.isInclusive(), is(true));
111 assertThat(linkTypeConstraint1.types(),
112 contains(Link.Type.OPTICAL, Link.Type.TUNNEL));
113 assertThat(linkTypeConstraintSameAs1.isInclusive(), is(true));
114 assertThat(linkTypeConstraintSameAs1.types(),
115 contains(Link.Type.OPTICAL, Link.Type.TUNNEL));
116 assertThat(linkTypeConstraint2.isInclusive(), is(true));
117 assertThat(linkTypeConstraint2.types(),
118 contains(Link.Type.OPTICAL, Link.Type.DIRECT));
119 }
120
121 /**
122 * Checks the correctness of the equals() method.
123 */
124 @Test
125 public void testLinkTypeConstraintEquals() {
126 new EqualsTester()
127 .addEqualityGroup(linkTypeConstraint1, linkTypeConstraintSameAs1)
128 .addEqualityGroup(linkTypeConstraint2)
129 .testEquals();
130 }
131}