blob: 95912433d0df06d774a33fef78c7b186cb72e12e [file] [log] [blame]
Ray Milkeya7d96ad2014-11-06 12:15:38 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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;
Ray Milkeya7d96ad2014-11-06 12:15:38 -080021
22import com.google.common.testing.EqualsTester;
23
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.contains;
26import static org.hamcrest.Matchers.equalTo;
27import static org.hamcrest.Matchers.is;
28
29/**
30 * Unit tests for Constraint objects.
31 */
32public class ConstraintObjectsTest {
33
34 // Bandwidth Constraint
35
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070036 private final Bandwidth bandwidth1 = Bandwidth.bps(100.0);
37 private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0);
38 private final Bandwidth bandwidth2 = Bandwidth.bps(200.0);
39
Sho SHIMIZUa88db492015-11-23 13:21:04 -080040 final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1);
41 final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1);
42 final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2);
Ray Milkeya7d96ad2014-11-06 12:15:38 -080043
44 /**
45 * Checks that the objects were created properly.
46 */
47 @Test
48 public void testBandwidthConstraintCreation() {
Sho SHIMIZUa88db492015-11-23 13:21:04 -080049 assertThat(bandwidthConstraint1.bandwidth().bps(), is(equalTo(100.0)));
50 assertThat(bandwidthConstraintSameAs1.bandwidth().bps(), is(equalTo(100.0)));
51 assertThat(bandwidthConstraint2.bandwidth().bps(), is(equalTo(200.0)));
Ray Milkeya7d96ad2014-11-06 12:15:38 -080052 }
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
Ray Milkeya7d96ad2014-11-06 12:15:38 -080065 // LinkType Constraint
66
67 final LinkTypeConstraint linkTypeConstraint1 =
68 new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL);
69 final LinkTypeConstraint linkTypeConstraintSameAs1 =
70 new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.TUNNEL);
71 final LinkTypeConstraint linkTypeConstraint2 =
72 new LinkTypeConstraint(true, Link.Type.OPTICAL, Link.Type.DIRECT);
73
74 /**
75 * Checks that the objects were created properly.
76 */
77 @Test
78 public void testLinkTypeConstraintCreation() {
79 assertThat(linkTypeConstraint1.isInclusive(), is(true));
80 assertThat(linkTypeConstraint1.types(),
81 contains(Link.Type.OPTICAL, Link.Type.TUNNEL));
82 assertThat(linkTypeConstraintSameAs1.isInclusive(), is(true));
83 assertThat(linkTypeConstraintSameAs1.types(),
84 contains(Link.Type.OPTICAL, Link.Type.TUNNEL));
85 assertThat(linkTypeConstraint2.isInclusive(), is(true));
86 assertThat(linkTypeConstraint2.types(),
87 contains(Link.Type.OPTICAL, Link.Type.DIRECT));
88 }
89
90 /**
91 * Checks the correctness of the equals() method.
92 */
93 @Test
94 public void testLinkTypeConstraintEquals() {
95 new EqualsTester()
96 .addEqualityGroup(linkTypeConstraint1, linkTypeConstraintSameAs1)
97 .addEqualityGroup(linkTypeConstraint2)
98 .testEquals();
99 }
100}