ad9f97f951385a7a10522b97e1df3d20b1f88143
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / subprocess / SDNCHandlerTest.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.infrastructure.bpmn.subprocess;
22
23 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat;
24 import static org.mockito.Mockito.doReturn;
25
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import org.camunda.bpm.engine.runtime.ProcessInstance;
33 import org.junit.Test;
34 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
35 import org.onap.so.bpmn.BaseBPMNTest;
36 import org.onap.so.client.exception.BadResponseException;
37 import org.onap.so.client.exception.MapperException;
38 import org.onap.so.client.sdnc.beans.SDNCRequest;
39 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
40
41 import com.fasterxml.jackson.core.JsonParseException;
42 import com.fasterxml.jackson.databind.JsonMappingException;
43 import com.fasterxml.jackson.databind.ObjectMapper;
44
45 public class SDNCHandlerTest extends BaseBPMNTest{
46         @Test
47         public void sunnyDay_SDNCHandler_Sync_Final_Test() throws InterruptedException, MapperException, BadResponseException, IOException {
48                 final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/SDNCClientPut200Response.json")));      
49                 doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION);  
50                 Map<String, Object> startVariables = new HashMap<>();
51                 startVariables.put("SDNCRequest", createSDNCRequest());
52                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("SDNCHandler", startVariables);
53                 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("SDNC_Start","SNDC_SetupCallback","Call_SDNC","isAsync_Gateway","SDNC_End").isEnded();
54         }
55
56
57         public SDNCRequest createSDNCRequest(){
58                 SDNCRequest request = new SDNCRequest();
59                 request.setCorrelationName("correlationName");
60                 request.setCorrelationValue("correlationValue");                
61                 request.setTopology(SDNCTopology.CONFIGURATION);
62                 ObjectMapper mapper = new ObjectMapper();
63                 try {
64                         GenericResourceApiServiceOperationInformation sdncReq = 
65                                         mapper.readValue(Files.readAllBytes(Paths.get("src/test/resources/SDNC_Client_Request.json")), GenericResourceApiServiceOperationInformation.class);
66                         request.setSDNCPayload(sdncReq);
67                 } catch (JsonParseException e) {                        
68
69                 } catch (JsonMappingException e) {
70
71                 } catch (IOException e) {
72
73                 }
74
75                 return request;
76         }
77 }