2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.nemo.user.vnspacemanager.languagestyle.updateintentlang;
\r
10 import junit.framework.TestCase;
\r
11 import org.junit.Assert;
\r
12 import org.junit.Before;
\r
13 import org.junit.Test;
\r
14 import static org.mockito.Mockito.*;
\r
15 import static org.junit.Assert.*;
\r
17 import java.util.ArrayList;
\r
18 import java.util.List;
\r
19 import java.util.HashMap;
\r
20 import java.util.LinkedHashMap;
\r
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
23 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
\r
24 import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;
\r
25 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateOperation;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationBuilder;
\r
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationKey;
\r
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
\r
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.ParameterValuesBuilder;
\r
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue;
\r
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueBuilder;
\r
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueKey;
\r
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValue;
\r
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValueBuilder;
\r
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue;
\r
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueBuilder;
\r
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueKey;
\r
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment;
\r
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegmentBuilder;
\r
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegmentKey;
\r
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.ConditionParameterTargetValueBuilder;
\r
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action;
\r
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.ActionBuilder;
\r
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.ActionKey;
\r
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;
\r
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationName;
\r
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationId;
\r
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeName;
\r
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId;
\r
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionName;
\r
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;
\r
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowName;
\r
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;
\r
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
\r
64 * Created by Thomas Liu on 2015/12/15.
\r
66 public class UpdateOperationLangTest extends TestCase {
\r
68 private UpdateOperationLang updateOperationLangTest;
\r
69 private DataBroker dataBroker;
\r
70 private TenantManage tenantManage;
\r
71 private UserId userId;
\r
72 private String operationname;
\r
73 private String target;
\r
74 private String priority;
\r
75 private LinkedHashMap<String, LinkedHashMap<String,String>> conditions,actions;
\r
76 private LinkedHashMap<String,String> condition,action;
\r
77 private Operations operation;
\r
78 private List<Operation> operationList;
\r
79 private Objects object;
\r
80 private List<Flow> flows;
\r
81 private List<Node> nodes;
\r
82 private List<Connection> connections;
\r
87 public void setUp() throws Exception {
\r
88 dataBroker = mock(DataBroker.class);
\r
89 tenantManage = mock(TenantManage.class);
\r
90 updateOperationLangTest = new UpdateOperationLang(dataBroker,tenantManage);
\r
91 conditions = new LinkedHashMap<String, LinkedHashMap<String,String>>();
\r
92 actions = new LinkedHashMap<String, LinkedHashMap<String,String>>();
\r
93 operation = mock(Operations.class);
\r
94 operationList = new ArrayList<Operation>(){{add(mock(Operation.class));}};
\r
95 operationname = new String("o1");
\r
96 object = mock(Objects.class);
\r
97 flows = new ArrayList<Flow>(){{add(mock(Flow.class));}};
\r
98 nodes = new ArrayList<Node>(){{add(mock(Node.class));}};
\r
99 connections = new ArrayList<Connection>(){{add(mock(Connection.class));}};
\r
100 user = mock(User.class);
\r
101 conditions = new LinkedHashMap<String, LinkedHashMap<String,String>>();
\r
102 actions = new LinkedHashMap<String, LinkedHashMap<String,String>>();
\r
107 public void testOperationHandling() throws Exception {
\r
109 doNothing().when(tenantManage).fetchVNSpace(userId);
\r
110 when(tenantManage.getUser()).thenReturn(user);
\r
112 when(user.getOperations()).thenReturn(operation);
\r
113 when(user.getOperations()).thenReturn(operation);
\r
114 when(operation.getOperation()).thenReturn(operationList);
\r
115 when(user.getOperations()).thenReturn(operation);
\r
116 when(operation.getOperation()).thenReturn(operationList);
\r
118 when(operationList.get(0).getOperationName()).thenReturn(new OperationName("o1"));
\r
119 when(operationList.get(0).getOperationId()).thenReturn(new OperationId("11111111-1111-1111-1111-111111111111"));
\r
121 when(user.getObjects()).thenReturn(object);
\r
123 when(user.getObjects()).thenReturn(object);
\r
124 when(object.getNode()).thenReturn(nodes);
\r
125 when(user.getObjects()).thenReturn(object);
\r
126 when(object.getNode()).thenReturn(nodes);
\r
127 when(nodes.get(0).getNodeName()).thenReturn(new NodeName("node1"));
\r
128 when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));
\r
130 when(user.getObjects()).thenReturn(object);
\r
131 when(object.getConnection()).thenReturn(connections);
\r
132 when(user.getObjects()).thenReturn(object);
\r
133 when(object.getConnection()).thenReturn(connections);
\r
134 when(connections.get(0).getConnectionName()).thenReturn(new ConnectionName("connection1"));
\r
135 when(connections.get(0).getConnectionId()).thenReturn(new ConnectionId("11111111-1111-1111-1111-111111111111"));
\r
138 when(user.getObjects()).thenReturn(object);
\r
139 when(object.getFlow()).thenReturn(flows);
\r
140 when(user.getObjects()).thenReturn(object);
\r
141 when(object.getFlow()).thenReturn(flows);
\r
142 when(flows.get(0).getFlowName()).thenReturn(new FlowName("flow1"));
\r
143 when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));
\r
146 condition = new LinkedHashMap<String,String>(){{
\r
147 put(new String("group"),NEMOConstants.string);
\r
149 conditions.put(",a,equal",condition);
\r
150 conditions.put("not,b,not_equal",condition);
\r
151 conditions.put("and,c,greater_than",condition);
\r
152 condition = new LinkedHashMap<String,String>(){{
\r
153 put(new String("100"),NEMOConstants.integer);
\r
155 conditions.put("or,d,less_than",condition);
\r
156 conditions.put("not,e,not_less_than",condition);
\r
157 conditions.put("and,f,not_greater_than",condition);
\r
158 condition = new LinkedHashMap<String,String>(){{
\r
159 put(new String("100,200"),NEMOConstants.range);
\r
161 conditions.put("or,g,between",condition);
\r
163 action = new LinkedHashMap<String,String>(){{
\r
164 //put(new String("1"),NEMOConstants.range);
\r
165 put(new String("group"),NEMOConstants.string);
\r
166 put(new String("100"),NEMOConstants.integer);
\r
167 put(new String("100,200"),NEMOConstants.range);
\r
169 actions.put(new String("action1"),action);
\r
171 when(user.getObjects()).thenReturn(object);
\r
173 when(user.getObjects()).thenReturn(object);
\r
175 when(object.getNode()).thenReturn(nodes);
\r
176 when(user.getObjects()).thenReturn(object);
\r
177 when(object.getNode()).thenReturn(nodes);
\r
178 when(nodes.get(0).getNodeName()).thenReturn(new NodeName("node1"));
\r
179 when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));
\r
180 when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));
\r
182 when(object.getConnection()).thenReturn(connections);
\r
183 when(user.getObjects()).thenReturn(object);
\r
184 when(object.getConnection()).thenReturn(connections);
\r
185 when(connections.get(0).getConnectionName()).thenReturn(new ConnectionName("connection1"));
\r
186 when(connections.get(0).getConnectionId()).thenReturn(new ConnectionId("11111111-1111-1111-1111-111111111111"));
\r
187 when(connections.get(0).getConnectionId()).thenReturn(new ConnectionId("11111111-1111-1111-1111-111111111111"));
\r
190 when(user.getObjects()).thenReturn(object);
\r
191 when(object.getFlow()).thenReturn(flows);
\r
192 when(user.getObjects()).thenReturn(object);
\r
193 when(object.getFlow()).thenReturn(flows);
\r
194 when(flows.get(0).getFlowName()).thenReturn(new FlowName("flow1"));
\r
195 when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));
\r
196 when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));
\r
200 updateOperationLangTest.OperationHandling(userId,operationname,target,priority,conditions,actions);
\r