summaryrefslogtreecommitdiffstats
path: root/wfenginemgrservice/src/test/java/org/onap/workflow/resources/WorkflowResourceTest.java
blob: 7d8b19460a739f78116c39fb253c3246efffa010 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * Copyright 2017 ZTE Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onap.workflow.resources;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

import java.io.IOException;
import java.io.InputStream;

import javax.ws.rs.core.Response;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.workflow.common.RestResponse;
import org.onap.workflow.entity.StartProcessRequest;
import org.onap.workflow.wrapper.WorkflowInstanceWrapper;
import org.powermock.reflect.Whitebox;

public class WorkflowResourceTest {
	
	private WorkflowResource workflowResource;
	private WorkflowInstanceWrapper workflowInstanceWrapper;
	
	@Before
	public void setUp() {

		workflowInstanceWrapper = mock(WorkflowInstanceWrapper.class);
		Whitebox.setInternalState(WorkflowInstanceWrapper.class, "wrapper", workflowInstanceWrapper);
	
		workflowResource =  new WorkflowResource();
	}

	@Test
	public void testDeployBpmnFile() {
		
 		InputStream fileInputStream = mock(InputStream.class);
		FormDataContentDisposition fileDetail = mock(FormDataContentDisposition.class);
		
		Response result = Response.ok("success").build();
	  //  when(fileInputStream.read()).thenReturn(-1);
	    try {
        when(fileInputStream.read(Mockito.anyObject())).thenReturn(-21);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

		when(workflowInstanceWrapper.deployBpmnFile(Mockito.anyString(), Mockito.anyObject(), Mockito.anyObject())).thenReturn(result);

		assertThat(workflowResource.deployBpmnFile(fileInputStream,fileDetail), is(result));
	}
	
	@Test
	public void testUndeployBpmnFile(){
		
		String deployId = "40";
		
		RestResponse result = new RestResponse();
		
		when(workflowInstanceWrapper.undeployBpmnFile(Mockito.anyString())).thenReturn(result);
		
		assertThat(workflowResource.undeployBpmnFile(deployId), is(result));
	}
	
	@Test
	public void testStartProcess(){
		
		StartProcessRequest request = new StartProcessRequest();
		
		Response result = Response.ok("success").build();
		
		when(workflowInstanceWrapper.startProcess(Mockito.anyObject())).thenReturn(result);
	
		assertThat(workflowResource.startProcess(request), is(result));
	}
}