fa297734b69ae22da26bcfe9aafec611f7e52e58
[appc.git] /
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.openecomp.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.Test;\r
36 import org.junit.runner.RunWith;\r
37 import org.mockito.Mock;\r
38 import org.openecomp.appc.flow.controller.data.Transaction;\r
39 import org.openecomp.appc.flow.controller.dbervices.FlowControlDBService;\r
40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
41 import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
42 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;\r
43 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;\r
44 import org.onap.ccsdk.sli.core.dblib.DbLibService;\r
45 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;\r
46 import org.powermock.api.mockito.PowerMockito;\r
47 import org.powermock.core.classloader.annotations.PrepareForTest;\r
48 import org.powermock.modules.junit4.PowerMockRunner;\r
49 import org.powermock.reflect.Whitebox;\r
50 import org.powermock.modules.junit4.PowerMockRunner;\r
51 \r
52 @PrepareForTest({ SqlResource.class, SvcLogicResource.class })\r
53 @RunWith(PowerMockRunner.class)\r
54 public class FlowControlDBServiceTest {\r
55 \r
56 @Mock\r
57          SvcLogicResource serviceLogic;\r
58 @Mock\r
59 SqlResource sqlrs;\r
60 @Mock\r
61 QueryStatus dblibSvc ;\r
62 \r
63         private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
64 \r
65         private Transaction transaction;;\r
66 \r
67         @Before\r
68         public void setUp() throws Exception {\r
69                 serviceLogic = new SqlResource();\r
70         }\r
71         \r
72         \r
73         /*public final void testGetFlowReferenceData() throws Exception {\r
74 \r
75                 SvcLogicContext localContext = new SvcLogicContext();\r
76                 FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
77                 PowerMockito.spy(SqlResource.class);\r
78 \r
79                 Map<String, String> inParams = null;\r
80                 //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");\r
81                 Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));\r
82                 \r
83         dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);\r
84                 //Assert.assertEquals("SUCCESS", status);\r
85                 //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
86 \r
87         }*/\r
88 \r
89         @Test(expected=Exception.class)\r
90         public final void testGetFlowReferenceData() throws Exception {\r
91 \r
92                 SvcLogicContext localContext = new SvcLogicContext();\r
93                 FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();\r
94                 PowerMockito.spy(FlowControlDBService.class);\r
95                 \r
96 \r
97                 PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");\r
98         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);\r
99                 Assert.assertEquals("SUCCESS", status);\r
100                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
101 \r
102         }\r
103 \r
104         \r
105         @Test(expected=Exception.class)\r
106         public final void testGetDesignTimeFlowModel() throws Exception {\r
107                 SvcLogicContext localContext = new SvcLogicContext();\r
108                 String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;\r
109                 Assert.assertEquals("SUCCESS", status);\r
110                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
111 \r
112                 \r
113                 \r
114 \r
115         }\r
116 \r
117         @Test(expected=Exception.class)\r
118         public final void testLoadSequenceIntoDB() throws SvcLogicException {\r
119                   \r
120 \r
121                 SvcLogicContext localContext = new SvcLogicContext();\r
122                 QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;\r
123                 Assert.assertEquals("SUCCESS", status);\r
124                 Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
125                 /*SvcLogicContext ctx = new SvcLogicContext();\r
126                 \r
127                 if (serviceLogic != null && localContext != null) {\r
128                         String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS\r
129                                         + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";\r
130                         Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))\r
131                                         .thenReturn(status);\r
132                         Assert.assertEquals("SUCCESS", status);\r
133                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/\r
134 \r
135                 \r
136 \r
137         }\r
138 \r
139         @Test(expected=Exception.class)\r
140         public final void testPopulateModuleAndRPC() throws SvcLogicException {\r
141                 SvcLogicContext localContext = new SvcLogicContext();\r
142                 SvcLogicContext ctx = new SvcLogicContext();\r
143                 String vnf_type = "test";\r
144          dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;\r
145         \r
146 \r
147         }\r
148 \r
149         @Test(expected=Exception.class)\r
150         public final void testGetDependencyInfo() throws SvcLogicException {\r
151                 SvcLogicContext localContext = new SvcLogicContext();\r
152                  String status = dgGeneralDBService.getDependencyInfo(localContext);\r
153                         Assert.assertEquals("SUCCESS", status);\r
154                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
155                 \r
156         }\r
157 \r
158         @Test(expected=Exception.class)\r
159         public final void testGetCapabilitiesData() throws SvcLogicException {\r
160                 SvcLogicContext localContext = new SvcLogicContext();\r
161                 String status = dgGeneralDBService.getCapabilitiesData(localContext);           \r
162                         Assert.assertEquals("SUCCESS", status);\r
163                         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);\r
164                 \r
165         }\r
166 \r
167 }\r