added partical test files
[nemo.git] / nemo-impl / src / test / java / org / opendaylight / nemo / user / vnspacemanager / languagestyle / QueryTest.java
1 /*
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.nemo.user.vnspacemanager.languagestyle;
9
10 import org.opendaylight.nemo.user.vnspacemanager.languagestyle.Query;
11 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeName;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionName;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.EndNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.MatchItem;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.SubNode;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.IntValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.RangeValue;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.StringValue;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionType;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowName;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.MatchItemName;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.match.item.instance.MatchItemValue;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationName;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.PropertyName;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValues;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ObjectId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment.PrecursorRelationOperator;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConditionParameterName;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment.ConditionParameterMatchPattern;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.ConditionParameterTargetValue;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ActionName;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.ParameterValues;
54 import java.util.LinkedList;
55 import org.junit.Assert;
56 import org.junit.Before;
57 import org.junit.Test;
58 import java.util.*;
59 import java.util.List;
60
61 import static org.mockito.Matchers.any;
62 import static org.mockito.Mockito.mock;
63 import static org.mockito.Mockito.times;
64 import static org.mockito.Mockito.verify;
65 import static org.mockito.Mockito.when;
66 /**
67  * Created by ldzd11 on 2015/12/14.
68  */
69 public class QueryTest {
70
71     private Query query;
72     private ParameterValues parameterValues;
73     private ConditionParameterTargetValue conditionParameterTargetValue;
74     private ActionName actionName;
75     private PrecursorRelationOperator precursorRelationOperator;
76    // private ConditionParameterMatchPattern conditionParameterMatchPattern;
77     private ConditionParameterName conditionParameterName;
78     private ObjectId objectId;
79     private ConditionSegment conditionSegment;
80     private OperationId operationId;
81     private FlowId flowId;
82     private PropertyName propertyName;
83     private NodeId nodeId;
84     private ConnectionId connectionId;
85     private OperationName operationName;
86     private MatchItemValue matchItemValue;
87     private  MatchItemName matchItemName;
88     private FlowName flowName;
89     private NodeName nodeName;
90     private TenantManage tenantManage;
91     private ConnectionType connectionType;
92     private NodeType nodeType;
93     private Objects objects;
94     private User user;
95     private ConnectionName connectionName;
96     private UserId userId;
97     private String item;
98     private String target;
99     private Node node;
100     private List<Node> nodelist;
101     private Connection connection;
102     private List<Connection> connectionList;
103
104     private Flow flow;
105     private List<Flow> flowList;
106
107     private MatchItem matchItem;
108     private List<MatchItem> matchItemList;
109
110     private Operations operations;
111     private Operation operation;
112     private List<Operation> operationList;
113
114     private  SubNode subNode;
115     private List<SubNode> subNodeList;
116
117     private  Action action;
118     private List<Action> actionList;
119
120     private  EndNode endNode;
121     private List<EndNode> endNodeList;
122
123     private Property property;
124     private List<Property> propertyList;
125
126     private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property propertyconnection;
127     private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property> propertyconnectionList;
128
129     private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.Property propertyflow;
130     private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.Property> propertyflowList;
131     private PropertyValues propertyValues;
132
133     private List<ConditionSegment> conditionSegmentList;
134
135
136     @org.junit.Before
137     public void setUp() throws Exception {
138         tenantManage = mock(TenantManage.class);
139         parameterValues = mock(ParameterValues.class);
140         actionName = mock(ActionName.class);
141         conditionParameterTargetValue = mock(ConditionParameterTargetValue.class);
142         //conditionParameterMatchPattern = mock(ConditionParameterMatchPattern.class);
143         conditionParameterName = mock(ConditionParameterName.class);
144        // precursorRelationOperator = mock(PrecursorRelationOperator.class);
145         conditionSegment = mock(ConditionSegment.class);
146         objectId = mock(ObjectId.class);
147         operationId = mock(OperationId.class);
148         flowId = mock(FlowId.class);
149         connectionId = mock(ConnectionId.class);
150         propertyValues = mock(PropertyValues.class);
151         propertyName = mock(PropertyName.class);
152         nodeId = mock(NodeId.class);
153         operationName = mock(OperationName.class);
154         matchItemValue = mock(MatchItemValue.class);
155         matchItemName = mock(MatchItemName.class);
156         flowName = mock(FlowName.class);
157         connectionType = mock(ConnectionType.class);
158         nodeType = mock(NodeType.class);
159         userId = mock(UserId.class);
160         item = new String();
161         target = new String();
162         user = mock(User.class);
163         objects = mock(Objects.class);
164         node=mock(Node.class);
165         nodeName = mock(NodeName.class);
166         nodelist=new ArrayList<Node>(1);
167         nodelist.add(node);
168         connectionName = mock(ConnectionName.class);
169
170         connection = mock(Connection.class);
171         connectionList = new ArrayList<Connection>(1);
172         connectionList.add(connection);
173
174         flow = mock(Flow.class);
175         flowList = new ArrayList<Flow>(1);
176         flowList.add(flow);
177
178         matchItem = mock(MatchItem.class);
179         matchItemList =  new ArrayList<MatchItem>(1);
180         matchItemList.add(matchItem);
181
182         operations = mock(Operations.class);
183         operation = mock(Operation.class);
184         operationList =  new ArrayList<Operation>(1);
185         operationList.add(operation);
186
187         subNode = mock(SubNode.class);
188         subNodeList =  new ArrayList<SubNode>(1);
189         subNodeList.add(subNode);
190
191         endNode = mock(EndNode.class);
192         endNodeList =  new ArrayList<EndNode>(1);
193         endNodeList.add(endNode);
194
195         property = mock(Property.class);
196         propertyList =  new ArrayList<Property>(1);
197         propertyList.add(property);
198
199         propertyconnection = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property.class);
200         propertyconnectionList =  new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property>(1);
201         propertyconnectionList.add(propertyconnection);
202
203         conditionSegment = mock(ConditionSegment.class);
204         conditionSegmentList =  new ArrayList<ConditionSegment>(0);
205         //conditionSegmentList.add(conditionSegment);
206
207         propertyflow = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.Property.class);
208         propertyflowList = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.Property>(1);
209         propertyflowList.add(propertyflow);
210
211         action = mock(Action.class);
212         actionList =  new ArrayList<Action>(1);
213         actionList.add(action);
214
215         query = new Query(tenantManage);
216
217     }
218
219     @org.junit.Test
220     public void testQuery() throws Exception {
221
222         when(tenantManage.getUser()).thenReturn(user);
223         target = new String("test");
224         when(user.getObjects()).thenReturn(objects);
225         when(user.getObjects().getNode()).thenReturn(nodelist);
226         when(node.getNodeName()).thenReturn(nodeName);
227         when(node.getNodeName().getValue()).thenReturn(new String("test"));
228         //to quertNode(user,item,node)
229         item = new String("Type");
230         when(node.getNodeType()).thenReturn(nodeType);
231         when(node.getNodeType().getValue()).thenReturn(new String("node"));
232         Assert.assertEquals(query.query(userId, item, target), "Results:node");
233
234         item = new String("Subnodes");
235         when(node.getSubNode()).thenReturn(subNodeList);
236         when(user.getObjects().getNode()).thenReturn(nodelist);
237         when(subNode.getNodeId()).thenReturn(nodeId);
238         when(node.getNodeId()).thenReturn(nodeId);
239         Assert.assertEquals(query.query(userId, item, target), "Results:test");
240
241         item = new String("Property");
242         when(node.getProperty()).thenReturn(propertyList);
243         when(property.getPropertyName()).thenReturn(propertyName);
244         when(property.getPropertyName().getValue()).thenReturn("propertyname");
245         when(property.getPropertyValues()).thenReturn(propertyValues);
246         when(property.getPropertyValues().getIntValue()).thenReturn(null);
247         when(property.getPropertyValues().getStringValue()).thenReturn(null);
248         when(property.getPropertyValues().getRangeValue()).thenReturn(null);
249         Assert.assertEquals(query.query(userId, item, target), "Results:propertyname:");
250
251         item = new String("exception");
252         when(property.getPropertyName().getValue()).thenReturn(new String("exception"));
253         Assert.assertEquals(query.query(userId, item, target), "Results:");
254
255         when(property.getPropertyName().getValue()).thenReturn(new String("exceptionnull"));
256         Assert.assertEquals(query.query(userId, item, target), "The item " + item + " is not included in " + node.getNodeName().getValue() + ";");
257
258
259         //if
260         when(user.getObjects().getNode()).thenReturn(null);
261         when(user.getObjects().getConnection()).thenReturn(connectionList);
262         when(connection.getConnectionName()).thenReturn(connectionName);
263         when(connection.getConnectionName().getValue()).thenReturn(new String("test"));
264         //to queryConnection(user,item,connection)
265         item = new String("Type");
266         when(connection.getConnectionType()).thenReturn(connectionType);
267         when(connection.getConnectionType().getValue()).thenReturn(new String("connection"));
268         Assert.assertEquals(query.query(userId, item, target), "Results:connection");
269
270         item = new String("Endnodes");
271         when(connection.getEndNode()).thenReturn(endNodeList);
272         when(user.getObjects().getNode()).thenReturn(nodelist);
273         when(endNode.getNodeId()).thenReturn(nodeId);
274         when(node.getNodeId()).thenReturn(nodeId);
275         Assert.assertEquals(query.query(userId, item, target), "Results:test");
276
277         item = new String("Property");
278         when(connection.getProperty()).thenReturn(propertyconnectionList);
279         when(propertyconnection.getPropertyName()).thenReturn(propertyName);
280         when(propertyconnection.getPropertyName().getValue()).thenReturn("propertyname");
281         when(propertyconnection.getPropertyValues()).thenReturn(propertyValues);
282         when(propertyconnection.getPropertyValues().getIntValue()).thenReturn(null);
283         when(propertyconnection.getPropertyValues().getStringValue()).thenReturn(null);
284         when(propertyconnection.getPropertyValues().getRangeValue()).thenReturn(null);
285         Assert.assertEquals(query.query(userId, item, target), "Results:propertyname:");
286
287         item = new String("exception");
288         when(connection.getProperty()).thenReturn(propertyconnectionList);
289         when(propertyconnection.getPropertyName().getValue()).thenReturn("exception");
290         Assert.assertEquals(query.query(userId, item, target), "Results:");
291
292         when(propertyconnection.getPropertyName().getValue()).thenReturn("exceptionnnull");
293         Assert.assertEquals(query.query(userId, item, target), "The item " + item + " is not included in " + connection.getConnectionName().getValue() + ";");
294
295
296         //if
297         when(user.getObjects().getNode()).thenReturn(null);
298         when(user.getObjects().getConnection()).thenReturn(null);
299         when(user.getObjects().getFlow()).thenReturn(flowList);
300         when(flow.getFlowName()).thenReturn(flowName);
301         when(flow.getFlowName().getValue()).thenReturn("test");
302         //to queryFlow(item,flow);
303         item = new String("Match");
304         when(flow.getMatchItem()).thenReturn(matchItemList);
305         when(matchItem.getMatchItemName()).thenReturn(matchItemName);
306         when(matchItem.getMatchItemName().getValue()).thenReturn(new String("flow"));
307         when(matchItem.getMatchItemValue()).thenReturn(matchItemValue);
308         when(matchItem.getMatchItemValue().getIntValue()).thenReturn(null);
309         when(matchItem.getMatchItemValue().getStringValue()).thenReturn(null);
310         when(matchItem.getMatchItemValue().getRangeValue()).thenReturn(null);
311         Assert.assertEquals(query.query(userId, item, target), "Results:flow:");
312
313         item = new String("Property");
314         when(flow.getProperty()).thenReturn(propertyflowList);
315         when(propertyflow.getPropertyName()).thenReturn(propertyName);
316         when(propertyflow.getPropertyName().getValue()).thenReturn(new String("propertyname"));
317         when(propertyflow.getPropertyValues()).thenReturn(propertyValues);
318         when(propertyflow.getPropertyValues().getIntValue()).thenReturn(null);
319         when(propertyflow.getPropertyValues().getStringValue()).thenReturn(null);
320         when(propertyflow.getPropertyValues().getRangeValue()).thenReturn(null);
321         Assert.assertEquals(query.query(userId, item, target), "Results:propertyname:");
322
323         item = new String("exception");
324         when(flow.getProperty()).thenReturn(propertyflowList);
325         when(property.getPropertyName().getValue()).thenReturn(new String("exception"));
326         Assert.assertEquals(query.query(userId, item, target), "Results:");
327
328         when(property.getPropertyName().getValue()).thenReturn(new String("ecxeptionnull"));
329         Assert.assertEquals(query.query(userId, item, target), "The item " + item + " is not included in " + flow.getFlowName().getValue() + ";");
330
331
332         //if
333         when(user.getObjects()).thenReturn(null);
334         when(user.getOperations()).thenReturn(operations);
335         when(user.getOperations().getOperation()).thenReturn(operationList);
336         when(operation.getOperationName()).thenReturn(operationName);
337         when(operation.getOperationName().getValue()).thenReturn(new String("test"));
338         //to queryOperation(user,item,operation);
339         item = new String("Priority");
340         long a = 123;
341         when(operation.getPriority()).thenReturn(a);
342         Assert.assertEquals(query.query(userId, item, target), "Results:" + a);
343
344         item = new String("Target");
345         when(user.getObjects()).thenReturn(objects);
346         when(user.getObjects().getNode()).thenReturn(nodelist);
347         when(node.getNodeId().getValue()).thenReturn(new String("123"));
348         when(operation.getTargetObject()).thenReturn(nodeId);
349         when(operation.getTargetObject().getValue()).thenReturn(new String("123"));
350         when(node.getNodeName()).thenReturn(nodeName);
351         when(node.getNodeName().getValue()).thenReturn(new String("test"));
352
353         when(user.getObjects().getConnection()).thenReturn(connectionList);
354         when(connection.getConnectionId()).thenReturn(connectionId);
355         when(operation.getTargetObject()).thenReturn(connectionId);
356         when(operation.getTargetObject().getValue()).thenReturn(new String("123"));
357         when(connection.getConnectionId().getValue()).thenReturn(new String("123"));
358         when(connection.getConnectionName().getValue()).thenReturn(new String("connectionname"));
359
360         when(user.getObjects().getFlow()).thenReturn(flowList);
361         when(flow.getFlowId()).thenReturn(flowId);
362         when(flow.getFlowId().getValue()).thenReturn(new String("123"));
363         when(operation.getTargetObject()).thenReturn(flowId);
364         when(operation.getTargetObject().getValue()).thenReturn(new String("123"));
365         when(flow.getFlowName().getValue()).thenReturn(new String("flowname"));
366         Assert.assertEquals(query.query(userId, item, target), "Results:testconnectionnameflowname");
367
368         item = new String("Action");
369         when(operation.getAction()).thenReturn(actionList);
370         when(action.getActionName()).thenReturn(actionName);
371         when(action.getActionName().getValue()).thenReturn(new String("actionname"));
372         when(action.getParameterValues()).thenReturn(parameterValues);
373         when(action.getParameterValues().getIntValue()).thenReturn(null);
374         when(action.getParameterValues().getStringValue()).thenReturn(null);
375         when(action.getParameterValues().getRangeValue()).thenReturn(null);
376         Assert.assertEquals(query.query(userId, item, target), "Results:actionname:");
377
378         item = new String("exception");
379         when(operation.getAction()).thenReturn(actionList);
380         when(action.getActionName()).thenReturn(actionName);
381         when(action.getActionName().getValue()).thenReturn(new String("exception"));
382         Assert.assertEquals(query.query(userId, item, target), "Results:exception:");
383
384         when(action.getActionName().getValue()).thenReturn(new String("exceptionnull"));
385         Assert.assertEquals(query.query(userId, item, target), "The item " + item + " is not included in the target " +operation.getOperationName().getValue());
386         //Assert.assertEquals(query.query(userId, item, target), "Results:test" );
387
388         //if
389         when(tenantManage.getUser()).thenReturn(null);
390         Assert.assertEquals(query.query(userId, item, target), "The target " + target + " is not exist in user vn space.");
391
392         target = null;
393         when(tenantManage.getUser()).thenReturn(user);
394         //if
395         item = new String("nodes");
396         //into queryAllNode(user)
397         when(user.getObjects()).thenReturn(objects);
398         when(user.getObjects().getNode()).thenReturn(nodelist);
399
400         when(node.getNodeId()).thenReturn(nodeId);
401         when(node.getNodeName()).thenReturn(nodeName);
402         when(node.getNodeType()).thenReturn(nodeType);
403
404         when(node.getNodeId().getValue()).thenReturn(new String("id"));
405         when(node.getNodeName().getValue()).thenReturn(new String("name2"));
406         when(node.getNodeType().getValue()).thenReturn(new String("type"));
407
408         when(node.getSubNode()).thenReturn(subNodeList);
409         when(subNode.getNodeId()).thenReturn(nodeId);
410
411         when(node.getProperty()).thenReturn(propertyList);
412         when(property.getPropertyName()).thenReturn(propertyName);
413         when(property.getPropertyName().getValue()).thenReturn(new String("property"));
414         when(property.getPropertyValues()).thenReturn(propertyValues);
415         when(property.getPropertyValues().getIntValue()).thenReturn(null);
416         when(property.getPropertyValues().getStringValue()).thenReturn(null);
417         when(property.getPropertyValues().getRangeValue()).thenReturn(null);
418
419         Assert.assertEquals(query.query(userId, item, target), "Results:Id:id Name:name2 Type:type Subnodes:name2Property:property: ");
420
421
422
423
424
425
426
427         //if
428         item = new String("connections");
429         //into queryAllConnection(user);
430         when(user.getObjects()).thenReturn(objects);
431         when(user.getObjects().getConnection()).thenReturn(connectionList);
432         when(connection.getConnectionId()).thenReturn(connectionId);
433         when(connection.getConnectionName()).thenReturn(connectionName);
434         when(connection.getConnectionType()).thenReturn(connectionType);
435         when(connection.getConnectionId().getValue()).thenReturn(new String("id"));
436         when(connection.getConnectionName().getValue()).thenReturn(new String("name"));
437         when(connection.getConnectionType().getValue()).thenReturn(new String("type"));
438         when(connection.getEndNode()).thenReturn(endNodeList);
439         when(user.getObjects().getNode()).thenReturn(nodelist);
440         when(endNode.getNodeId()).thenReturn(nodeId);
441         when(node.getNodeId()).thenReturn(nodeId);
442         when(node.getNodeName().getValue()).thenReturn(new String("name2"));
443
444         when(connection.getProperty()).thenReturn(propertyconnectionList);
445         when(propertyconnection.getPropertyName()).thenReturn(propertyName);
446         when(propertyconnection.getPropertyName().getValue()).thenReturn(new String("property"));
447         when(propertyconnection.getPropertyValues()).thenReturn(propertyValues);
448         when(propertyconnection.getPropertyValues().getIntValue()).thenReturn(null);
449         when(propertyconnection.getPropertyValues().getStringValue()).thenReturn(null);
450         when(propertyconnection.getPropertyValues().getRangeValue()).thenReturn(null);
451
452         Assert.assertEquals(query.query(userId, item, target), "Results:Id:id Name:name Type:type Endnodes:name2 Property:property: ");
453
454
455         //if
456         item = new String("flows");
457         //into queryAllFlow(user)
458         when(user.getObjects()).thenReturn(objects);
459         when(user.getObjects().getFlow()).thenReturn(flowList);
460         when(flow.getFlowId()).thenReturn(flowId);
461         when(flow.getFlowId().getValue()).thenReturn(new String("id"));
462         when(flow.getFlowName().getValue()).thenReturn(new String("name"));
463         when(flow.getMatchItem()).thenReturn(matchItemList);
464         when(matchItem.getMatchItemName().getValue()).thenReturn(new String("name2"));
465         when(matchItem.getMatchItemValue().getIntValue()).thenReturn(null);
466         when(matchItem.getMatchItemValue().getStringValue()).thenReturn(null);
467         when(matchItem.getMatchItemValue().getRangeValue()).thenReturn(null);
468
469         when(flow.getProperty()).thenReturn(propertyflowList);
470         when(propertyflow.getPropertyName()).thenReturn(propertyName);
471         when(propertyflow.getPropertyName().getValue()).thenReturn(new String("property"));
472         when(propertyflow.getPropertyValues()).thenReturn(propertyValues);
473         when(propertyflow.getPropertyValues().getIntValue()).thenReturn(null);
474         when(propertyflow.getPropertyValues().getStringValue()).thenReturn(null);
475         when(propertyflow.getPropertyValues().getRangeValue()).thenReturn(null);
476
477         Assert.assertEquals(query.query(userId, item, target), "Results:Id:id Name:name Match: name2;Property: property: ");
478
479         //if
480         item = new String("operations");
481         //into queryAllOperation(user)'
482         when(user.getOperations()).thenReturn(operations);
483         when(operation.getOperationId()).thenReturn(operationId);
484         when(operation.getOperationId().getValue()).thenReturn(new String("id"));
485         when(operation.getOperationName().getValue()).thenReturn(new String("name"));
486         when(operation.getPriority()).thenReturn(a);
487
488         when(user.getObjects().getNode()).thenReturn(nodelist);
489         when(node.getNodeId()).thenReturn(nodeId);
490         when(operation.getTargetObject()).thenReturn(nodeId);
491         when(node.getNodeName().getValue()).thenReturn(new String("name2"));
492
493         when(user.getObjects().getFlow()).thenReturn(flowList);
494         when(flow.getFlowId()).thenReturn(flowId);
495         when(operation.getTargetObject()).thenReturn(flowId);
496         when(flow.getFlowName().getValue()).thenReturn(new String("name3"));
497
498         when(operation.getConditionSegment()).thenReturn(conditionSegmentList);
499        // when(conditionSegment.getPrecursorRelationOperator()).thenReturn(precursorRelationOperator);
500       //  when(conditionSegment.getPrecursorRelationOperator().getIntValue()).thenReturn(1);//case1
501
502       //  when(conditionSegment.getConditionParameterName()).thenReturn(conditionParameterName);
503         //when(conditionSegment.getConditionParameterName().getValue()).thenReturn(new String("?"));
504        // when(conditionSegment.getConditionParameterMatchPattern()).thenReturn(conditionParameterMatchPattern);
505         //when(conditionSegment.getConditionParameterMatchPattern().getIntValue()).thenReturn(1);//case2
506
507         //when(conditionSegment.getConditionParameterTargetValue()).thenReturn(conditionParameterTargetValue);
508         //when(conditionSegment.getConditionParameterTargetValue().getIntValue()).thenReturn(null);
509        // when(conditionSegment.getConditionParameterTargetValue().getStringValue()).thenReturn(null);
510
511         when(operation.getAction()).thenReturn(actionList);
512         when(action.getActionName()).thenReturn(actionName);
513         when(action.getActionName().getValue()).thenReturn(new String("actionname"));
514         when(action.getParameterValues()).thenReturn(parameterValues);
515         when(action.getParameterValues().getIntValue()).thenReturn(null);
516         when(action.getParameterValues().getStringValue()).thenReturn(null);
517         when(action.getParameterValues().getRangeValue()).thenReturn(null);
518
519         Assert.assertEquals(query.query(userId, item, target), "Results:Id:id Name:name Priority:123 Target:name3 Condition: Action: actionname:)");
520         //else
521         //  Assert.assertEquals(query.query(userId, item, target), "The item is not supported.");
522
523
524
525
526
527         //org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue intValue;
528
529
530
531
532
533
534
535
536     }
537 }