Modify nemo-impl partical test files 71/30371/1
authorGaoJie <gaojieusy@163.com>
Mon, 30 Nov 2015 09:50:19 +0000 (17:50 +0800)
committerGaoJie <gaojieusy@163.com>
Mon, 30 Nov 2015 09:51:09 +0000 (17:51 +0800)
Change-Id: Ie2d24658cd471d8b20d45331fb0a231a48fe6828
Signed-off-by: GaoJie <gaojieusy@163.com>
nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/deleteintent/DeleteConnectionTest.java
nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/deleteintent/DeleteFlowTest.java
nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/deleteintent/DeleteNodeTest.java
nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/deleteintent/DeleteOperationTest.java
nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/structurestyle/deleteintent/DeleteResultTest.java

index 9719a45dd18023ed3090b4b1fd46935c7d2ebea1..5eecf5b07f5a77fd9ce57021098d68b9a4c14752 100644 (file)
@@ -1,24 +1,46 @@
-/*
- * 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.ConnectionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import com.google.common.util.concurrent.CheckedFuture;
+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);
@@ -26,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
index 54b83be9112e940c89c90d5cf7a0cc543d7bd105..3a5daa59706b72129b358651df9541356211417d 100644 (file)
@@ -1,34 +1,95 @@
-/*
- * 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.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import com.google.common.util.concurrent.CheckedFuture;
+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.*;
+import java.util.List;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
 public class DeleteFlowTest{
        private DataBroker dataBroker;
     private TenantManage tenantManage;
        private DeleteFlow deleteflow;
        private UserId userId;
     private    FlowId flowId;
+       private Objects objects;
+       private User  user;
+       private List<Flow> flowlist;
+       private Flow flow;
+       private FlowId notflowId;
+       private   WriteTransaction  writetransaction;
        @org.junit.Before
        public void setUp() throws Exception {
                dataBroker=mock(DataBroker.class);
                tenantManage=mock(TenantManage.class);
-               deleteflow=mock(DeleteFlow.class);
+               deleteflow=new DeleteFlow(dataBroker,tenantManage);
                userId=mock(UserId.class);
                flowId=mock(FlowId.class);
+               objects=mock(Objects.class);
+               user=mock(User.class);
+               flow=mock(Flow.class);
+               notflowId=mock(FlowId.class);
+               flowlist=new ArrayList<Flow>(1);
+               flowlist.add(flow);
+               writetransaction=mock(WriteTransaction.class);
        }
        @org.junit.Test
        public void  DeleteFlowHandlingTest() throws Exception{
-               Assert.assertNull(deleteflow.DeleteFlowHandling(userId,flowId));
+        CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);
+     ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+        when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+
+     //no data test
+        when(tenantManage.getUser()).thenReturn(null);
+        Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),"There are no user in the data store.");
+        //data exists and other branches
+        //branch 1
+       when(tenantManage.getUser()).thenReturn(user);
+       when(user.getObjects()).thenReturn(null);
+       Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),null);
+       //branch 2
+       when(tenantManage.getUser()).thenReturn(user);
+       when(user.getObjects()).thenReturn(objects);
+       when(user.getObjects().getFlow()).thenReturn(null);
+       Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),"There are no flow instances in the data store.");
+       //branch 3
+       when(tenantManage.getUser()).thenReturn(user);
+       when(user.getObjects()).thenReturn(objects);
+       when(user.getObjects().getFlow()).thenReturn(flowlist);
+       when(flow.getFlowId()).thenReturn(notflowId);
+       Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),"The flow instance" +flowId.toString()+"is not exist. Could not be deleted.");
+       //branch 4
+       when(tenantManage.getUser()).thenReturn(user);
+       when(user.getObjects()).thenReturn(objects);
+       when(user.getObjects().getFlow()).thenReturn(flowlist);
+       when(flow.getFlowId()).thenReturn(flowId);
+       when(dataBroker.newWriteOnlyTransaction()).thenReturn(writetransaction);
+       CheckedFuture<Void, TransactionCommitFailedException> f;
+       f=mock(CheckedFuture.class);
+       when(writetransaction.submit()).thenReturn(f);
+       Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),null);
        }
 }
index 901dc665d5a5dae6138612aeedd3057cfd965055..264bf593375c91db6431b2cb0e62837d1ecfa1a8 100644 (file)
@@ -1,34 +1,93 @@
-/*\r
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;\r
 import static org.mockito.Mockito.mock;\r
-\r
 import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
 import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.NodeKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;\r
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;\r
+import com.google.common.util.concurrent.CheckedFuture;\r
+import com.google.common.util.concurrent.FutureCallback;\r
+import com.google.common.util.concurrent.Futures;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import java.util.List;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Mockito.*;\r
+import java.util.*;\r
 public class DeleteNodeTest{\r
        private DataBroker dataBroker;\r
     private TenantManage tenantManage;\r
        private UserId  userid;\r
        private NodeId  nodeid;\r
        private DeleteNode deletenode;\r
+       private User user;\r
+       private Objects objects;\r
+       private  Node node;\r
+       private NodeId notnodeid;\r
+       private List<Node> nodeList;\r
+       private   WriteTransaction  writetransaction;\r
        @org.junit.Before\r
        public void setUp() throws Exception{\r
                dataBroker=mock(DataBroker.class);\r
                tenantManage=mock(TenantManage.class);\r
         userid=mock(UserId.class);     \r
                nodeid=mock(NodeId.class);\r
-               deletenode=mock(DeleteNode.class);\r
+               deletenode=new DeleteNode(dataBroker,tenantManage);\r
+               user=mock(User.class);\r
+               objects=mock(Objects.class);\r
+               node=mock(Node.class);\r
+               notnodeid=mock(NodeId.class);\r
+               nodeList=new ArrayList<Node>(1);\r
+               nodeList.add(node);\r
+               writetransaction=mock(WriteTransaction.class);\r
        }\r
        @org.junit.Test\r
     public void DeleNodeHandlingTest(){\r
-               Assert.assertNull(deletenode.DeleNodeHandling(userid,nodeid));\r
+        CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);\r
+     ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);\r
+        when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);\r
+    //branch 1\r
+    when(tenantManage.getUser()).thenReturn(null);\r
+    Assert.assertEquals(deletenode.DeleNodeHandling(userid,nodeid),"There are no user in data store.");        \r
+       //branch 2\r
+       when(tenantManage.getUser()).thenReturn(user);\r
+       when(user.getObjects()).thenReturn(null);\r
+       Assert.assertEquals(deletenode.DeleNodeHandling(userid,nodeid),null);\r
+   //branch 3\r
+       when(tenantManage.getUser()).thenReturn(user);\r
+       when(user.getObjects()).thenReturn(objects);\r
+       when(objects.getNode()).thenReturn(null);\r
+       Assert.assertEquals(deletenode.DeleNodeHandling(userid,nodeid),"There are no nodes instances in data store.");\r
+       //branch 4\r
+       when(tenantManage.getUser()).thenReturn(user);\r
+       when(user.getObjects()).thenReturn(objects);\r
+       when(objects.getNode()).thenReturn(nodeList);\r
+       when(node.getNodeId()).thenReturn(notnodeid);\r
+       Assert.assertEquals(deletenode.DeleNodeHandling(userid,nodeid),"The node instance" +nodeid.toString()+"is not exist.Could not be deleted");\r
+       //branch 5\r
+       when(tenantManage.getUser()).thenReturn(user);\r
+       when(user.getObjects()).thenReturn(objects);\r
+       when(objects.getNode()).thenReturn(nodeList);\r
+       when(node.getNodeId()).thenReturn(nodeid);\r
+       when(dataBroker.newWriteOnlyTransaction()).thenReturn(writetransaction);\r
+       CheckedFuture<Void, TransactionCommitFailedException> f;\r
+       f=mock(CheckedFuture.class);\r
+       when(writetransaction.submit()).thenReturn(f);\r
+       Assert.assertEquals(deletenode.DeleNodeHandling(userid,nodeid),null);\r
        }\r
 }\r
index 4ead7bf2561c52be074715c3ebc2f46b62f96455..4c97735c992ad31054855c43e25b8d8243fa0dd9 100644 (file)
@@ -1,34 +1,93 @@
-/*\r
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;\r
 import static org.mockito.Mockito.mock;\r
-\r
 import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
 import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;\r
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;\r
+import com.google.common.util.concurrent.CheckedFuture;\r
+import com.google.common.util.concurrent.FutureCallback;\r
+import com.google.common.util.concurrent.Futures;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import java.util.List;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
+import static org.junit.Assert.*;\r
+import static org.mockito.Mockito.*;\r
+import java.util.*;\r
 public class DeleteOperationTest{\r
        private DataBroker dataBroker;\r
     private TenantManage tenantManage;\r
        private UserId userId;\r
+       private User user;\r
     private    OperationId operationId;\r
        private DeleteOperation deleteoperation;\r
+       private Operations operations;\r
+       private Operation operation;\r
+       private OperationId notoperationId;\r
+       private List<Operation> operationList;\r
+       private   WriteTransaction  writetransaction;\r
        @org.junit.Before\r
        public void setUp() throws Exception{\r
        dataBroker=mock(DataBroker.class);\r
        tenantManage=mock(TenantManage.class);\r
     userId=mock(UserId.class);\r
     operationId=mock(OperationId.class);\r
-    deleteoperation=mock(DeleteOperation.class);       \r
+       user=mock(User.class);\r
+       operation=mock(Operation.class);\r
+       notoperationId=mock(OperationId.class);\r
+    deleteoperation=new DeleteOperation(dataBroker,tenantManage);\r
+    operations=mock(Operations.class);\r
+    operationList=new ArrayList<Operation>(1);\r
+       operationList.add(operation);\r
+    writetransaction=mock(WriteTransaction.class);\r
        }\r
        @org.junit.Test\r
        public void DeleteOperationhandlingTest(){\r
-               Assert.assertNull(deleteoperation.DeleteOperationhandling(userId,operationId));\r
+        CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);\r
+     ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);\r
+        when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);\r
+               //branch 1\r
+               when(tenantManage.getUser()).thenReturn(null);\r
+               Assert.assertEquals(deleteoperation.DeleteOperationhandling(userId,operationId),"There are no user in the data store.");\r
+               //branch 2\r
+               when(tenantManage.getUser()).thenReturn(user);\r
+               when(user.getOperations()).thenReturn(null);\r
+               Assert.assertEquals(deleteoperation.DeleteOperationhandling(userId,operationId),null);\r
+               //branch 3\r
+               when(tenantManage.getUser()).thenReturn(user);\r
+               when(user.getOperations()).thenReturn(operations);      \r
+        when(operations.getOperation()).thenReturn(null);\r
+        Assert.assertEquals(deleteoperation.DeleteOperationhandling(userId,operationId),"There are no operation instances in the data store.");                \r
+           //branch 4\r
+               when(tenantManage.getUser()).thenReturn(user);\r
+               when(user.getOperations()).thenReturn(operations);      \r
+        when(operations.getOperation()).thenReturn(operationList);\r
+               when(operation.getOperationId()).thenReturn(notoperationId);\r
+               Assert.assertEquals(deleteoperation.DeleteOperationhandling(userId,operationId),"The operation instance" +operationId.toString()+"is not exist. Could not be deleted.");\r
+           //branch 5\r
+               when(tenantManage.getUser()).thenReturn(user);\r
+               when(user.getOperations()).thenReturn(operations);      \r
+        when(operations.getOperation()).thenReturn(operationList);\r
+               when(operation.getOperationId()).thenReturn(operationId);\r
+               when(dataBroker.newWriteOnlyTransaction()).thenReturn(writetransaction);\r
+           CheckedFuture<Void, TransactionCommitFailedException> f;\r
+           f=mock(CheckedFuture.class);\r
+           when(writetransaction.submit()).thenReturn(f);\r
+               Assert.assertEquals(deleteoperation.DeleteOperationhandling(userId,operationId),null);\r
        }\r
 }
\ No newline at end of file
index da879ceeaefc336617a575c4d435e065791d0f19..b2cce97c51416868d3d987ce546d066206e79624 100644 (file)
@@ -1,14 +1,9 @@
-/*\r
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;\r
 import static org.mockito.Mockito.mock;\r
-\r
 import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.structure.style.nemo.delete.input.Results;\r
 public class DeleteResultTest{\r