/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.so.bpmn.common;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static org.onap.so.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.Assert;
import org.junit.Test;
import org.onap.so.BaseIntegrationTest;
import org.onap.so.logger.MsoLogger;
/**
* Unit test for FalloutHandler.bpmn.
*/
public class FalloutHandlerIT extends BaseIntegrationTest {
MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,FalloutHandlerIT.class);
private void setupMocks() {
stubFor(post(urlEqualTo("/dbadapters/AttRequestsDbAdapter"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody("Notified")));
stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody("Notified")));
}
private String executeFlow(String inputRequestFile) throws InterruptedException {
Map variables = new HashMap<>();
variables.put("FalloutHandlerRequest",inputRequestFile); variables.put("mso-request-id", UUID.randomUUID().toString());
String processId = invokeSubProcess( "FalloutHandler", variables);
waitForWorkflowToFinish(processEngine,processId);
logEnd();
return processId;
}
@Test
public void msoFalloutHandlerWithNotificationurl_200() throws Exception{
//Setup Mocks
setupMocks();
//Execute Flow
String processId = executeFlow(gMsoFalloutHandlerWithNotificationurl());
//Verify Error
String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode",processId);
Assert.assertEquals("200", FH_ResponseCode);
Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator",processId));
}
public String gMsoFalloutHandlerWithNotificationurl() {
//Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
String xml = ""
+ ""
+ " "
+ " 1020_STUW105_5002"
+ " requestAction"
+ " CANCEL"
+ " source"
+ " http://localhost:28090/CCD/StatusNotification"
+ " 10205000"
+ " 1"
+ " "
+ " "
+ " Some Error Message - Fallout Handler"
+ " Some Error Code - Fallout Handler"
+ " Some Source System Error Code- Fallout Handler"
+ " "
+ "";
return xml;
}
@Test
public void msoFalloutHandlerWithNoNotificationurl() throws Exception{
//Setup Mocks
setupMocks();
//Execute Flow
executeFlow(gMsoFalloutHandlerWithNoNotificationurl());
//Verify Error
String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
Assert.assertEquals("200", FH_ResponseCode);
Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator"));
}
public String gMsoFalloutHandlerWithNoNotificationurl() {
//Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
String xml = ""
+ ""
+ " "
+ " 1020_STUW105_5002"
+ " requestAction"
+ " CANCEL"
+ " source"
+ " "
+ " 10205000"
+ " 1"
+ " "
+ " "
+ " Some Error Message - Fallout Handler"
+ " Some Error Code - Fallout Handler"
+ " Some Source System Error Code- Fallout Handler"
+ " "
+ "";
return xml;
}
@Test
public void msoFalloutHandlerWithNotificationurlNoRequestId() throws Exception{
String method = getClass().getSimpleName() + "." + new Object() {
}.getClass().getEnclosingMethod().getName();
logger.debug("STARTED TEST: " + method);
//Setup Mocks
setupMocks();
//Execute Flow
executeFlow(gMsoFalloutHandlerWithNotificationurlNoRequestId());
//Verify Error
String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
Assert.assertEquals("200", FH_ResponseCode);
Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator"));
}
public String gMsoFalloutHandlerWithNotificationurlNoRequestId() {
//Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
String xml = ""
+ ""
+ " "
+ " "
+ " requestAction"
+ " CANCEL"
+ " source"
+ " www.test.com"
+ " 10205000"
+ " 1"
+ " "
+ " "
+ " Some Error Message - Fallout Handler"
+ " Some Error Code - Fallout Handler"
+ " Some Source System Error Code- Fallout Handler"
+ " "
+ "";
return xml;
}
@Test
public void msoFalloutHandlerWithNoNotificationurlNoRequestId() throws Exception{
String method = getClass().getSimpleName() + "." + new Object() {
}.getClass().getEnclosingMethod().getName();
logger.debug("STARTED TEST: " + method);
//Setup Mocks
setupMocks();
//Execute Flow
executeFlow(gMsoFalloutHandlerWithNoNotificationurlNoRequestId());
//Verify Error
String FH_ResponseCode = BPMNUtil.getVariable(processEngine, "FalloutHandler", "FH_ResponseCode");
Assert.assertEquals("200", FH_ResponseCode);
Assert.assertTrue((boolean) BPMNUtil.getRawVariable(processEngine, "FalloutHandler", "FH_SuccessIndicator"));
}
public String gMsoFalloutHandlerWithNoNotificationurlNoRequestId() {
//Generated the below XML from ActiveVOS moduler ... Using the generate sample XML feature in ActiveVOS
String xml = ""
+ ""
+ " "
+ " "
+ " requestAction"
+ " CANCEL"
+ " source"
+ " "
+ " 10205000"
+ " 1"
+ " "
+ " "
+ " Some Error Message - Fallout Handler"
+ " Some Error Code - Fallout Handler"
+ " Some Source System Error Code- Fallout Handler"
+ " "
+ "";
return xml;
}
}