Open Kilda Java Documentation
TopologyTests.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.topo;
17 
18 import static java.util.Collections.emptyMap;
19 import static java.util.Collections.singletonMap;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22 
23 import com.google.common.collect.ImmutableMap;
24 import org.junit.Test;
25 
29 public class TopologyTests {
30 
31  @Test
33  Topology t1 = new Topology();
34  Topology t2 = new Topology();
35  assertTrue("Empty topologies are equivalent", t1.equivalent(t2));
36  assertTrue("Empty topologies are equal", t1.equals(t2));
37  }
38 
39  @Test
41  Switch s1 = new Switch("one");
42  Topology t1 = new Topology(singletonMap(s1.getId(),s1), emptyMap());
43  assertTrue("Single Switch topologies, same object are equivalent", t1.equivalent(t1));
44  assertTrue("Single Switch topologies, same object are equal", t1.equals(t1));
45 
46  Switch s2 = new Switch("one");
47  Topology t2 = new Topology(singletonMap(s2.getId(),s2), emptyMap());
48  assertTrue("Single Switch topologies, different object are equivalent", t1.equivalent(t2));
49  assertTrue("Single Switch topologies, different object are equal", t1.equals(t2));
50 
51  Switch s3 = new Switch("three");
52  t1 = new Topology(ImmutableMap.of(s1.getId(),s1, s3.getId(), s3), emptyMap());
53  t2 = new Topology(ImmutableMap.of(s2.getId(),s2, s3.getId(), s3), emptyMap());
54  assertTrue("Multiple Switch topologies, mixed objects are equivalent", t1.equivalent(t2));
55  assertTrue("Multiple Switch topologies, mixed objects are equal", t1.equals(t2));
56 
57  t1 = new Topology(singletonMap(s1.getId(),s1), emptyMap());
58  t2 = new Topology(singletonMap(s3.getId(), s3), emptyMap());
59  assertFalse("Single Switch topology, different switches are not equivalent", t1.equivalent(t2));
60  assertFalse("Single Switch topology, different switches are not equal", t1.equals(t2));
61  }
62 
63  @Test
65  Switch s1 = new Switch("one");
66  Switch s2 = new Switch("one");
67  LinkEndpoint le1 = new LinkEndpoint(s1,null,null);
68  LinkEndpoint le2 = new LinkEndpoint(s2,null,null);
69  Link l1a = new Link(le1, le2);
70  Link l1b = new Link(le1, le2);
71  Link l2a = new Link(le2, le1);
72  Link l2b = new Link(le2, le1);
73  Topology t1 = new Topology(singletonMap(s1.getId(),s1), singletonMap(l1a.getSlug(),l1a));
74  Topology t2 = new Topology(singletonMap(s1.getId(),s1), singletonMap(l1a.getSlug(),l1a));
75  assertTrue("Single Switch-Link topologies, same object are equivalent", t1.equivalent(t2));
76  assertTrue("Single Switch-Link topologies, same object are equal", t1.equals(t2));
77 
78  t1 = new Topology(singletonMap(s1.getId(),s1), singletonMap(l1a.getSlug(),l1a));
79  t2 = new Topology(singletonMap(s2.getId(),s2), singletonMap(l1b.getSlug(),l1b));
80  assertTrue("Single Switch-Link topologies, different object are equivalent", t1.equivalent(t2));
81  assertTrue("Single Switch-Link topologies, different object are equal", t1.equals(t2));
82 
83  Switch s3 = new Switch("three");
84  t1 = new Topology(singletonMap(s3.getId(),s3), singletonMap(l2a.getSlug(),l2a));
85  t2 = new Topology(singletonMap(s3.getId(),s3), singletonMap(l2a.getSlug(),l2a));
86  assertTrue("Multiple Switch topologies, mixed objects are equivalent", t1.equivalent(t2));
87  assertTrue("Multiple Switch topologies, mixed objects are equal", t1.equals(t2));
88 
89  t1 = new Topology(singletonMap(s1.getId(),s1), singletonMap(l1a.getSlug(),l1a));
90  t2 = new Topology(singletonMap(s3.getId(),s3), singletonMap(l2a.getSlug(),l2a));
91  assertFalse("Single Switch topology, different switches are not equivalent", t1.equivalent(t2));
92  assertFalse("Single Switch topology, different switches are not equal", t1.equals(t2));
93 
94  LinkEndpoint le3 = new LinkEndpoint(s3,null,null);
95  Link l3 = new Link(le3, le2);
96  t1 = new Topology(singletonMap(s1.getId(),s1), singletonMap(l1a.getSlug(),l1a));
97  t2 = new Topology(singletonMap(s1.getId(),s1), singletonMap(l3.getSlug(),l3));
98  assertFalse("Single Switch topology, different switches are not equivalent", t1.equivalent(t2));
99  assertFalse("Single Switch topology, different switches are not equal", t1.equals(t2));
100  }
101 }
s1
Definition: plan-c.py:44
boolean equivalent(ITopology other)
Definition: Topology.java:61