1 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;
2 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;
3 import static org.mockito.Mockito.mock;
5 import org.junit.Assert;
6 import org.junit.Before;
8 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
9 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.ConnectionKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import com.google.common.util.concurrent.CheckedFuture;
23 import com.google.common.util.concurrent.FutureCallback;
24 import com.google.common.util.concurrent.Futures;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import java.util.List;
29 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
30 import static org.mockito.Mockito.*;
31 public class DeleteConnectionTest{
32 private DataBroker dataBroker;
33 private TenantManage tenantManage;
34 private DeleteConnection deleteconnection;
35 private UserId userId;
36 private ConnectionId connectionID;
38 private Objects objects;
39 private Connection connection;
40 private List<Connection> connectionList;
41 private ConnectionId NotconnectionID;
42 private ConnectionId connectionID2;
43 private WriteTransaction writetransaction;
45 public void setUp() throws Exception {
46 dataBroker=mock(DataBroker.class);
47 tenantManage=mock(TenantManage.class);
48 deleteconnection=mock(DeleteConnection.class);
49 userId=mock(UserId.class);
50 connectionID=mock(ConnectionId.class);
51 NotconnectionID=mock(ConnectionId.class);
52 connectionID2=connectionID;
53 user=mock(User.class);
54 objects=mock(Objects.class);
55 connection=mock(Connection.class);
56 connectionList=new ArrayList<Connection>(3);
57 connectionList.add(connection);
58 deleteconnection=new DeleteConnection(dataBroker,tenantManage);
59 writetransaction=mock(WriteTransaction.class);
62 public void DeleteConnectionHandlingTest() throws Exception{
64 CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);
65 ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
66 when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
68 when(tenantManage.getUser()).thenReturn(null);
69 Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),"There are no connection instances in data store.");
70 //data exists and other branches
72 when (tenantManage.getUser()).thenReturn(user);
73 when(user.getObjects()).thenReturn(null);
74 Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),null);
76 when(tenantManage.getUser()).thenReturn(user);
77 when(user.getObjects()).thenReturn(objects);
78 when(user.getObjects().getConnection()).thenReturn(null);
79 Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),"There are no connection instances in data store.");
81 when(tenantManage.getUser()).thenReturn(user);
82 when(user.getObjects()).thenReturn(objects);
83 when(objects.getConnection()).thenReturn(connectionList);
84 when(connection.getConnectionId()).thenReturn(NotconnectionID);
85 Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),"The connection instance"+connectionID.toString()+ "is not exit. Could not be deleted.");
87 when(tenantManage.getUser()).thenReturn(user);
88 when(user.getObjects()).thenReturn(objects);
89 when(objects.getConnection()).thenReturn(connectionList);
90 when(connection.getConnectionId()).thenReturn(connectionID);
91 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writetransaction);
92 CheckedFuture<Void, TransactionCommitFailedException> f;
93 f=mock(CheckedFuture.class);
94 when(writetransaction.submit()).thenReturn(f);
95 Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),null);
97 Assert.assertNotNull(deleteconnection);
98 Assert.assertNotNull(tenantManage);
99 //Assert.assertNull(deleteconnection.DeleteConnectionHandling(userId,connectionID));