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