Replaced all tabs with spaces in java and pom.xml
[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 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.UUID;
32 import org.junit.Assert;
33 import org.junit.Test;
34 import org.onap.so.BaseIntegrationTest;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * Unit test for FalloutHandler.bpmn.
40  */
41
42 public class FalloutHandlerIT extends BaseIntegrationTest {
43
44     Logger logger = LoggerFactory.getLogger(FalloutHandlerIT.class);
45
46
47     private void setupMocks() {
48         wireMockServer.stubFor(post(urlEqualTo("/dbadapters/AttRequestsDbAdapter")).willReturn(aResponse()
49                 .withStatus(200).withHeader("Content-Type", "text/xml").withBody("<DbTag>Notified</DbTag>")));
50         wireMockServer.stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter")).willReturn(aResponse().withStatus(200)
51                 .withHeader("Content-Type", "text/xml").withBody("<DbTag>Notified</DbTag>")));
52     }
53
54     private String executeFlow(String inputRequestFile) throws InterruptedException {
55
56         Map<String, Object> variables = new HashMap<>();
57         variables.put("FalloutHandlerRequest", inputRequestFile);
58         variables.put("mso-request-id", UUID.randomUUID().toString());
59         String processId = invokeSubProcess("FalloutHandler", variables);
60         waitForWorkflowToFinish(processEngine, processId);
61         logEnd();
62         return processId;
63     }
64
65     @Test
66     public void msoFalloutHandlerWithNotificationurl_200() throws Exception {
67         // Setup Mocks
68         setupMocks();
69         // Execute Flow
70         String processId = executeFlow(gMsoFalloutHandlerWithNotificationurl());
71         // Verify Error
72         String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode", processId);
73         Assert.assertEquals("200", FH_ResponseCode);
74         Assert.assertTrue(
75                 (boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator", processId));
76     }
77
78     public String gMsoFalloutHandlerWithNotificationurl() {
79         // Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
80         String xml = ""
81                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
82                 + "             <ns7:request-information>" + "                  <ns7:request-id>1020_STUW105_5002</ns7:request-id>"
83                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
84                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
85                 + "                     <ns7:source>source</ns7:source>"
86                 + "                     <ns7:notification-url>http://localhost:28090/CCD/StatusNotification</ns7:notification-url>"
87                 + "                     <ns7:order-number>10205000</ns7:order-number>"
88                 + "                     <ns7:order-version>1</ns7:order-version>" + "           </ns7:request-information>"
89                 + "             <sdncadapterworkflow:WorkflowException>"
90                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
91                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
92                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
93                 + "             </sdncadapterworkflow:WorkflowException>" + "</sdncadapterworkflow:FalloutHandlerRequest>";
94
95         return xml;
96
97     }
98
99
100
101     @Test
102     public void msoFalloutHandlerWithNoNotificationurl() throws Exception {
103
104         // Setup Mocks
105         setupMocks();
106         // Execute Flow
107         executeFlow(gMsoFalloutHandlerWithNoNotificationurl());
108         // Verify Error
109         String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
110         Assert.assertEquals("200", FH_ResponseCode);
111         Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator"));
112     }
113
114     public String gMsoFalloutHandlerWithNoNotificationurl() {
115         // Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
116         String xml = ""
117                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
118                 + "             <ns7:request-information>" + "                  <ns7:request-id>1020_STUW105_5002</ns7:request-id>"
119                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
120                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
121                 + "                     <ns7:source>source</ns7:source>" + "                    <ns7:notification-url></ns7:notification-url>"
122                 + "                     <ns7:order-number>10205000</ns7:order-number>"
123                 + "                     <ns7:order-version>1</ns7:order-version>" + "           </ns7:request-information>"
124                 + "             <sdncadapterworkflow:WorkflowException>"
125                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
126                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
127                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
128                 + "             </sdncadapterworkflow:WorkflowException>" + "</sdncadapterworkflow:FalloutHandlerRequest>";
129
130         return xml;
131     }
132
133     @Test
134
135     public void msoFalloutHandlerWithNotificationurlNoRequestId() throws Exception {
136         String method = getClass().getSimpleName() + "." + new Object() {}.getClass().getEnclosingMethod().getName();
137         logger.debug("STARTED TEST: {}", method);
138         // Setup Mocks
139         setupMocks();
140         // Execute Flow
141         executeFlow(gMsoFalloutHandlerWithNotificationurlNoRequestId());
142         // Verify Error
143         String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
144         Assert.assertEquals("200", FH_ResponseCode);
145         Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator"));
146     }
147
148     public String gMsoFalloutHandlerWithNotificationurlNoRequestId() {
149         // Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
150         String xml = ""
151                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
152                 + "             <ns7:request-information>" + "                  <ns7:request-id></ns7:request-id>"
153                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
154                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
155                 + "                     <ns7:source>source</ns7:source>"
156                 + "                     <ns7:notification-url>www.test.com</ns7:notification-url>"
157                 + "                     <ns7:order-number>10205000</ns7:order-number>"
158                 + "                     <ns7:order-version>1</ns7:order-version>" + "           </ns7:request-information>"
159                 + "             <sdncadapterworkflow:WorkflowException>"
160                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
161                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
162                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
163                 + "             </sdncadapterworkflow:WorkflowException>" + "</sdncadapterworkflow:FalloutHandlerRequest>";
164
165         return xml;
166     }
167
168     @Test
169
170     public void msoFalloutHandlerWithNoNotificationurlNoRequestId() throws Exception {
171         String method = getClass().getSimpleName() + "." + new Object() {}.getClass().getEnclosingMethod().getName();
172         logger.debug("STARTED TEST: {}", method);
173         // Setup Mocks
174         setupMocks();
175         // Execute Flow
176         executeFlow(gMsoFalloutHandlerWithNoNotificationurlNoRequestId());
177         // Verify Error
178         String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
179         Assert.assertEquals("200", FH_ResponseCode);
180         Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator"));
181     }
182
183     public String gMsoFalloutHandlerWithNoNotificationurlNoRequestId() {
184         // Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
185         String xml = ""
186                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.onap/so/workflow/schema/v1\" xmlns:ns7=\"http://org.onap/so/request/types/v1\">"
187                 + "             <ns7:request-information>" + "                  <ns7:request-id></ns7:request-id>"
188                 + "                     <ns7:request-action>requestAction</ns7:request-action>"
189                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
190                 + "                     <ns7:source>source</ns7:source>" + "                    <ns7:notification-url></ns7:notification-url>"
191                 + "                     <ns7:order-number>10205000</ns7:order-number>"
192                 + "                     <ns7:order-version>1</ns7:order-version>" + "           </ns7:request-information>"
193                 + "             <sdncadapterworkflow:WorkflowException>"
194                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
195                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
196                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
197                 + "             </sdncadapterworkflow:WorkflowException>" + "</sdncadapterworkflow:FalloutHandlerRequest>";
198
199         return xml;
200     }
201
202 }
203