Modify nemo-impl partical test files
[nemo.git] / nemo-impl / src / test / java / org / opendaylight / nemo / user / vnspacemanager / structurestyle / deleteintent / DeleteConnectionTest.java
index d0ed22ad1cab45ef7e4d4026c8ceaa83f26e32ca..5eecf5b07f5a77fd9ce57021098d68b9a4c14752 100644 (file)
@@ -1,17 +1,10 @@
-/*
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;
 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;
 import static org.mockito.Mockito.mock;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;
@@ -31,14 +24,23 @@ import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import java.util.List;
+import java.util.*;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import static org.mockito.Mockito.*;
 public class  DeleteConnectionTest{
            private DataBroker dataBroker;
         private TenantManage tenantManage;
         private DeleteConnection deleteconnection;
         private UserId userId;
         private ConnectionId connectionID;
+               private User user;
+               private Objects objects;
+               private Connection connection;
+               private List<Connection> connectionList;
+               private ConnectionId NotconnectionID;
+               private  ConnectionId connectionID2;
+               private   WriteTransaction  writetransaction;
 @org.junit.Before
 public void setUp() throws Exception {
            dataBroker=mock(DataBroker.class);
@@ -46,9 +48,55 @@ public void setUp() throws Exception {
         deleteconnection=mock(DeleteConnection.class);
         userId=mock(UserId.class);
         connectionID=mock(ConnectionId.class);
+               NotconnectionID=mock(ConnectionId.class);
+               connectionID2=connectionID;
+               user=mock(User.class);
+               objects=mock(Objects.class);
+               connection=mock(Connection.class);
+               connectionList=new ArrayList<Connection>(3);
+               connectionList.add(connection);
+               deleteconnection=new DeleteConnection(dataBroker,tenantManage);
+               writetransaction=mock(WriteTransaction.class);
         }
 @org.junit.Test
 public void DeleteConnectionHandlingTest() throws Exception{
-        Assert.assertNull(deleteconnection.DeleteConnectionHandling(userId,connectionID));
+       //no data test
+          CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);
+       ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+          when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+         
+          when(tenantManage.getUser()).thenReturn(null);
+          Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),"There are no connection instances in data store.");
+          //data exists and other branches
+          // branch 1
+          when (tenantManage.getUser()).thenReturn(user);
+          when(user.getObjects()).thenReturn(null);
+          Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),null);
+          //branch 2
+          when(tenantManage.getUser()).thenReturn(user);
+          when(user.getObjects()).thenReturn(objects);
+          when(user.getObjects().getConnection()).thenReturn(null);
+          Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),"There are no connection instances in data store.");
+       //branch 3
+          when(tenantManage.getUser()).thenReturn(user);
+          when(user.getObjects()).thenReturn(objects);
+          when(objects.getConnection()).thenReturn(connectionList);
+          when(connection.getConnectionId()).thenReturn(NotconnectionID);
+          Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),"The connection instance"+connectionID.toString()+ "is not exit. Could not be deleted.");
+       //branch 4
+          when(tenantManage.getUser()).thenReturn(user);
+          when(user.getObjects()).thenReturn(objects);
+          when(objects.getConnection()).thenReturn(connectionList);
+          when(connection.getConnectionId()).thenReturn(connectionID);
+          when(dataBroker.newWriteOnlyTransaction()).thenReturn(writetransaction);
+          CheckedFuture<Void, TransactionCommitFailedException> f;
+          f=mock(CheckedFuture.class);
+          when(writetransaction.submit()).thenReturn(f);
+          Assert.assertEquals(deleteconnection.DeleteConnectionHandling(userId,connectionID),null);
+       //-------
+               Assert.assertNotNull(deleteconnection);
+               Assert.assertNotNull(tenantManage);
+        //Assert.assertNull(deleteconnection.DeleteConnectionHandling(userId,connectionID));
         }
         }
\ No newline at end of file