2 * Copyright (c) 2015 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 org.junit.Before;
11 import org.junit.Test;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.nemo.user.tenantmanager.AAA;
14 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.StructureStyleNemoUpdateInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Results;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
25 import java.util.List;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.LinkedList;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
34 import java.util.List;
36 import static org.mockito.Matchers.any;
37 import static org.mockito.Mockito.mock;
38 import static org.mockito.Mockito.times;
39 import static org.mockito.Mockito.verify;
40 import static org.mockito.Mockito.when;
41 import com.google.common.util.concurrent.CheckedFuture;
42 import java.lang.reflect.Field;
43 import java.lang.reflect.Method;
44 import java.util.ArrayList;
45 import java.util.List;
46 import java.lang.reflect.Field;
47 import java.lang.reflect.Method;
48 import java.util.HashMap;
49 import java.util.List;
51 import java.util.concurrent.ExecutionException;
52 import java.util.concurrent.TimeUnit;
53 import java.util.concurrent.TimeoutException;
54 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Results;
57 import static org.junit.Assert.*;
60 * Created by ldzd11 on 2015/12/22.
62 public class UpdateIntentTest {
63 private UpdateIntent updateIntent;
64 private DataBroker dataBroker;
65 private TenantManage tenantManage;
67 private UserId userId;
68 private Objects objects;
70 private List<Node> nodeList;
71 private Connection connection;
72 private List<Connection> connectionList;
74 private List<Flow> flowList;
75 private Operations operations;
76 private Operation operation;
77 private List<Operation> operationList;
78 private Results results;
79 private StructureStyleNemoUpdateInput structureStyleNemoUpdateInput;
82 public void setUp() throws Exception {
83 dataBroker = mock(DataBroker.class);
84 tenantManage = mock(TenantManage.class);
85 aaa = mock(AAA.class);
86 structureStyleNemoUpdateInput = mock(StructureStyleNemoUpdateInput.class);
87 userId = mock(UserId.class);
88 objects = mock(Objects.class);
89 node = mock(Node.class);
90 nodeList = new ArrayList<Node>(1);
92 operations = mock(Operations.class);
93 operation = mock(Operation.class);
94 operationList = new ArrayList<Operation>(1);
95 operationList.add(operation);
97 connection = mock(Connection.class);
98 connectionList = new ArrayList<Connection>(1);
99 connectionList.add(connection);
100 results = mock(Results.class);
102 flow = mock(Flow.class);
103 flowList = new ArrayList<Flow>(1);
108 updateIntent = new UpdateIntent(dataBroker,tenantManage);
113 public void testUpdateIntent() throws Exception {
114 when(structureStyleNemoUpdateInput.getUserId()).thenReturn(userId);
115 when(aaa.checkUser(structureStyleNemoUpdateInput.getUserId())).thenReturn(null);
117 when(structureStyleNemoUpdateInput.getObjects()).thenReturn(objects);
119 when(structureStyleNemoUpdateInput.getObjects().getNode()).thenReturn(nodeList);
121 Class<UpdateIntent> class_1 = UpdateIntent.class;
122 Field field_1 = class_1.getDeclaredField("updateNode");
123 field_1.setAccessible(true);
125 UpdateNode updateNode_1 = mock(UpdateNode.class);
126 field_1.set(updateIntent,updateNode_1);
127 when(updateNode_1.NodeHandling(userId,node)).thenReturn(new String("node success"));
128 Assert.assertEquals(updateIntent.updateIntent(aaa, structureStyleNemoUpdateInput), "node success");
131 when(structureStyleNemoUpdateInput.getObjects().getNode()).thenReturn(null);
132 when(structureStyleNemoUpdateInput.getObjects().getConnection()).thenReturn(connectionList);
134 Field field_2 = class_1.getDeclaredField("updateConnection");
135 field_2.setAccessible(true);
136 UpdateConnection updateConnection = mock(UpdateConnection.class);
137 field_2.set(updateIntent, updateConnection);
139 when(updateConnection.ConnectionHandling(userId,connection)).thenReturn(new String("connection success"));
140 Assert.assertEquals(updateIntent.updateIntent(aaa, structureStyleNemoUpdateInput), "connection success");
143 when(structureStyleNemoUpdateInput.getObjects().getNode()).thenReturn(null);
144 when(structureStyleNemoUpdateInput.getObjects().getConnection()).thenReturn(null);
145 when(structureStyleNemoUpdateInput.getObjects().getFlow()).thenReturn(flowList);
147 Field field_3 = class_1.getDeclaredField("updateFlow");
148 field_3.setAccessible(true);
149 UpdateFlow updateFlow = mock(UpdateFlow.class);
150 field_3.set(updateIntent, updateFlow);
151 when(updateFlow.FlowHandling(userId,flow)).thenReturn(new String("flow success"));
152 Assert.assertEquals(updateIntent.updateIntent(aaa, structureStyleNemoUpdateInput), "flow success");
155 when(structureStyleNemoUpdateInput.getObjects()).thenReturn(null);
156 when(structureStyleNemoUpdateInput.getOperations()).thenReturn(operations);
157 when(structureStyleNemoUpdateInput.getOperations().getOperation()).thenReturn(operationList);
160 Field field_4 = class_1.getDeclaredField("updateOperation");
161 field_4.setAccessible(true);
162 UpdateOperation updateOperation = mock(UpdateOperation.class);
163 field_4.set(updateIntent, updateOperation);
164 when(updateOperation.OperationHandling(userId,operation)).thenReturn(new String("operation success"));
165 Assert.assertEquals(updateIntent.updateIntent(aaa, structureStyleNemoUpdateInput), "operation success");
169 when(structureStyleNemoUpdateInput.getObjects()).thenReturn(null);
170 when(structureStyleNemoUpdateInput.getOperations()).thenReturn(null);
171 when(structureStyleNemoUpdateInput.getResults()).thenReturn(results);
173 Field field_5 = class_1.getDeclaredField("updateResult");
174 field_5.setAccessible(true);
175 UpdateResult updateResult = mock(UpdateResult.class);
176 field_5.set(updateIntent, updateResult);
177 when(updateResult.ResultHandling(userId, results)).thenReturn(new String("result success"));
178 Assert.assertEquals(updateIntent.updateIntent(aaa, structureStyleNemoUpdateInput), "result success");