[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / FalloutHandlerTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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.openecomp.mso.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.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
28 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
29
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import org.camunda.bpm.engine.test.Deployment;
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
37
38 /**
39  * Unit test for FalloutHandler.bpmn.
40  */
41 public class FalloutHandlerTest extends WorkflowTest {
42         private void setupMocks() {
43                 stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter"))
44                                 .willReturn(aResponse()
45                                 .withStatus(200)
46                                 .withHeader("Content-Type", "text/xml")
47                                 .withBody("<DbTag>Notified</DbTag>")));
48         }       
49         
50         private void executeFlow(String inputRequestFile) throws InterruptedException {
51                 String method = getClass().getSimpleName() + "." + new Object() {
52                 }.getClass().getEnclosingMethod().getName();
53                 System.out.println("STARTED TEST: " + method);
54         
55                 //String changeFeatureActivateRequest = FileUtil.readResourceFile("__files/SDN-ETHERNET-INTERNET/ChangeFeatureActivateV1/" + inputRequestFile);
56                 Map<String, String> variables = new HashMap<String, String>();          
57                 variables.put("FalloutHandlerRequest",inputRequestFile);
58                 
59                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "FalloutHandler", variables);
60                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
61                 System.out.println("ENDED TEST: " + method);
62         }       
63         
64         @Test           
65         @Deployment(resources = {"subprocess/FalloutHandler.bpmn"})
66         public void msoFalloutHandlerWithNotificationurl_200() throws Exception{
67                 String method = getClass().getSimpleName() + "." + new Object() {
68                 }.getClass().getEnclosingMethod().getName();
69                 System.out.println("STARTED TEST: " + method);
70                 
71                 //Setup Mocks
72                 setupMocks();
73                 //Execute Flow
74                 executeFlow(gMsoFalloutHandlerWithNotificationurl());
75                 //Verify Error
76                 String FH_ResponseCode = BPMNUtil.getVariable(processEngineRule, "FalloutHandler", "FH_ResponseCode");
77                 Assert.assertEquals("200", FH_ResponseCode);
78                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngineRule, "FalloutHandler", "FH_SuccessIndicator")); 
79         }
80         
81         public String gMsoFalloutHandlerWithNotificationurl() {
82                 //Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
83                 String xml = ""
84                                 + "<sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow=\"http://org.openecomp/mso/workflow/schema/v1\" xmlns:ns7=\"http://org.openecomp/mso/request/types/v1\">"
85                                 + "             <ns7:request-information>"
86                                 + "                     <ns7:request-id>uCPE1020_STUW105_5002</ns7:request-id>"
87                                 + "                     <ns7:request-action>Layer3ServiceActivateRequest</ns7:request-action>"
88                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
89                                 + "                     <ns7:source>OMX</ns7:source>"
90                                 + "                     <ns7:notification-url>http://localhost:28090/CCD/StatusNotification</ns7:notification-url>"
91                                 + "                     <ns7:order-number>10205000</ns7:order-number>"
92                                 + "                     <ns7:order-version>1</ns7:order-version>"
93                                 + "             </ns7:request-information>"
94                                 + "             <sdncadapterworkflow:WorkflowException>"
95                                 + "                     <sdncadapterworkflow:ErrorMessage>Some Error Message - Fallout Handler</sdncadapterworkflow:ErrorMessage>"
96                                 + "                     <sdncadapterworkflow:ErrorCode>Some Error Code - Fallout Handler</sdncadapterworkflow:ErrorCode>"
97                                 + "                     <sdncadapterworkflow:SourceSystemErrorCode>Some Source System Error Code- Fallout Handler</sdncadapterworkflow:SourceSystemErrorCode>"
98                                 + "             </sdncadapterworkflow:WorkflowException>"
99                                 + "</sdncadapterworkflow:FalloutHandlerRequest>";
100                 
101                 return xml;
102
103         }       
104         
105
106
107
108         @Test           
109         @Deployment(resources = {"subprocess/FalloutHandler.bpmn"})
110         public void msoFalloutHandlerWithNoNotificationurl() throws Exception{
111                 String method = getClass().getSimpleName() + "." + new Object() {
112                 }.getClass().getEnclosingMethod().getName();
113                 System.out.println("STARTED TEST: " + method);          
114                 //Setup Mocks
115                 setupMocks();
116                 //Execute Flow
117                 executeFlow(gMsoFalloutHandlerWithNoNotificationurl());
118                 //Verify Error
119                 String FH_ResponseCode = BPMNUtil.getVariable(processEngineRule, "FalloutHandler", "FH_ResponseCode");
120                 Assert.assertEquals("200", FH_ResponseCode);
121                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngineRule, "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.openecomp/mso/workflow/schema/v1\" xmlns:ns7=\"http://org.openecomp/mso/request/types/v1\">"
128                                 + "             <ns7:request-information>"
129                                 + "                     <ns7:request-id>uCPE1020_STUW105_5002</ns7:request-id>"
130                                 + "                     <ns7:request-action>Layer3ServiceActivateRequest</ns7:request-action>"
131                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
132                                 + "                     <ns7:source>OMX</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         @Deployment(resources = {"subprocess/FalloutHandler.bpmn"})
149         public void msoFalloutHandlerWithNotificationurlNoRequestId() throws Exception{
150                 String method = getClass().getSimpleName() + "." + new Object() {
151                 }.getClass().getEnclosingMethod().getName();
152                 System.out.println("STARTED TEST: " + method);          
153                 //Setup Mocks
154                 setupMocks();
155                 //Execute Flow
156                 executeFlow(gMsoFalloutHandlerWithNotificationurlNoRequestId());
157                 //Verify Error          
158                 String FH_ResponseCode = BPMNUtil.getVariable(processEngineRule, "FalloutHandler", "FH_ResponseCode");
159                 Assert.assertEquals("200", FH_ResponseCode);
160                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngineRule, "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.openecomp/mso/workflow/schema/v1\" xmlns:ns7=\"http://org.openecomp/mso/request/types/v1\">"
167                                 + "             <ns7:request-information>"
168                                 + "                     <ns7:request-id></ns7:request-id>"
169                                 + "                     <ns7:request-action>Layer3ServiceActivateRequest</ns7:request-action>"
170                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
171                                 + "                     <ns7:source>OMX</ns7:source>"
172                                 + "                     <ns7:notification-url>www.att.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         @Deployment(resources = {"subprocess/FalloutHandler.bpmn"})
188         public void msoFalloutHandlerWithNoNotificationurlNoRequestId() throws Exception{
189                 String method = getClass().getSimpleName() + "." + new Object() {
190                 }.getClass().getEnclosingMethod().getName();
191                 System.out.println("STARTED TEST: " + method);          
192                 //Setup Mocks
193                 setupMocks();
194                 //Execute Flow
195                 executeFlow(gMsoFalloutHandlerWithNoNotificationurlNoRequestId());
196                 //Verify Error
197                 String FH_ResponseCode = BPMNUtil.getVariable(processEngineRule, "FalloutHandler", "FH_ResponseCode");
198                 Assert.assertEquals("200", FH_ResponseCode);
199                 Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngineRule, "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.openecomp/mso/workflow/schema/v1\" xmlns:ns7=\"http://org.openecomp/mso/request/types/v1\">"
206                                 + "             <ns7:request-information>"
207                                 + "                     <ns7:request-id></ns7:request-id>"
208                                 + "                     <ns7:request-action>Layer3ServiceActivateRequest</ns7:request-action>"
209                                 + "                     <ns7:request-sub-action>CANCEL</ns7:request-sub-action>"
210                                 + "                     <ns7:source>OMX</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