First part of onap rename
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / executor / node / FlowControlDBServiceTest.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP : APPC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Copyright (C) 2017 Amdocs\r
8  * =============================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  *\r
13  *      http://www.apache.org/licenses/LICENSE-2.0\r
14  *\r
15  * Unless required by applicable law or agreed to in writing, software\r
16  * distributed under the License is distributed on an "AS IS" BASIS,\r
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18  * See the License for the specific language governing permissions and\r
19  * limitations under the License.\r
20  *\r
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * ============LICENSE_END=========================================================\r
23  */\r
24 \r
25 package org.onap.appc.flow.executor.node;\r
26 \r
27 import static org.mockito.Matchers.any;\r
28 import static org.mockito.Matchers.anyBoolean;\r
29 import static org.mockito.Matchers.anyString;\r
30 \r
31 import java.util.Map;\r
32 \r
33 import org.junit.Assert;\r
34 import org.junit.Before;\r
35 import org.junit.Ignore;\r
36 import org.junit.Test;\r
37 import org.junit.runner.RunWith;\r
38 import org.mockito.Mock;\r
39 import org.onap.appc.flow.controller.data.Transaction;\r
40 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;\r
41 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
42 import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
43 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;\r
44 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;\r
45 import org.onap.ccsdk.sli.core.dblib.DbLibService;\r
46 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;\r
47 import org.powermock.api.mockito.PowerMockito;\r
48 import org.powermock.core.classloader.annotations.PrepareForTest;\r
49 import org.powermock.modules.junit4.PowerMockRunner;\r
50 import org.powermock.reflect.Whitebox;\r
51 import org.powermock.modules.junit4.PowerMockRunner;\r
52 \r
53 @PrepareForTest({ SqlResource.class, SvcLogicResource.class })\r
54 @RunWith(PowerMockRunner.class)\r
55 public class FlowControlDBServiceTest {\r
56 \r
57 @Mock\r
58          SvcLogicResource serviceLogic;\r
59 @Mock\r
60 SqlResource sqlrs;\r
61 @Mock\r
62 QueryStatus dblibSvc ;\r
63 \r
64         private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
65 \r
66         private Transaction transaction;;\r
67 \r
68         @Before\r
69         public void setUp() throws Exception {\r
70                 serviceLogic = new SqlResource();\r
71         }\r
72         \r
73         \r
74         /*public final void testGetFlowReferenceData() throws Exception {\r
75 \r
76                 SvcLogicContext localContext = new SvcLogicContext();\r
77                 FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
78                 PowerMockito.spy(SqlResource.class);\r
79 \r
80                 Map<String, String> inParams = null;\r
81                 //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");\r
82                 Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));\r
83                 \r
84         dgGeneralDBService.getFlowReferenceData(localContext, inParams, 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         @Test(expected=Exception.class)\r
91         public final void testGetFlowReferenceData() throws Exception {\r
92 \r
93                 SvcLogicContext localContext = new SvcLogicContext();\r
94                 FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
95                 PowerMockito.spy(FlowControlDBService.class);\r
96                 \r
97 \r
98                 PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");\r
99         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);\r
100                 Assert.assertEquals("SUCCESS", status);\r
101                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
102 \r
103         }\r
104 \r
105         \r
106         @Ignore("Test is taking 60 seconds")\r
107         @Test(expected=Exception.class)\r
108         public final void testGetDesignTimeFlowModel() throws Exception {\r
109                 SvcLogicContext localContext = new SvcLogicContext();\r
110                 String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;\r
111                 Assert.assertEquals("SUCCESS", status);\r
112                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
113 \r
114                 \r
115                 \r
116 \r
117         }\r
118 \r
119         @Ignore("Test is taking 60 seconds")\r
120         @Test(expected=Exception.class)\r
121         public final void testLoadSequenceIntoDB() throws SvcLogicException {\r
122                   \r
123 \r
124                 SvcLogicContext localContext = new SvcLogicContext();\r
125                 QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;\r
126                 Assert.assertEquals("SUCCESS", status);\r
127                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
128                 /*SvcLogicContext ctx = new SvcLogicContext();\r
129                 \r
130                 if (serviceLogic != null && localContext != null) {\r
131                         String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS\r
132                                         + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";\r
133                         Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))\r
134                                         .thenReturn(status);\r
135                         Assert.assertEquals("SUCCESS", status);\r
136                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/\r
137 \r
138                 \r
139 \r
140         }\r
141 \r
142         @Test(expected=Exception.class)\r
143         public final void testPopulateModuleAndRPC() throws SvcLogicException {\r
144                 SvcLogicContext localContext = new SvcLogicContext();\r
145                 SvcLogicContext ctx = new SvcLogicContext();\r
146                 String vnf_type = "test";\r
147          dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;\r
148         \r
149 \r
150         }\r
151 \r
152         @Ignore("Test is taking 60 seconds")\r
153         @Test(expected=Exception.class)\r
154         public final void testGetDependencyInfo() throws SvcLogicException {\r
155                 SvcLogicContext localContext = new SvcLogicContext();\r
156                  String status = dgGeneralDBService.getDependencyInfo(localContext);\r
157                         Assert.assertEquals("SUCCESS", status);\r
158                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
159                 \r
160         }\r
161 \r
162         @Ignore("Test is taking 60 seconds")\r
163         @Test(expected=Exception.class)\r
164         public final void testGetCapabilitiesData() throws SvcLogicException {\r
165                 SvcLogicContext localContext = new SvcLogicContext();\r
166                 String status = dgGeneralDBService.getCapabilitiesData(localContext);           \r
167                         Assert.assertEquals("SUCCESS", status);\r
168                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
169                 \r
170         }\r
171 \r
172 }\r