b117b97958b929d8cdef353fa7f57b5900332d20
[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.powermock.api.mockito.PowerMockito.mock;
19
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;
33
34 @PrepareForTest({HighLevelRestApi.class})
35 @RunWith(PowerMockRunner.class)
36 public class HttpUtilTest {
37
38         private HttpUtil httpUtil;
39
40         @Before
41         public void setUp() {
42                 httpUtil = new HttpUtil();
43         }
44         
45         @Test
46         public void testExecute(){
47                 
48                 DelegateExecution executionEntity = mock(ExecutionEntity.class);
49                 
50                 HttpUtil httpUtil1 = mock(HttpUtil.class);;
51                 try {
52                         httpUtil1.execute(executionEntity);
53                         
54                         Assert.assertTrue(true);
55                 } catch (Exception e) {
56                         // TODO Auto-generated catch block
57                         e.printStackTrace();
58                         Assert.assertTrue(false);
59                 }
60         }
61
62         @Test
63         public void testExecuteMethod() {
64                 
65                 DelegateExecution executionEntity = mock(ExecutionEntity.class);
66                 HttpUtil httpUtil1 = mock(HttpUtil.class);;
67                 try {
68                         
69                         PowerMockito.when(executionEntity.getCurrentActivityId()).thenReturn("1111");
70                         
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);
76                         
77                         httpUtil1.executeMethod(executionEntity);
78                         Assert.assertTrue(true);
79                 } catch (Exception e) {
80                         e.printStackTrace();
81                         Assert.assertTrue(false);
82                 }
83         }
84         
85         @Test
86         public void testHandleParam(){
87                 
88                 try {
89                         DelegateExecution executionEntity = mock(ExecutionEntity.class);
90                         Parameter param = new Parameter();
91                         param.setName("id");
92                         param.setPosition("path");
93                         param.setType("");
94                         param.setValue("abc");
95                         
96                         RestInfo info = new RestInfo();
97                         info.setMethod("GET");
98                         info.setName("name");
99                         info.setPath("/catalog/v1");
100                         info.setRealUri("");
101                         info.setUrl("csars");
102                         info.setVersion("v1");
103                         
104                         httpUtil.handleParam(executionEntity, param, info);
105                         Assert.assertTrue(true);
106                 } catch (ActivitiException e) {
107                         // TODO Auto-generated catch block
108                         e.printStackTrace();
109                         Assert.assertTrue(true);
110                 }
111                 
112         }
113 }