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