2 * Copyright 2017 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.workflow.activitiext.restservicetask;
18 import static org.powermock.api.mockito.PowerMockito.mock;
20 import org.activiti.engine.ActivitiException;
21 import org.activiti.engine.delegate.DelegateExecution;
22 import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mockito;
28 import org.onap.workflow.activitiext.common.Parameter;
29 import org.onap.workflow.activitiext.common.RestInfo;
30 import org.powermock.api.mockito.PowerMockito;
31 import org.powermock.core.classloader.annotations.PrepareForTest;
32 import org.powermock.modules.junit4.PowerMockRunner;
34 @PrepareForTest({HighLevelRestApi.class})
35 @RunWith(PowerMockRunner.class)
36 public class HttpUtilTest {
38 private HttpUtil httpUtil;
42 httpUtil = new HttpUtil();
46 public void testExecute(){
48 DelegateExecution executionEntity = mock(ExecutionEntity.class);
50 HttpUtil httpUtil1 = mock(HttpUtil.class);;
52 httpUtil1.execute(executionEntity);
54 Assert.assertTrue(true);
55 } catch (Exception e) {
56 // TODO Auto-generated catch block
58 Assert.assertTrue(false);
63 public void testExecuteMethod() {
65 DelegateExecution executionEntity = mock(ExecutionEntity.class);
66 HttpUtil httpUtil1 = mock(HttpUtil.class);;
69 PowerMockito.when(executionEntity.getCurrentActivityId()).thenReturn("1111");
71 HttpResponseMessage msg = new HttpResponseMessage();
72 msg.setStatusCode(200);
73 msg.setResponseBody(null);
74 PowerMockito.mockStatic(HighLevelRestApi.class);
75 PowerMockito.when(HighLevelRestApi.invoke(Mockito.anyObject())).thenReturn(msg);
77 httpUtil1.executeMethod(executionEntity);
78 Assert.assertTrue(true);
79 } catch (Exception e) {
81 Assert.assertTrue(false);
86 public void testHandleParam(){
89 DelegateExecution executionEntity = mock(ExecutionEntity.class);
90 Parameter param = new Parameter();
92 param.setPosition("path");
94 param.setValue("abc");
96 RestInfo info = new RestInfo();
97 info.setMethod("GET");
99 info.setPath("/catalog/v1");
101 info.setUrl("csars");
102 info.setVersion("v1");
104 httpUtil.handleParam(executionEntity, param, info);
105 Assert.assertTrue(true);
106 } catch (ActivitiException e) {
107 // TODO Auto-generated catch block
109 Assert.assertTrue(true);