2 * Copyright (c) 2016 Huawei, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent;
10 import junit.framework.TestCase;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.ParameterValues;
15 import static org.junit.Assert.*;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
18 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.GetDefinitions;
19 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateTemplateDefinition;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.PropertyName;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.match.item.instance.MatchItemValue;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValues;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.template.definitions.TemplateDefinition;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.definitions.ConnectionDefinition;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.EndNode;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.MatchItem;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.match.item.definitions.MatchItemDefinition;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.definitions.NodeDefinition;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.SubNode;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.definitions.PropertyDefinition;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.StringValue;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.definitions.ActionDefinition;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.parameter.definitions.ConditionParameterDefinition;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping.AbstractIntents;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping.TemplateParameter;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping._abstract.intents._abstract.objects.AbstractConnection;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping._abstract.intents._abstract.objects.AbstractFlow;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping._abstract.intents._abstract.objects.AbstractNode;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping._abstract.intents._abstract.operations.AbstractOperation;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConditionParameterName;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.ConditionParameterTargetValue;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.TemplateName;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping._abstract.intents.AbstractOperations;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.template.rev151201.template.definition.grouping._abstract.intents.AbstractObjects;
49 import java.lang.reflect.Field;
50 import java.lang.reflect.Method;
51 import java.util.ArrayList;
52 import java.util.HashMap;
53 import java.util.List;
55 import static org.mockito.Mockito.*;
57 * Created by zhangmeng on 2015/12/28.
59 public class UpdateTemplateDefinitionTest extends TestCase {
60 private DataBroker dataBroker;
61 private TenantManage tenantManage;
62 private UpdateTemplateDefinition updateTemplateDefinition;
63 private Class<UpdateTemplateDefinition> class1;
65 private Method method;
67 public void setUp() throws Exception {
68 class1 = UpdateTemplateDefinition.class;
69 dataBroker = mock(DataBroker.class);
70 tenantManage = mock(TenantManage.class);
72 updateTemplateDefinition = new UpdateTemplateDefinition(dataBroker,tenantManage);
76 public void testCheckTemplateDefinition() throws Exception {
77 field = class1.getDeclaredField("getDefinitions");
78 field.setAccessible(true);
80 UserId userId = mock(UserId.class);
81 NodeId nodeId = mock(NodeId.class);
82 SubNode subNode = mock(SubNode.class);
83 EndNode endNode = mock(EndNode.class);
84 MatchItem matchItem = mock(MatchItem.class);
85 ObjectId objectId = mock(ObjectId.class);
86 AbstractFlow abstractFlow = mock(AbstractFlow.class);
87 TemplateName templateName = mock(TemplateName.class);
88 ParameterName parameterName = mock(ParameterName.class);
89 AbstractOperation abstractOperation = mock(AbstractOperation.class);
90 TemplateParameter templateParameter = mock(TemplateParameter.class);
91 TemplateDefinition templateDefinition = mock(TemplateDefinition.class);
92 AbstractNode abstractNode = mock(AbstractNode.class);
93 AbstractIntents abstractIntents = mock(AbstractIntents.class);
94 AbstractObjects abstractObjects = mock(AbstractObjects.class);
95 AbstractOperations abstractOperations = mock(AbstractOperations.class);
96 AbstractConnection abstractConnection = mock(AbstractConnection.class);
97 GetDefinitions getDefinitions = mock(GetDefinitions.class);
98 List<TemplateParameter> list = new ArrayList<TemplateParameter>();
99 List<AbstractNode> nodeList = new ArrayList<AbstractNode>();
100 List<SubNode> subNodeList = new ArrayList<SubNode>();
101 List<AbstractConnection> connectionList = new ArrayList<AbstractConnection>();
102 List<EndNode> endNodeList = new ArrayList<EndNode>();
103 List<AbstractFlow> flowList = new ArrayList<AbstractFlow>();
104 List<MatchItem> matchItemList = new ArrayList<MatchItem>();
105 List<AbstractOperation> operationList = new ArrayList<AbstractOperation>();
106 Map<TemplateName, TemplateDefinition> map = mock(Map.class);
107 Map<NodeType, NodeDefinition> nodeDefinitions = mock(Map.class);
108 Map<MatchItemName, MatchItemDefinition> matchItemDefinitionMap = mock(Map.class);
110 list.add(templateParameter);
111 nodeList.add(abstractNode);
112 subNodeList.add(subNode);
113 endNodeList.add(endNode);
114 connectionList.add(abstractConnection);
115 flowList.add(abstractFlow);
116 matchItemList.add(matchItem);
117 operationList.add(abstractOperation);
119 when(tenantManage.getTempalteDefinition(userId))
123 when(templateDefinition.getTemplateName()).thenReturn(templateName);
124 when(map.containsKey(templateDefinition.getTemplateName())).thenReturn(true);
125 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The template " + templateDefinition.getTemplateName().getValue() + " has been defined."));
126 verify(tenantManage, times(2)).getTempalteDefinition(userId);
128 when(templateDefinition.getTemplateParameter()).thenReturn(list);
129 when(templateParameter.getParameterName()).thenReturn(parameterName);
130 when(templateParameter.getParameterValueType()).thenReturn(TemplateParameter.ParameterValueType.Int);
131 when(templateDefinition.getAbstractIntents()).thenReturn(abstractIntents);
132 // when(abstractIntents.getAbstractOperations())
133 // .thenReturn(null);
134 when(abstractIntents.getAbstractObjects()).thenReturn(abstractObjects);
135 when(abstractObjects.getAbstractNode())
136 .thenReturn(nodeList) //1
137 .thenReturn(nodeList) //1
138 .thenReturn(nodeList) //1
139 .thenReturn(nodeList) //1
140 .thenReturn(null) //1
141 .thenReturn(nodeList)//2
142 .thenReturn(nodeList)//2
147 .thenReturn(nodeList)//3
148 .thenReturn(nodeList);//3
149 when(abstractNode.getNodeId()).thenReturn(nodeId);
150 when(abstractNode.getSubNode())
151 .thenReturn(subNodeList)
152 .thenReturn(subNodeList)
154 when(subNode.getNodeId()).thenReturn(null);
155 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The sub node is not defined."));
156 verify(abstractNode,times(2)).getSubNode();
157 verify(abstractObjects,times(2)).getAbstractNode();
158 //get into method "checkNodeTemplate" args(abstractNode,map)
159 field.set(updateTemplateDefinition, getDefinitions);
160 when(abstractNode.getNodeType()).thenReturn(mock(NodeType.class));
161 when(getDefinitions.getNodeDefinition()).thenReturn(nodeDefinitions);
162 when(nodeDefinitions.containsKey(any(NodeType.class))).thenReturn(false);
163 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The node type " + abstractNode.getNodeType().getValue() + " is not defined."));
164 verify(abstractNode,times(3)).getSubNode();
165 verify(abstractObjects, times(4)).getAbstractNode();
167 when(abstractObjects.getAbstractConnection())
168 .thenReturn(connectionList)//1
169 .thenReturn(connectionList)//1
170 .thenReturn(connectionList)//1
171 .thenReturn(connectionList)//1
174 .thenReturn(connectionList)//2
175 .thenReturn(connectionList);//2
176 when(abstractConnection.getEndNode()).thenReturn(endNodeList);
177 when(endNode.getNodeId()).thenReturn(null);
178 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The end node is not exist."));
179 verify(abstractObjects,times(7)).getAbstractNode();
180 verify(abstractObjects,times(2)).getAbstractConnection();
181 // Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The end node is not exist."));
182 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("There are no end nodes exist."));
183 verify(abstractObjects, times(9)).getAbstractNode();
184 verify(abstractObjects, times(4)).getAbstractConnection();
186 when(abstractObjects.getAbstractFlow())
187 .thenReturn(flowList)//1
188 .thenReturn(flowList)//1
190 .thenReturn(flowList)//2
191 .thenReturn(flowList);//2
192 //get into method "checkFlowTemplate" args(abstractFlow,map)
193 when(getDefinitions.getMatchItemDefinition()).thenReturn(matchItemDefinitionMap);
194 when(abstractFlow.getMatchItem()).thenReturn(matchItemList);
195 when(matchItem.getMatchItemName()).thenReturn(mock(MatchItemName.class));
196 when(matchItemDefinitionMap.containsKey(any(MatchItemName.class))).thenReturn(false);
197 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The match item " + matchItem.getMatchItemName().getValue() + " is not defined."));
198 verify(abstractObjects, times(10)).getAbstractNode();
199 verify(abstractObjects, times(5)).getAbstractConnection();
200 verify(abstractObjects, times(2)).getAbstractFlow();
202 when(abstractIntents.getAbstractOperations()).thenReturn(abstractOperations);
203 when(abstractOperations.getAbstractOperation())
204 .thenReturn(operationList)
205 .thenReturn(operationList)
207 when(abstractOperation.getTargetObject()).thenReturn(objectId);
208 Assert.assertTrue(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition).equals("The target is not exist."));
209 // System.out.println(updateTemplateDefinition.checkTemplateDefinition(userId, templateDefinition) + "dfsfsdfsfds");
210 verify(abstractObjects, times(13)).getAbstractNode();
211 verify(abstractObjects, times(8)).getAbstractConnection();
212 verify(abstractObjects, times(5)).getAbstractFlow();
218 public void testCheckNodeTemplate() throws Exception{
219 method = class1.getDeclaredMethod("checkNodeTemplate",new Class[]{
223 method.setAccessible(true);
224 field = class1.getDeclaredField("getDefinitions");
225 field.setAccessible(true);
227 GetDefinitions getDefinitions = mock(GetDefinitions.class);
228 AbstractNode node = mock(AbstractNode.class);
229 NodeType nodeType = mock(NodeType.class);
230 NodeDefinition nodeDefinition = mock(NodeDefinition.class);
231 PropertyName propertyName = mock(PropertyName.class);
232 Property property = mock(Property.class);
233 StringValue stringValue = mock(StringValue.class);
234 PropertyValues propertyValues = mock(PropertyValues.class);
235 PropertyDefinition.PropertyValueType type = PropertyDefinition.PropertyValueType.String;
236 PropertyDefinition propertyDefinition = mock(PropertyDefinition.class);
237 TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
238 List<Property> properties = new ArrayList<Property>();
239 List<StringValue> stringValues = new ArrayList<StringValue>();
240 List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>();
241 Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
242 Map<NodeType, NodeDefinition> nodeDefinitions = new HashMap<NodeType, NodeDefinition>();
244 parameterValueTypeMap.put(new ParameterName("ParameterName"),valueType);
246 field.set(updateTemplateDefinition, getDefinitions);
247 when(getDefinitions.getNodeDefinition()).thenReturn(nodeDefinitions);
248 when(node.getNodeType()).thenReturn(nodeType);
249 when(nodeType.getValue()).thenReturn("test");
251 Assert.assertTrue(method.invoke(updateTemplateDefinition,node,parameterValueTypeMap).equals("The node type " + node.getNodeType().getValue() + " is not defined."));
252 verify(node,times(3)).getNodeType();
254 nodeDefinitions.put(nodeType, nodeDefinition);
255 propertyDefinitions.add(propertyDefinition);
256 properties.add(property);
257 stringValues.add(stringValue);
258 Assert.assertTrue(nodeDefinitions.get(nodeType) == nodeDefinition);
259 when(nodeDefinition.getPropertyDefinition()).thenReturn(propertyDefinitions);
260 when(propertyDefinition.getPropertyName()).thenReturn(propertyName);
261 when(propertyName.getValue()).thenReturn("test");
262 when(node.getProperty())
264 .thenReturn(properties);
265 Assert.assertTrue(method.invoke(updateTemplateDefinition, node, parameterValueTypeMap) == null);
266 when(property.getPropertyName())
267 .thenReturn(mock(PropertyName.class))
268 .thenReturn(propertyName);
269 Assert.assertTrue(method.invoke(updateTemplateDefinition, node, parameterValueTypeMap).equals("The property name " + property.getPropertyName().getValue() + " is not defined."));
270 when(propertyDefinition.getPropertyValueType())
271 .thenReturn(PropertyDefinition.PropertyValueType.Int)
273 // System.out.println("type" + type.getIntValue());
274 Assert.assertTrue(method.invoke(updateTemplateDefinition, node, parameterValueTypeMap) == null);
275 when(property.getPropertyValues()).thenReturn(propertyValues);
276 when(propertyValues.getStringValue()).thenReturn(stringValues);
277 when(stringValue.getValue()).thenReturn(new String("ParameterName"));
278 Assert.assertTrue(method.invoke(updateTemplateDefinition, node, parameterValueTypeMap).equals("The property " + property.getPropertyName().getValue() + " type is not right."));
283 public void testCheckConnectionTemplate() throws Exception{
284 method = class1.getDeclaredMethod("checkConnectionTemplate", new Class[]{
285 AbstractConnection.class,
288 method.setAccessible(true);
289 field = class1.getDeclaredField("getDefinitions");
290 field.setAccessible(true);
292 GetDefinitions getDefinitions = mock(GetDefinitions.class);
293 AbstractConnection connection = mock(AbstractConnection.class);
294 ConnectionDefinition connectionDefinition = mock(ConnectionDefinition.class);
295 ConnectionType connectionType = mock(ConnectionType.class);
296 PropertyDefinition propertyDefinition = mock(PropertyDefinition.class);
297 PropertyName propertyName = mock(PropertyName.class);
298 PropertyValues propertyValues = mock(PropertyValues.class);
299 StringValue stringValue = mock(StringValue.class);
300 PropertyDefinition.PropertyValueType type = PropertyDefinition.PropertyValueType.String;
301 TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
302 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property
303 property = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property.class);
304 List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property>
305 properties = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property>();
306 List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>();
307 List<StringValue> stringValues = new ArrayList<StringValue>();
308 Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
309 Map<ConnectionType, ConnectionDefinition> connDefinitions = new HashMap<ConnectionType, ConnectionDefinition>();
311 field.set(updateTemplateDefinition, getDefinitions);
312 propertyDefinitions.add(propertyDefinition);
313 properties.add(property);
314 stringValues.add(stringValue);
315 parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType);
317 when(getDefinitions.getConnectionDefinition()).thenReturn(connDefinitions);
318 when(connection.getConnectionType()).thenReturn(connectionType);
319 when(connectionType.getValue()).thenReturn("test");
321 Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap).equals("The connection type " + connection.getConnectionType().getValue() + " is not defined."));
323 connDefinitions.put(connectionType, connectionDefinition);
324 when(connectionDefinition.getPropertyDefinition()).thenReturn(propertyDefinitions);
325 when(propertyDefinition.getPropertyName()).thenReturn(propertyName);
326 when(connection.getProperty())
328 .thenReturn(properties);
329 Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap) == null);
330 when(property.getPropertyName())
331 .thenReturn(mock(PropertyName.class))
332 .thenReturn(propertyName);
333 when(propertyName.getValue()).thenReturn("test");
334 Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap).equals("The property name " + property.getPropertyName().getValue() + " is not defined."));
335 Assert.assertTrue(type.getIntValue() == 0);
336 when(propertyDefinition.getPropertyValueType())
337 .thenReturn(PropertyDefinition.PropertyValueType.Int)
339 Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap) == null);
340 verify(propertyDefinition).getPropertyValueType();
341 when(property.getPropertyValues()).thenReturn(propertyValues);
342 when(propertyValues.getStringValue()).thenReturn(stringValues);
343 when(stringValue.getValue()).thenReturn(new String("ParameterName"));
344 Assert.assertTrue(parameterValueTypeMap.get(new ParameterName("ParameterName")) == valueType);
345 // System.out.println((String) method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap));
346 // System.out.println("valuetype" + valueType.getIntValue());
347 Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap).equals("The property " + property.getPropertyName().getValue() + " type is not right."));
348 verify(stringValue).getValue();
352 public void testCheckFlowTemplate() throws Exception{
353 method = class1.getDeclaredMethod("checkFlowTemplate",new Class[]{
357 method.setAccessible(true);
358 field = class1.getDeclaredField("getDefinitions");
359 field.setAccessible(true);
361 GetDefinitions getDefinitions = mock(GetDefinitions.class);
362 AbstractFlow flow = mock(AbstractFlow.class);
363 MatchItem matchItem = mock(MatchItem.class);
364 List<MatchItem> matchItemList = new ArrayList<MatchItem>();
365 MatchItemValue matchItemValue = mock(MatchItemValue.class);
366 MatchItemName matchItemName = mock(MatchItemName.class);
367 MatchItemDefinition matchItemDefinition = mock(MatchItemDefinition.class);
368 MatchItemDefinition.MatchItemValueType type = MatchItemDefinition.MatchItemValueType.String;
369 TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
370 Map<MatchItemName, MatchItemDefinition> matchItemDefinitionMap = new HashMap<MatchItemName, MatchItemDefinition>();
371 Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
373 field.set(updateTemplateDefinition, getDefinitions);
374 parameterValueTypeMap.put(new ParameterName("ParameterName"),valueType);
376 when(getDefinitions.getMatchItemDefinition()).thenReturn(matchItemDefinitionMap);
377 when(flow.getMatchItem()).thenReturn(matchItemList);
378 Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap) == null);
379 matchItemList.add(matchItem);
380 when(matchItem.getMatchItemName()).thenReturn(matchItemName);
381 when(matchItemName.getValue()).thenReturn("test");
382 Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap).equals("The match item " + matchItem.getMatchItemName().getValue() +" is not defined."));
384 matchItemDefinitionMap.put(matchItemName,matchItemDefinition);
385 Assert.assertTrue(matchItemDefinitionMap.containsKey(matchItemName));
386 when(matchItemDefinition.getMatchItemValueType())
387 .thenReturn(MatchItemDefinition.MatchItemValueType.Int)
389 Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap) == null);
390 when(matchItem.getMatchItemValue()).thenReturn(matchItemValue);
391 when(matchItemValue.getStringValue()).thenReturn("ParameterName");
392 Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap).equals("The match item " + "ParameterName" +" type is not right."));
397 public void testCheckOperationTemplate() throws Exception{
398 method = class1.getDeclaredMethod("checkOperationTemplate",new Class[]{
399 AbstractOperation.class,
402 method.setAccessible(true);
403 field = class1.getDeclaredField("getDefinitions");
404 field.setAccessible(true);
406 GetDefinitions getDefinitions = mock(GetDefinitions.class);
407 Action action = mock(Action.class);
408 ActionName actionName = mock(ActionName.class);
409 ActionDefinition actionDefinition = mock(ActionDefinition.class);
410 AbstractOperation operation = mock(AbstractOperation.class);
411 ConditionSegment conditionSegment = mock(ConditionSegment.class);
412 ParameterName parameterName = mock(ParameterName.class);
413 ParameterValues parameterValues = mock(ParameterValues.class);
414 ConditionParameterName conditionParameterName = mock(ConditionParameterName.class);
415 ConditionParameterDefinition definition = mock(ConditionParameterDefinition.class);
416 ConditionParameterDefinition conditionParameterDefinition = mock(ConditionParameterDefinition.class);
417 ConditionParameterTargetValue conditionParameterTargetValue = mock(ConditionParameterTargetValue.class);
418 ConditionParameterDefinition.ParameterValueType type = ConditionParameterDefinition.ParameterValueType.String;
419 TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
420 ActionDefinition.ParameterValueType type1 = ActionDefinition.ParameterValueType.String;
421 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue
422 stringValue = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue.class);
423 List<Action> actionList = new ArrayList<Action>();
424 List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue>
425 stringValues = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue>();
426 List<ConditionSegment> conditionSegmentList = new ArrayList<ConditionSegment>();
427 Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
428 Map<ActionName, ActionDefinition> actionDefinitionMap = new HashMap<ActionName, ActionDefinition>();
429 Map<ParameterName, ConditionParameterDefinition> conditionParameterDefinitionMap = mock(Map.class);
431 field.set(updateTemplateDefinition, getDefinitions);
432 conditionSegmentList.add(conditionSegment);
433 parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType);
434 conditionParameterDefinitionMap.put(parameterName, conditionParameterDefinition);
436 when(getDefinitions.getActionDefinition()).thenReturn(actionDefinitionMap);
437 when(getDefinitions.getConditionParameterDefinition()).thenReturn(conditionParameterDefinitionMap);
438 when(operation.getConditionSegment())
440 .thenReturn(conditionSegmentList);
441 when(operation.getAction())
443 .thenReturn(actionList);
444 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
446 when(conditionSegment.getConditionParameterName())
447 .thenReturn(conditionParameterName);
448 when(conditionParameterDefinitionMap.containsKey(conditionSegment.getConditionParameterName()))
451 when(parameterName.getValue()).thenReturn("test");
452 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The Condition " + conditionSegment.getConditionParameterName().getValue() + " is not defined."));
453 when(conditionSegment.getConditionParameterTargetValue())
455 .thenReturn(conditionParameterTargetValue);
456 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
457 when(conditionParameterDefinitionMap.get(conditionSegment.getConditionParameterName())).thenReturn(definition);
458 when(definition.getParameterValueType())
459 .thenReturn(ConditionParameterDefinition.ParameterValueType.Int)
461 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
462 when(conditionParameterTargetValue.getStringValue()).thenReturn("ParameterName");
463 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The condition " + conditionSegment.getConditionParameterName().getValue() + " type is not right."));
466 conditionSegmentList.clear();
467 actionList.add(action);
468 stringValues.add(stringValue);
470 when(action.getActionName()).thenReturn(actionName);
471 when(actionName.getValue()).thenReturn("test");
472 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The action " + action.getActionName().getValue() + " is not defined."));
473 actionDefinitionMap.put(actionName, actionDefinition);
474 when(action.getParameterValues())
476 .thenReturn(parameterValues);
477 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null);
478 when(actionDefinition.getParameterValueType()).thenReturn(type1);
479 when(parameterValues.getStringValue()).thenReturn(stringValues);
480 when(stringValue.getValue()).thenReturn("ParameterName");
481 Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The action " + action.getActionName().getValue() +" type is not right."));