2 * Copyright 2017 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onap.workflow.externalservice.service.activitiservice;
\r
18 import static org.mockito.Mockito.mock;
\r
19 import static org.powermock.api.mockito.PowerMockito.when;
\r
21 import java.io.FileInputStream;
\r
22 import java.io.IOException;
\r
23 import java.io.InputStream;
\r
25 import org.apache.http.client.ClientProtocolException;
\r
26 import org.junit.Assert;
\r
27 import org.junit.Test;
\r
28 import org.mockito.Mockito;
\r
29 import org.onap.workflow.WorkflowAppConfig;
\r
30 import org.onap.workflow.common.Config;
\r
31 import org.onap.workflow.common.RestClient;
\r
32 import org.onap.workflow.common.RestResponse;
\r
33 import org.onap.workflow.entity.MsbClientConfig;
\r
34 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
\r
35 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
\r
37 public class ActivitiServiceConsumerTest {
\r
39 public void undeploybpmnfile() throws ClientProtocolException, IOException {
\r
40 RestClient.setIsTest(true);
\r
41 RestResponse response = ActivitiServiceConsumer.undeploybpmnfile("22");
\r
42 Assert.assertTrue(response != null);
\r
43 RestClient.setIsTest(false);
\r
47 public void startBpmnProcess() throws Exception {
\r
48 RestClient.setIsTest(true);
\r
49 RestResponse response =
\r
50 ActivitiServiceConsumer.startBpmnProcess(mock(ActivitiStartProcessRequest.class));
\r
51 Assert.assertTrue(response != null);
\r
52 RestClient.setIsTest(false);
\r
56 public void testDeleteDeployProcess() throws Exception {
\r
57 RestClient.setIsTest(true);
\r
58 RestResponse response = ActivitiServiceConsumer.deleteDeployProcess("22");
\r
59 Assert.assertTrue(response != null);
\r
60 RestClient.setIsTest(false);
\r
64 public void testDeleteDeployProcessReturnNull() throws Exception {
\r
65 RestClient.setIsTest(false);
\r
66 RestResponse response = ActivitiServiceConsumer.deleteDeployProcess("22");
\r
67 if (response != null) {
\r
68 Assert.assertTrue(response.getResult() == null);
\r
70 Assert.assertTrue(response == null);
\r
75 public void testStartProcessShouldReturnResponse() throws Exception {
\r
76 RestClient.setIsTest(true);
\r
77 RestResponse response =
\r
78 ActivitiServiceConsumer.startProcess(mock(ActivitiStartProcessRequest.class));
\r
79 Assert.assertTrue(response != null);
\r
80 RestClient.setIsTest(false);
\r
84 public void testStartProcessShouldReturnNull() {
\r
85 RestClient.setIsTest(false);
\r
86 RestResponse response =
\r
87 ActivitiServiceConsumer.startProcess(mock(ActivitiStartProcessRequest.class));
\r
88 Assert.assertTrue(response.getResult() == null);
\r
92 public void deploybpmnfile() throws Exception {
\r
93 RestClient.setIsTest(true);
\r
94 WorkflowAppConfig workflowAppConfig = new WorkflowAppConfig();
\r
95 MsbClientConfig msbClientConfig = new MsbClientConfig();
\r
96 msbClientConfig.setMsbSvrPort(2);
\r
97 msbClientConfig.setMsbSvrIp("127.0.0.1");
\r
98 workflowAppConfig.setMsbClientConfig(msbClientConfig);
\r
99 Config.setWorkflowAppConfig(workflowAppConfig);
\r
100 InputStream ins = mock(InputStream.class);
\r
101 // Byte b[]=(Byte) mock(Byte.class);
\r
102 when(ins.read(Mockito.anyObject())).thenReturn(-21);
\r
103 ActivitiDeployResponse result = ActivitiServiceConsumer.deploybpmnfile(ins, "result");
\r
104 Assert.assertTrue(result == null);
\r
105 RestClient.setIsTest(false);
\r