0d08427d4ff80187c25c7a5a1e289c5762708d9e
[vfc/nfvo/wfengine.git] / wfenginemgrservice / src / test / java / org / onap / workflow / resources / WorkflowInstanceWrapperTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.workflow.resources;
17
18 import static org.powermock.api.mockito.PowerMockito.mock;
19
20 import java.io.InputStream;
21
22 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
23 import org.junit.After;
24 import org.junit.AfterClass;
25 import org.junit.Before;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.onap.workflow.common.RestResponse;
30 import org.onap.workflow.entity.StartProcessRequest;
31 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiDeployResponse;
32 import org.onap.workflow.externalservice.entity.activitientitiy.ActivitiStartProcessRequest;
33 import org.onap.workflow.externalservice.service.activitiservice.ActivitiServiceConsumer;
34 import org.onap.workflow.wrapper.WorkflowInstanceWrapper;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
38
39 @PrepareForTest({ActivitiServiceConsumer.class})
40 @RunWith(PowerMockRunner.class)
41 public class WorkflowInstanceWrapperTest {
42
43   private WorkflowInstanceWrapper workflowInstanceWrapper;
44
45   @BeforeClass
46   public static void setUpBeforeClass() throws Exception {}
47
48   @AfterClass
49   public static void tearDownAfterClass() throws Exception {}
50
51   @Before
52   public void setUp() throws Exception {
53     workflowInstanceWrapper = new WorkflowInstanceWrapper();
54     PowerMockito.mockStatic(ActivitiServiceConsumer.class);// 3
55   }
56
57   @After
58   public void tearDown() throws Exception {}
59
60   @Test
61   public final void testDeployBpmnFile() throws Exception {
62
63     InputStream fileInputStream = mock(InputStream.class);
64     FormDataContentDisposition f = mock(FormDataContentDisposition.class);
65     String filename = "test";
66     ActivitiDeployResponse reponse = new ActivitiDeployResponse();
67     reponse.setId("123");
68     reponse.setUrl("http://url");
69     PowerMockito.mockStatic(ActivitiServiceConsumer.class);
70     PowerMockito.when(ActivitiServiceConsumer.deploybpmnfile(fileInputStream, filename))
71         .thenReturn(reponse);
72     workflowInstanceWrapper.deployBpmnFile(filename, fileInputStream, f);
73     // assertThat(, is(result));
74   }
75
76   @Test
77   public final void testUndeployBpmnFile() throws Exception {
78     WorkflowInstanceWrapper.getInstance().undeployBpmnFile(null);
79   }
80
81   @Test
82   public final void testStartProcess() throws Exception {
83     ActivitiStartProcessRequest startProcessRequest = new ActivitiStartProcessRequest();
84     startProcessRequest.setProcessDefinitionKey("first");
85     StartProcessRequest tt = new StartProcessRequest();
86     tt.setProcessDefinitionKey("first");
87     RestResponse reponse = new RestResponse();
88     reponse.setResult("123");
89     PowerMockito.mockStatic(ActivitiServiceConsumer.class);
90     PowerMockito.when(ActivitiServiceConsumer.startBpmnProcess(startProcessRequest))
91         .thenReturn(reponse);
92     workflowInstanceWrapper.startProcess(tt);
93   }
94
95 }