2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
29 import java.io.IOException;
30 import java.nio.file.Files;
31 import java.nio.file.Paths;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
36 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
37 import org.junit.Before;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.rules.ExpectedException;
41 import org.junit.runner.RunWith;
42 import org.mockito.ArgumentCaptor;
43 import org.mockito.InjectMocks;
44 import org.mockito.Mock;
45 import org.mockito.Spy;
46 import org.mockito.runners.MockitoJUnitRunner;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
48 import org.onap.so.client.exception.BadResponseException;
49 import org.onap.so.client.exception.ExceptionBuilder;
50 import org.onap.so.client.exception.MapperException;
51 import org.onap.so.client.sdnc.SDNCClient;
52 import org.onap.so.client.sdnc.beans.SDNCRequest;
53 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
55 import com.fasterxml.jackson.core.JsonParseException;
56 import com.fasterxml.jackson.databind.JsonMappingException;
57 import com.fasterxml.jackson.databind.ObjectMapper;
59 @RunWith(MockitoJUnitRunner.class)
60 public class SDNCRequestTasksTest extends SDNCRequestTasks{
63 public ExpectedException expectedException = ExpectedException.none();
66 SDNCRequestTasks sndcRequestTasks = new SDNCRequestTasks();
69 SDNCClient sdncClient;
72 private ExceptionBuilder exceptionBuilder;
74 protected DelegateExecution delegateExecution;
79 delegateExecution = new DelegateExecutionFake();
80 delegateExecution.setVariable("SDNCRequest", createSDNCRequest());
84 public void createCorrelationVariables_Test(){
85 sndcRequestTasks.createCorrelationVariables(delegateExecution);
86 assertEquals("correlationValue",delegateExecution.getVariable("correlationName_CORRELATOR"));
90 public void callSDNC_Final_Test() throws MapperException, BadResponseException, IOException{
91 final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientPut200Response.json")));
92 doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION);
93 sndcRequestTasks.callSDNC(delegateExecution);
94 assertEquals(true,delegateExecution.getVariable("isSDNCCompleted"));
98 public void callSDNC_Not_Final_Test() throws MapperException, BadResponseException, IOException{
99 final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientPut200ResponseNotFinal.json")));
100 doReturn(sdncResponse).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION);
101 sndcRequestTasks.callSDNC(delegateExecution);
102 assertEquals(false,delegateExecution.getVariable("isSDNCCompleted"));
106 public void callSDNC_Error_Test() throws MapperException, BadResponseException{
107 doThrow(MapperException.class).when(sdncClient).post(createSDNCRequest().getSDNCPayload(),SDNCTopology.CONFIGURATION);
108 doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution);
109 expectedException.expect(BpmnError.class);
110 sndcRequestTasks.callSDNC(delegateExecution);
114 public void convertIndicatorToBoolean_True_Test() throws MapperException, BadResponseException{
115 boolean testValue = sndcRequestTasks.convertIndicatorToBoolean("Y");
116 assertEquals(true,testValue);
120 public void convertIndicatorToBoolean_False_Test() throws MapperException, BadResponseException{
121 boolean testValue = sndcRequestTasks.convertIndicatorToBoolean("N");
122 assertEquals(false,testValue);
126 public void HandleTimeout_Test() throws MapperException, BadResponseException{
127 doReturn("processKey").when(exceptionBuilder).getProcessKey(delegateExecution);
128 expectedException.expect(BpmnError.class);
129 sndcRequestTasks.handleTimeOutException(delegateExecution);
133 public void processCallBack_Final_Test() throws MapperException, BadResponseException, IOException{
134 final String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_ASYNC_Request.json")));
135 delegateExecution.setVariable("correlationName_MESSAGE", sdncResponse);
136 sndcRequestTasks.processCallback(delegateExecution);
137 assertEquals(true,delegateExecution.getVariable(IS_CALLBACK_COMPLETED));
140 public SDNCRequest createSDNCRequest(){
141 SDNCRequest request = new SDNCRequest();
142 request.setCorrelationName("correlationName");
143 request.setCorrelationValue("correlationValue");
144 request.setTopology(SDNCTopology.CONFIGURATION);
145 ObjectMapper mapper = new ObjectMapper();
147 GenericResourceApiServiceOperationInformation sdncReq =
148 mapper.readValue(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNC_Client_Request.json")), GenericResourceApiServiceOperationInformation.class);
149 request.setSDNCPayload(sdncReq);
150 } catch (JsonParseException e) {
152 } catch (JsonMappingException e) {
154 } catch (IOException e) {