Containerization feature of SO
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / FalloutHandlerIT.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
4  * ================================================================================ 
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
6  * ================================================================================ 
7  * Licensed under the Apache License, Version 2.0 (the "License"); 
8  * you may not use this file except in compliance with the License. 
9  * You may obtain a copy of the License at 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
13  * Unless required by applicable law or agreed to in writing, software 
14  * distributed under the License is distributed on an "AS IS" BASIS, 
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
16  * See the License for the specific language governing permissions and 
17  * limitations under the License. 
18  * ============LICENSE_END========================================================= 
19  */ 
20
21 package org.onap.so.bpmn.common;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27 import static org.onap.so.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
28
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.UUID;
32
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.onap.so.BaseIntegrationTest;
36 import org.onap.so.logger.MsoLogger;
37
38 /**
39  * Unit test for FalloutHandler.bpmn.
40  */
41
42 public class FalloutHandlerIT extends BaseIntegrationTest {
43         
44         MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,FalloutHandlerIT.class);
45         
46         
47         private void setupMocks() {
48                 stubFor(post(urlEqualTo("/dbadapters/AttRequestsDbAdapter"))
49                                 .willReturn(aResponse()
50                                 .withStatus(200)
51                                 .withHeader("Content-Type", "text/xml")
52                                 .withBody("<DbTag>Notified</DbTag>")));
53                 stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter"))
54                                 .willReturn(aResponse()
55                                 .withStatus(200)
56                                 .withHeader("Content-Type", "text/xml")
57                                 .withBody("<DbTag>Notified</DbTag>")));
58         }       
59         
60         private String executeFlow(String inputRequestFile) throws InterruptedException {       
61                 
62                 Map<String, Object> variables = new HashMap<>();
63                 variables.put("FalloutHandlerRequest",inputRequestFile);                variables.put("mso-request-id", UUID.randomUUID().toString());
64                 String processId = invokeSubProcess( "FalloutHandler", variables);
65                 waitForWorkflowToFinish(processEngine,processId);
66                 logEnd();
67                 return processId;
68         }       
69         
70         @Test           
71         public void msoFalloutHandlerWithNotificationurl_200() throws Exception{                
72                 //Setup Mocks
73                 setupMocks();
74                 //Execute Flow
75                 String processId = executeFlow(gMsoFalloutHandlerWithNotificationurl());
76                 //Verify Error
77                 String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode",processId);
78                 Assert.assertEquals("200", FH_ResponseCode);
79                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator",processId)); 
80         }
81         
82         public String gMsoFalloutHandlerWithNotificationurl() {
83                 //Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
84                 String xml = ""
85                                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
86                                 + "             <ns7:request-information>"
87                                 + "                     <ns7:request-id>1020_STUW105_5002</ns7:request-id>"
88                                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
89                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
90                                 + "                     <ns7:source>source</ns7:source>"
91                                 + "                     <ns7:notification-url>http://localhost:28090/CCD/StatusNotification</ns7:notification-url>"
92                                 + "                     <ns7:order-number>10205000</ns7:order-number>"
93                                 + "                     <ns7:order-version>1</ns7:order-version>"
94                                 + "             </ns7:request-information>"
95                                 + "             <sdncadapterworkflow:WorkflowException>"
96                                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
97                                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
98                                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
99                                 + "             </sdncadapterworkflow:WorkflowException>"
100                                 + "</sdncadapterworkflow:FalloutHandlerRequest>";
101                 
102                 return xml;
103
104         }       
105         
106
107
108
109         @Test           
110         public void msoFalloutHandlerWithNoNotificationurl() throws Exception{
111         
112                 //Setup Mocks
113                 setupMocks();
114                 //Execute Flow
115                 executeFlow(gMsoFalloutHandlerWithNoNotificationurl());
116                 //Verify Error
117                 String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
118                 Assert.assertEquals("200", FH_ResponseCode);
119                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator")); 
120         }
121         
122         public String gMsoFalloutHandlerWithNoNotificationurl() {
123                 //Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
124                 String xml = ""
125                                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
126                                 + "             <ns7:request-information>"
127                                 + "                     <ns7:request-id>1020_STUW105_5002</ns7:request-id>"
128                                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
129                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
130                                 + "                     <ns7:source>source</ns7:source>"
131                                 + "                     <ns7:notification-url></ns7:notification-url>"
132                                 + "                     <ns7:order-number>10205000</ns7:order-number>"
133                                 + "                     <ns7:order-version>1</ns7:order-version>"
134                                 + "             </ns7:request-information>"
135                                 + "             <sdncadapterworkflow:WorkflowException>"
136                                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
137                                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
138                                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
139                                 + "             </sdncadapterworkflow:WorkflowException>"
140                                 + "</sdncadapterworkflow:FalloutHandlerRequest>";
141                 
142                 return xml;
143         }       
144         
145         @Test           
146         
147         public void msoFalloutHandlerWithNotificationurlNoRequestId() throws Exception{
148                 String method = getClass().getSimpleName() + "." + new Object() {
149                 }.getClass().getEnclosingMethod().getName();
150                 logger.debug("STARTED TEST: " + method);                
151                 //Setup Mocks
152                 setupMocks();
153                 //Execute Flow
154                 executeFlow(gMsoFalloutHandlerWithNotificationurlNoRequestId());
155                 //Verify Error          
156                 String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
157                 Assert.assertEquals("200", FH_ResponseCode);
158                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator")); 
159         }
160
161         public String gMsoFalloutHandlerWithNotificationurlNoRequestId() {
162                 //Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
163                 String xml = ""
164                                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
165                                 + "             <ns7:request-information>"
166                                 + "                     <ns7:request-id></ns7:request-id>"
167                                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
168                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
169                                 + "                     <ns7:source>source</ns7:source>"
170                                 + "                     <ns7:notification-url>www.test.com</ns7:notification-url>"
171                                 + "                     <ns7:order-number>10205000</ns7:order-number>"
172                                 + "                     <ns7:order-version>1</ns7:order-version>"
173                                 + "             </ns7:request-information>"
174                                 + "             <sdncadapterworkflow:WorkflowException>"
175                                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
176                                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
177                                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
178                                 + "             </sdncadapterworkflow:WorkflowException>"
179                                 + "</sdncadapterworkflow:FalloutHandlerRequest>";
180                 
181                 return xml;
182         }               
183         
184         @Test           
185         
186         public void msoFalloutHandlerWithNoNotificationurlNoRequestId() throws Exception{
187                 String method = getClass().getSimpleName() + "." + new Object() {
188                 }.getClass().getEnclosingMethod().getName();
189                 logger.debug("STARTED TEST: " + method);                
190                 //Setup Mocks
191                 setupMocks();
192                 //Execute Flow
193                 executeFlow(gMsoFalloutHandlerWithNoNotificationurlNoRequestId());
194                 //Verify Error
195                 String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
196                 Assert.assertEquals("200", FH_ResponseCode);
197                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator")); 
198         }       
199         
200         public String gMsoFalloutHandlerWithNoNotificationurlNoRequestId() {
201                 //Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
202                 String xml = ""
203                                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
204                                 + "             <ns7:request-information>"
205                                 + "                     <ns7:request-id></ns7:request-id>"
206                                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
207                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
208                                 + "                     <ns7:source>source</ns7:source>"
209                                 + "                     <ns7:notification-url></ns7:notification-url>"
210                                 + "                     <ns7:order-number>10205000</ns7:order-number>"
211                                 + "                     <ns7:order-version>1</ns7:order-version>"
212                                 + "             </ns7:request-information>"
213                                 + "             <sdncadapterworkflow:WorkflowException>"
214                                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
215                                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
216                                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
217                                 + "             </sdncadapterworkflow:WorkflowException>"
218                                 + "</sdncadapterworkflow:FalloutHandlerRequest>";
219                 
220                 return xml;
221         }       
222         
223 }
224