Add unit test for vfc-nfvo-wfengine
[vfc/nfvo/wfengine.git] / activiti-extension / src / test / java / org / onap / workflow / activitiext / restservicetask / HttpUtilTest.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.activitiext.restservicetask;
17
18 import static org.hamcrest.CoreMatchers.is;
19 import static org.hamcrest.MatcherAssert.assertThat;
20 import static org.powermock.api.mockito.PowerMockito.mock;
21
22 import java.util.ArrayList;
23
24 import org.activiti.engine.delegate.DelegateExecution;
25 import org.activiti.engine.impl.context.Context;
26 import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mockito;
31 import org.powermock.api.mockito.PowerMockito;
32 import org.powermock.core.classloader.annotations.PrepareForTest;
33 import org.powermock.modules.junit4.PowerMockRunner;
34
35 @PrepareForTest({HighLevelRestApi.class})
36 @RunWith(PowerMockRunner.class)
37 public class HttpUtilTest {
38
39         private HttpUtil httpUtil;
40
41         @Before
42         public void setUp() {
43                 httpUtil = new HttpUtil();
44         }
45
46         @Test
47         public void testExecute() {
48                 try {
49                         
50                         DelegateExecution executionEntity = mock(ExecutionEntity.class);
51                         
52                         PowerMockito.when(executionEntity.getCurrentActivityId()).thenReturn("1111");
53                         
54                         HttpResponseMessage msg = new HttpResponseMessage();
55                         msg.setStatusCode(200);
56                         msg.setResponseBody("success");
57                         PowerMockito.mockStatic(HighLevelRestApi.class);
58                         PowerMockito.when(HighLevelRestApi.invoke(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(msg);
59                         
60                         assertThat(httpUtil.executeMethod(executionEntity), is(true));
61                 } catch (Exception e) {
62                         e.printStackTrace();
63                 }
64         }
65 }