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.deleteintent;
9 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;
10 import static org.mockito.Mockito.mock;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.nemo.user.tenantmanager.AAA;
17 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.structure.style.nemo.delete.input.Objects;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.structure.style.nemo.delete.input.Operations;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.StructureStyleNemoDeleteInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.structure.style.nemo.delete.input.Results;
27 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
28 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
31 import com.google.common.util.concurrent.CheckedFuture;
32 import com.google.common.util.concurrent.FutureCallback;
33 import com.google.common.util.concurrent.Futures;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
39 import java.util.List;
40 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserName;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserPassword;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserRoleName;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
46 import static org.junit.Assert.*;
47 import static org.mockito.Mockito.*;
48 public class DeleteIntentTest{
49 private DataBroker dataBroker;
50 private TenantManage tenantManage;
51 private DeleteNode deleteNode;
52 private DeleteConnection deleteConnection;
53 private DeleteFlow deleteFlow;
54 private DeleteOperation deleteOperation;
55 private DeleteResult deleteResult;
57 private Objects objects;
58 private StructureStyleNemoDeleteInput styleNemoDeleteInput;
59 private DeleteIntent deleteintent;
60 private Operations operations;
61 private Results results;
62 private UserId userid;
63 private NodeId nodeid;
64 private ConnectionId connectionid;
65 private FlowId flowid;
66 private List<NodeId> nodeidlist;
67 private List<ConnectionId> connectionidlist;
68 private List<FlowId> flowidlist;
69 private List<OperationId> operationidlist;
70 private OperationId operationid;
73 public void setUp() throws Exception{
74 dataBroker=mock(DataBroker.class);
75 tenantManage=mock(TenantManage.class);
76 deleteNode=mock(DeleteNode.class);
77 deleteConnection=mock(DeleteConnection.class);
78 //deleteFlow=mock(DeleteFlow.class);
79 deleteOperation=mock(DeleteOperation.class);
80 deleteResult=mock(DeleteResult.class);
82 objects=mock(Objects.class);
83 styleNemoDeleteInput=mock(StructureStyleNemoDeleteInput.class);
84 deleteintent=new DeleteIntent(dataBroker,tenantManage);
85 results=mock(Results.class);
86 operations=mock(Operations.class);
87 nodeid=mock(NodeId.class);
88 connectionid=mock(ConnectionId.class);
89 flowid=mock(FlowId.class);
90 nodeidlist=new ArrayList<NodeId>(1);
91 nodeidlist.add(nodeid);
92 connectionidlist=new ArrayList<ConnectionId>(1);
93 connectionidlist.add(connectionid);
94 flowidlist=new ArrayList<FlowId>(1);
95 flowidlist.add(flowid);
96 user=mock(User.class);
97 operationid=mock(OperationId.class);
98 operationidlist=new ArrayList<OperationId>(1);
99 operationidlist.add(operationid);
102 public void styleNemoDeleteOutputTest(){
103 CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);
104 ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
105 when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
106 UserId useridtest=mock(UserId.class);
107 UserName usernametest=mock(UserName.class);
108 UserPassword userpasswordtest=mock(UserPassword.class);
109 UserRoleName userrolenametest=mock(UserRoleName.class);
110 when(styleNemoDeleteInput.getUserId()).thenReturn(useridtest);
112 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn("The user is not exist.");
113 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),"The user is not exist.");
115 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
116 when(styleNemoDeleteInput.getObjects()).thenReturn(null);
117 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),null);
120 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
121 when(styleNemoDeleteInput.getObjects()).thenReturn(objects);
122 when(styleNemoDeleteInput.getResults()).thenReturn(null);
123 when(styleNemoDeleteInput.getOperations()).thenReturn(null);
125 when(styleNemoDeleteInput.getObjects().getNode()).thenReturn(null);
126 when(styleNemoDeleteInput.getObjects().getConnection()).thenReturn(null);
127 when(styleNemoDeleteInput.getObjects().getFlow()).thenReturn(null);
128 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),null);
131 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
132 when(styleNemoDeleteInput.getObjects()).thenReturn(objects);
133 when(styleNemoDeleteInput.getResults()).thenReturn(null);
134 when(styleNemoDeleteInput.getOperations()).thenReturn(null);
136 when(styleNemoDeleteInput.getObjects().getNode()).thenReturn(nodeidlist);
137 when(styleNemoDeleteInput.getObjects().getConnection()).thenReturn(null);
138 when(styleNemoDeleteInput.getObjects().getFlow()).thenReturn(null);
139 when(styleNemoDeleteInput.getUserId()).thenReturn(userid);
140 when(tenantManage.getUser()).thenReturn(user);
141 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),"The node instance null is not exist.");
144 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
145 when(styleNemoDeleteInput.getObjects()).thenReturn(objects);
146 when(styleNemoDeleteInput.getResults()).thenReturn(null);
147 when(styleNemoDeleteInput.getOperations()).thenReturn(null);
149 when(styleNemoDeleteInput.getObjects().getNode()).thenReturn(null);
150 when(styleNemoDeleteInput.getObjects().getConnection()).thenReturn(connectionidlist);
151 when(styleNemoDeleteInput.getObjects().getFlow()).thenReturn(null);
152 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),"The connection instance null is not exit.");
155 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
156 when(styleNemoDeleteInput.getObjects()).thenReturn(objects);
157 when(styleNemoDeleteInput.getResults()).thenReturn(null);
158 when(styleNemoDeleteInput.getOperations()).thenReturn(null);
160 when(styleNemoDeleteInput.getObjects().getNode()).thenReturn(null);
161 when(styleNemoDeleteInput.getObjects().getConnection()).thenReturn(null);
162 when(styleNemoDeleteInput.getObjects().getFlow()).thenReturn(flowidlist);
163 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),"The flow instance null is not exist.");
166 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
167 when(styleNemoDeleteInput.getObjects()).thenReturn(null);
168 when(styleNemoDeleteInput.getResults()).thenReturn(null);
169 when(styleNemoDeleteInput.getOperations()).thenReturn(operations);
171 when(operations.getOperation()).thenReturn(null);
172 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),null);
175 when(styleNemoDeleteInput.getObjects()).thenReturn(null);
176 when(styleNemoDeleteInput.getResults()).thenReturn(null);
177 when(styleNemoDeleteInput.getOperations()).thenReturn(operations);
179 when(operations.getOperation()).thenReturn(operationidlist);
180 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),"The operation instance null is not exist.");
183 when(aaa.checkUser(styleNemoDeleteInput.getUserId())).thenReturn(null);
184 when(styleNemoDeleteInput.getObjects()).thenReturn(null);
185 when(styleNemoDeleteInput.getResults()).thenReturn(results);
186 when(styleNemoDeleteInput.getOperations()).thenReturn(null);
187 Assert.assertEquals(deleteintent.styleNemoDeleteOutput(aaa,styleNemoDeleteInput),null);