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