Modify nemo-impl partical test files
[nemo.git] / nemo-impl / src / test / java / org / opendaylight / nemo / user / vnspacemanager / structurestyle / deleteintent / DeleteFlowTest.java
1 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;
2 import org.opendaylight.nemo.user.vnspacemanager.structurestyle.*;
3 import static org.mockito.Mockito.mock;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
7
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.FlowId;
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.Flow;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowKey;
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.*;
28 import java.util.List;
29 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
30 import static org.junit.Assert.*;
31 import static org.mockito.Mockito.*;
32 public class DeleteFlowTest{
33         private DataBroker dataBroker;
34     private TenantManage tenantManage;
35         private DeleteFlow deleteflow;
36         private UserId userId;
37     private     FlowId flowId;
38         private Objects objects;
39         private User  user;
40         private List<Flow> flowlist;
41         private Flow flow;
42         private FlowId notflowId;
43         private   WriteTransaction  writetransaction;
44         @org.junit.Before
45         public void setUp() throws Exception {
46                 dataBroker=mock(DataBroker.class);
47                 tenantManage=mock(TenantManage.class);
48                 deleteflow=new DeleteFlow(dataBroker,tenantManage);
49                 userId=mock(UserId.class);
50                 flowId=mock(FlowId.class);
51                 objects=mock(Objects.class);
52                 user=mock(User.class);
53                 flow=mock(Flow.class);
54                 notflowId=mock(FlowId.class);
55                 flowlist=new ArrayList<Flow>(1);
56                 flowlist.add(flow);
57                 writetransaction=mock(WriteTransaction.class);
58         }
59         @org.junit.Test
60         public void  DeleteFlowHandlingTest() throws Exception{
61          CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class);
62      ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
63          when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
64
65      //no data test
66          when(tenantManage.getUser()).thenReturn(null);
67          Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),"There are no user in the data store.");
68          //data exists and other branches
69          //branch 1
70         when(tenantManage.getUser()).thenReturn(user);
71         when(user.getObjects()).thenReturn(null);
72         Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),null);
73         //branch 2
74         when(tenantManage.getUser()).thenReturn(user);
75         when(user.getObjects()).thenReturn(objects);
76         when(user.getObjects().getFlow()).thenReturn(null);
77         Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),"There are no flow instances in the data store.");
78         //branch 3
79         when(tenantManage.getUser()).thenReturn(user);
80         when(user.getObjects()).thenReturn(objects);
81         when(user.getObjects().getFlow()).thenReturn(flowlist);
82         when(flow.getFlowId()).thenReturn(notflowId);
83         Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),"The flow instance" +flowId.toString()+"is not exist. Could not be deleted.");
84         //branch 4
85         when(tenantManage.getUser()).thenReturn(user);
86         when(user.getObjects()).thenReturn(objects);
87         when(user.getObjects().getFlow()).thenReturn(flowlist);
88         when(flow.getFlowId()).thenReturn(flowId);
89         when(dataBroker.newWriteOnlyTransaction()).thenReturn(writetransaction);
90         CheckedFuture<Void, TransactionCommitFailedException> f;
91         f=mock(CheckedFuture.class);
92         when(writetransaction.submit()).thenReturn(f);
93         Assert.assertEquals(deleteflow.DeleteFlowHandling(userId,flowId),null);
94         }
95 }