blob: b2a807edda8420e34018e729ef41ebdc723c7c97 [file] [log] [blame]
Mahesh Poojary Huawei59fdb652015-11-27 13:14:10 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Mahesh Poojary Huawei59fdb652015-11-27 13:14:10 +05303 *
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 */
16package org.onosproject.vtnrsc.portpair.impl;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21
22import org.junit.Test;
23
24import org.onosproject.vtnrsc.PortPair;
25import org.onosproject.vtnrsc.PortPairId;
26import org.onosproject.vtnrsc.TenantId;
27import org.onosproject.vtnrsc.DefaultPortPair;
28import org.onosproject.vtnrsc.util.VtnStorageServiceTest;
Bharat saraswal89f5f0d2015-12-11 01:01:37 +053029import org.onosproject.common.event.impl.TestEventDispatcher;
30
31import static org.onosproject.net.NetTestTools.injectEventDispatcher;
Mahesh Poojary Huawei59fdb652015-11-27 13:14:10 +053032
33/**
34 * Unit tests for PortPairManager class.
35 */
36public class PortPairManagerTest {
37 final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
38 final TenantId tenantId = TenantId.tenantId("1");
39 final String name = "PortPair";
40 final String description = "PortPair";
41 final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
42 final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
43 DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
44 PortPairManager portPairMgr = new PortPairManager();
45 PortPair portPair = null;
46 private final VtnStorageServiceTest storageService = new VtnStorageServiceTest();
47
48 /**
49 * Checks the operation of createPortPair() method.
50 */
51 @Test
52 public void testCreatePortPair() {
53 // initialize port pair manager
54 portPairMgr.storageService = storageService;
Bharat saraswal89f5f0d2015-12-11 01:01:37 +053055 injectEventDispatcher(portPairMgr, new TestEventDispatcher());
Mahesh Poojary Huawei59fdb652015-11-27 13:14:10 +053056 portPairMgr.activate();
57
58 // create port pair
59 portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
60 .setDescription(description).setIngress(ingress).setEgress(egress).build();
61 assertThat(portPairMgr.createPortPair(portPair), is(true));
62 }
63
64 /**
65 * Checks the operation of exists() method.
66 */
67 @Test
68 public void testExists() {
69 testCreatePortPair();
70 assertThat(portPairMgr.exists(portPairId), is(true));
71 }
72
73 /**
74 * Checks the operation of getPortPairCount() method.
75 */
76 @Test
77 public void testGetPortPairCount() {
78 testCreatePortPair();
79 assertThat(portPairMgr.getPortPairCount(), is(1));
80 }
81
82 /**
83 * Checks the operation of getPortPairs() method.
84 */
85 @Test
86 public void testGetPortPairs() {
87 testCreatePortPair();
88 final Iterable<PortPair> portPairList = portPairMgr.getPortPairs();
89 assertThat(portPairList, is(notNullValue()));
90 assertThat(portPairList.iterator().hasNext(), is(true));
91 }
92
93 /**
94 * Checks the operation of getPortPair() method.
95 */
96 @Test
97 public void testGetPortPair() {
98 testCreatePortPair();
99 assertThat(portPair, is(notNullValue()));
100 assertThat(portPairMgr.getPortPair(portPairId), is(portPair));
101 }
102
103 /**
104 * Checks the operation of updatePortPair() method.
105 */
106 @Test
107 public void testUpdatePortPair() {
108 // create a port pair
109 testCreatePortPair();
110
111 // new updates
112 final TenantId tenantId2 = TenantId.tenantId("2");
113 final String name2 = "PortPair2";
114 final String description2 = "PortPair2";
115 final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1";
116 final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345";
117 portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId2).setName(name2)
118 .setDescription(description2).setIngress(ingress2).setEgress(egress2).build();
119 assertThat(portPairMgr.updatePortPair(portPair), is(true));
120 }
121
122 /**
123 * Checks the operation of removePortPair() method.
124 */
125 @Test
126 public void testRemovePortPair() {
127 testCreatePortPair();
128 assertThat(portPairMgr.removePortPair(portPairId), is(true));
129 }
130}