blob: 95bcd09a6b28ba9174ec287e282bdd32dff729f5 [file] [log] [blame]
Mahesh Poojary Huaweieafd9802015-11-27 12:14:31 +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.portpairgroup.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;
23import java.util.List;
24import java.util.LinkedList;
25
26import org.onosproject.vtnrsc.PortPairId;
27import org.onosproject.vtnrsc.PortPairGroup;
28import org.onosproject.vtnrsc.PortPairGroupId;
29import org.onosproject.vtnrsc.TenantId;
30import org.onosproject.vtnrsc.DefaultPortPairGroup;
31import org.onosproject.vtnrsc.util.VtnStorageServiceTest;
32
33/**
34 * Unit tests for PortPairGroupManager class.
35 */
36public class PortPairGroupManagerTest {
37 final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
38 final TenantId tenantId = TenantId.tenantId("1");
39 final String name = "PortPairGroup";
40 final String description = "PortPairGroup";
41 final List<PortPairId> portPairIdList = new LinkedList<PortPairId>();
42 DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
43 PortPairGroupManager portPairGroupMgr = new PortPairGroupManager();
44 PortPairGroup portPairGroup = null;
45 private final VtnStorageServiceTest storageService = new VtnStorageServiceTest();
46
47 /**
48 * Checks the operation of createPortPairGroup() method.
49 */
50 @Test
51 public void testCreatePortPairGroup() {
52 // initialize port pair group manager
53 portPairGroupMgr.storageService = storageService;
54 portPairGroupMgr.activate();
55
56 // create port-pair-id list
57 PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
58 portPairIdList.add(portPairId);
59 portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
60 portPairIdList.add(portPairId);
61
62 // create port pair
63 portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId).setName(name)
64 .setDescription(description).setPortPairs(portPairIdList).build();
65 assertThat(portPairGroupMgr.createPortPairGroup(portPairGroup), is(true));
66 }
67
68 /**
69 * Checks the operation of exists() method.
70 */
71 @Test
72 public void testExists() {
73 testCreatePortPairGroup();
74 assertThat(portPairGroupMgr.exists(portPairGroupId), is(true));
75 }
76
77 /**
78 * Checks the operation of getPortPairGroupCount() method.
79 */
80 @Test
81 public void testGetPortPairGroupCount() {
82 testCreatePortPairGroup();
83 assertThat(portPairGroupMgr.getPortPairGroupCount(), is(1));
84 }
85
86 /**
87 * Checks the operation of getPortPairGroups() method.
88 */
89 @Test
90 public void testGetPortPairGroups() {
91 testCreatePortPairGroup();
92 final Iterable<PortPairGroup> portPairGroupList = portPairGroupMgr.getPortPairGroups();
93 assertThat(portPairGroupList, is(notNullValue()));
94 assertThat(portPairGroupList.iterator().hasNext(), is(true));
95 }
96
97 /**
98 * Checks the operation of getPortPairGroup() method.
99 */
100 @Test
101 public void testGetPortPairGroup() {
102 testCreatePortPairGroup();
103 assertThat(portPairGroup, is(notNullValue()));
104 assertThat(portPairGroupMgr.getPortPairGroup(portPairGroupId), is(portPairGroup));
105 }
106
107 /**
108 * Checks the operation of updatePortPairGroup() method.
109 */
110 @Test
111 public void testUpdatePortPairGroup() {
112 // create a port pair group
113 testCreatePortPairGroup();
114
115 // new updates
116 // create port-pair-id list
117 final TenantId tenantId2 = TenantId.tenantId("2");
118 final String name2 = "PortPairGroup2";
119 final String description2 = "PortPairGroup2";
120 final List<PortPairId> portPairIdList = new LinkedList<PortPairId>();
121 PortPairId portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
122 portPairIdList.add(portPairId);
123 portPairId = PortPairId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
124 portPairIdList.add(portPairId);
125
126 // create port pair
127 portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId2).setName(name2)
128 .setDescription(description2).setPortPairs(portPairIdList).build();
129 assertThat(portPairGroupMgr.updatePortPairGroup(portPairGroup), is(true));
130 }
131
132 /**
133 * Checks the operation of removePortPairGroup() method.
134 */
135 @Test
136 public void testRemovePortPairGroup() {
137 testCreatePortPairGroup();
138 assertThat(portPairGroupMgr.removePortPairGroup(portPairGroupId), is(true));
139 }
140}