Ray Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Ray Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.constraint; |
Ray Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 19 | import org.onlab.util.Bandwidth; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.net.Link; |
Ray Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 21 | |
| 22 | import com.google.common.testing.EqualsTester; |
| 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.contains; |
| 26 | import static org.hamcrest.Matchers.equalTo; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for Constraint objects. |
| 31 | */ |
| 32 | public class ConstraintObjectsTest { |
| 33 | |
| 34 | // Bandwidth Constraint |
| 35 | |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 36 | 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 SHIMIZU | a88db49 | 2015-11-23 13:21:04 -0800 | [diff] [blame] | 40 | final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1); |
| 41 | final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1); |
| 42 | final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2); |
Ray Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Checks that the objects were created properly. |
| 46 | */ |
| 47 | @Test |
| 48 | public void testBandwidthConstraintCreation() { |
Sho SHIMIZU | a88db49 | 2015-11-23 13:21:04 -0800 | [diff] [blame] | 49 | 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 Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 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 | |
Ray Milkey | a7d96ad | 2014-11-06 12:15:38 -0800 | [diff] [blame] | 65 | // 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 | } |