Added New Junit Cases for APPC Design Services
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / openecomp / appc / flow / executor / node / FlowControlDBServiceTest.java
1 package org.openecomp.appc.flow.executor.node;\r
2 \r
3 import static org.mockito.Matchers.any;\r
4 import static org.mockito.Matchers.anyBoolean;\r
5 import static org.mockito.Matchers.anyString;\r
6 \r
7 import java.util.Map;\r
8 \r
9 import org.junit.Assert;\r
10 import org.junit.Before;\r
11 import org.junit.Test;\r
12 import org.junit.runner.RunWith;\r
13 import org.mockito.Mock;\r
14 import org.openecomp.appc.flow.controller.data.Transaction;\r
15 import org.openecomp.appc.flow.controller.dbervices.FlowControlDBService;\r
16 import org.openecomp.sdnc.sli.SvcLogicContext;\r
17 import org.openecomp.sdnc.sli.SvcLogicException;\r
18 import org.openecomp.sdnc.sli.SvcLogicResource;\r
19 import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;\r
20 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;\r
21 import org.openecomp.sdnc.sli.resource.sql.SqlResource;\r
22 import org.powermock.api.mockito.PowerMockito;\r
23 import org.powermock.core.classloader.annotations.PrepareForTest;\r
24 import org.powermock.modules.junit4.PowerMockRunner;\r
25 import org.powermock.reflect.Whitebox;\r
26 import org.powermock.modules.junit4.PowerMockRunner;\r
27 \r
28 @PrepareForTest({ SqlResource.class, SvcLogicResource.class })\r
29 @RunWith(PowerMockRunner.class)\r
30 public class FlowControlDBServiceTest {\r
31 \r
32 @Mock\r
33          SvcLogicResource serviceLogic;\r
34 @Mock\r
35 SqlResource sqlrs;\r
36 @Mock\r
37 QueryStatus dblibSvc ;\r
38 \r
39         private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
40 \r
41         private Transaction transaction;;\r
42 \r
43         @Before\r
44         public void setUp() throws Exception {\r
45                 serviceLogic = new SqlResource();\r
46         }\r
47         \r
48         \r
49         /*public final void testGetFlowReferenceData() throws Exception {\r
50 \r
51                 SvcLogicContext localContext = new SvcLogicContext();\r
52                 FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
53                 PowerMockito.spy(SqlResource.class);\r
54 \r
55                 Map<String, String> inParams = null;\r
56                 //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");\r
57                 Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));\r
58                 \r
59         dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);\r
60                 //Assert.assertEquals("SUCCESS", status);\r
61                 //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
62 \r
63         }*/\r
64 \r
65         @Test(expected=Exception.class)\r
66         public final void testGetFlowReferenceData() throws Exception {\r
67 \r
68                 SvcLogicContext localContext = new SvcLogicContext();\r
69                 FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
70                 PowerMockito.spy(FlowControlDBService.class);\r
71                 \r
72 \r
73                 PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");\r
74         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);\r
75                 Assert.assertEquals("SUCCESS", status);\r
76                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
77 \r
78         }\r
79 \r
80         \r
81         @Test(expected=Exception.class)\r
82         public final void testGetDesignTimeFlowModel() throws Exception {\r
83                 SvcLogicContext localContext = new SvcLogicContext();\r
84                 String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;\r
85                 Assert.assertEquals("SUCCESS", status);\r
86                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
87 \r
88                 \r
89                 \r
90 \r
91         }\r
92 \r
93         @Test(expected=Exception.class)\r
94         public final void testLoadSequenceIntoDB() throws SvcLogicException {\r
95                   \r
96 \r
97                 SvcLogicContext localContext = new SvcLogicContext();\r
98                 QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;\r
99                 Assert.assertEquals("SUCCESS", status);\r
100                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
101                 /*SvcLogicContext ctx = new SvcLogicContext();\r
102                 \r
103                 if (serviceLogic != null && localContext != null) {\r
104                         String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS\r
105                                         + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";\r
106                         Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))\r
107                                         .thenReturn(status);\r
108                         Assert.assertEquals("SUCCESS", status);\r
109                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/\r
110 \r
111                 \r
112 \r
113         }\r
114 \r
115         @Test(expected=Exception.class)\r
116         public final void testPopulateModuleAndRPC() throws SvcLogicException {\r
117                 SvcLogicContext localContext = new SvcLogicContext();\r
118                 SvcLogicContext ctx = new SvcLogicContext();\r
119                 String vnf_type = "test";\r
120          dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;\r
121         \r
122 \r
123         }\r
124 \r
125         @Test(expected=Exception.class)\r
126         public final void testGetDependencyInfo() throws SvcLogicException {\r
127                 SvcLogicContext localContext = new SvcLogicContext();\r
128                  String status = dgGeneralDBService.getDependencyInfo(localContext);\r
129                         Assert.assertEquals("SUCCESS", status);\r
130                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
131                 \r
132         }\r
133 \r
134         @Test(expected=Exception.class)\r
135         public final void testGetCapabilitiesData() throws SvcLogicException {\r
136                 SvcLogicContext localContext = new SvcLogicContext();\r
137                 String status = dgGeneralDBService.getCapabilitiesData(localContext);           \r
138                         Assert.assertEquals("SUCCESS", status);\r
139                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
140                 \r
141         }\r
142 \r
143 }\r