Fix the docker build error for vfc-nfvo-wfengine
[vfc/nfvo/wfengine.git] / wfenginemgrservice / src / test / java / org / onap / workflow / externalservice / service / activitiservice / ActivitiServiceConsumerTest.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  * <p>\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
7  * <p>\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  * <p>\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
15  */\r
16 package org.onap.workflow.externalservice.service.activitiservice;\r
17 \r
18 import static org.mockito.Mockito.mock;\r
19 import static org.powermock.api.mockito.PowerMockito.when;\r
20 \r
21 import java.io.FileInputStream;\r
22 import java.io.IOException;\r
23 import java.io.InputStream;\r
24 \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
36 \r
37 public class ActivitiServiceConsumerTest {\r
38   @Test\r
39   public void undeploybpmnfile() throws ClientProtocolException, IOException {\r
40     RestClient.isTest = true;\r
41     RestResponse response = ActivitiServiceConsumer.undeploybpmnfile("22");\r
42     Assert.assertTrue(response != null);\r
43     RestClient.isTest = false;\r
44   }\r
45 \r
46   @Test\r
47   public void startBpmnProcess() throws Exception {\r
48     RestClient.isTest = true;\r
49     RestResponse response =\r
50         ActivitiServiceConsumer.startBpmnProcess(mock(ActivitiStartProcessRequest.class));\r
51     Assert.assertTrue(response != null);\r
52     RestClient.isTest = false;\r
53   }\r
54 \r
55   @Test\r
56   public void testDeleteDeployProcess() throws Exception {\r
57     RestClient.isTest = true;\r
58     RestResponse response = ActivitiServiceConsumer.deleteDeployProcess("22");\r
59     Assert.assertTrue(response != null);\r
60     RestClient.isTest = false;\r
61   }\r
62 \r
63   @Test\r
64   public void testDeleteDeployProcessReturnNull() throws Exception {\r
65     RestClient.isTest = false;\r
66     RestResponse response = ActivitiServiceConsumer.deleteDeployProcess("22");\r
67     if (response != null) {\r
68       Assert.assertTrue(response.getResult() == null);\r
69     } else {\r
70       Assert.assertTrue(response == null);\r
71     }\r
72   }\r
73 \r
74   @Test\r
75   public void testStartProcessShouldReturnResponse() throws Exception {\r
76     RestClient.isTest = true;\r
77     RestResponse response =\r
78         ActivitiServiceConsumer.startProcess(mock(ActivitiStartProcessRequest.class));\r
79     Assert.assertTrue(response != null);\r
80     RestClient.isTest = false;\r
81   }\r
82 \r
83   @Test\r
84   public void testStartProcessShouldReturnNull() {\r
85     RestClient.isTest = false;\r
86     RestResponse response =\r
87         ActivitiServiceConsumer.startProcess(mock(ActivitiStartProcessRequest.class));\r
88     Assert.assertTrue(response.getResult() == null);\r
89   }\r
90 \r
91   @Test\r
92   public void deploybpmnfile() throws Exception {\r
93     RestClient.isTest = 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.isTest = false;\r
106   }\r
107 \r
108 }