summaryrefslogtreecommitdiffstats
path: root/activiti-extension/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'activiti-extension/src/test')
-rw-r--r--activiti-extension/src/test/java/org/onap/workflow/activitiext/common/EnumModuleUrlTest.java45
-rw-r--r--activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApiTest.java146
-rw-r--r--activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HttpUtilTest.java70
3 files changed, 250 insertions, 11 deletions
diff --git a/activiti-extension/src/test/java/org/onap/workflow/activitiext/common/EnumModuleUrlTest.java b/activiti-extension/src/test/java/org/onap/workflow/activitiext/common/EnumModuleUrlTest.java
new file mode 100644
index 0000000..d7b0e57
--- /dev/null
+++ b/activiti-extension/src/test/java/org/onap/workflow/activitiext/common/EnumModuleUrlTest.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2017 [ZTE] and others.
+ *
+ * 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.activitiext.common;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.msb.sdk.discovery.common.RouteException;
+import org.onap.workflow.utils.MsbUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ *
+ */
+@PrepareForTest({MsbUtils.class})
+@RunWith(PowerMockRunner.class)
+public class EnumModuleUrlTest {
+ @Test
+ public void testGetBaseUrl() {
+ try {
+ String baseUrl = "http://127.0.0.1:80";
+ PowerMockito.mockStatic(MsbUtils.class);
+ PowerMockito.when(MsbUtils.getServiceAddress("catalog", "v1")).thenReturn(baseUrl);
+ Assert.assertEquals(baseUrl, EnumModuleUrl.getBaseUrl(ServiceType.catalog));
+ } catch (RouteException e) {
+ assert (false);
+ }
+ }
+}
diff --git a/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApiTest.java b/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApiTest.java
new file mode 100644
index 0000000..7e791f7
--- /dev/null
+++ b/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HighLevelRestApiTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.activitiext.restservicetask;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@PrepareForTest({HighLevelRestApi.class,LowLevelRestApi.class})
+@RunWith(PowerMockRunner.class)
+public class HighLevelRestApiTest {
+
+ private HighLevelRestApi highLevelRestApi;
+
+ @Before
+ public void setUp() {
+ highLevelRestApi = new HighLevelRestApi();
+ }
+
+ @Test
+ public void testGet() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ HighLevelRestApi.Get(uri, acceptValue, contentTypeValue);
+ assertThat(HighLevelRestApi.Get(uri, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testPost() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars";
+ String requestBody = "{'type':'NFAR'}";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ assertThat(HighLevelRestApi.Post(uri, requestBody, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testDelete() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars/aa1bc611c9fbc08247d5ea71fd67ec3f";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ assertThat(HighLevelRestApi.Delete(uri, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testPut() {
+
+ try {
+ HttpResponseMessage msg = new HttpResponseMessage();
+ msg.setStatusCode(200);
+ msg.setResponseBody(null);
+ PowerMockito.mockStatic(LowLevelRestApi.class);
+ PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
+
+ String uri = "10.74.148.107/openoapi/catalog/v1/csars";
+ String requestBody = "{'type':'NFAR'}";
+ String acceptValue = "application/json";
+ String contentTypeValue = "application/json";
+
+ assertThat(HighLevelRestApi.Put(uri, requestBody, acceptValue, contentTypeValue), is(msg));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testCreateNameValuePairArrayFromQuery() {
+ NameValuePair[] pair = new NameValuePair[2];
+ NameValuePair p1 = new NameValuePair();
+ p1.setName("name");
+ p1.setValue("liuyao");
+ NameValuePair p2 = new NameValuePair();
+ p2.setName("pwd");
+ p2.setValue("zte");
+
+ pair[0] = p1;
+ pair[1] = p2;
+
+ String query = "name=liuyao&pwd=zte";
+
+ assertThat(highLevelRestApi.createNameValuePairArrayFromQuery(query), is(pair));
+ }
+
+}
diff --git a/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HttpUtilTest.java b/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HttpUtilTest.java
index d2298c1..b117b97 100644
--- a/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HttpUtilTest.java
+++ b/activiti-extension/src/test/java/org/onap/workflow/activitiext/restservicetask/HttpUtilTest.java
@@ -15,19 +15,18 @@
*/
package org.onap.workflow.activitiext.restservicetask;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.powermock.api.mockito.PowerMockito.mock;
-import java.util.ArrayList;
-
+import org.activiti.engine.ActivitiException;
import org.activiti.engine.delegate.DelegateExecution;
-import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
+import org.onap.workflow.activitiext.common.Parameter;
+import org.onap.workflow.activitiext.common.RestInfo;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -42,24 +41,73 @@ public class HttpUtilTest {
public void setUp() {
httpUtil = new HttpUtil();
}
-
+
@Test
- public void testExecute() {
+ public void testExecute(){
+
+ DelegateExecution executionEntity = mock(ExecutionEntity.class);
+
+ HttpUtil httpUtil1 = mock(HttpUtil.class);;
try {
+ httpUtil1.execute(executionEntity);
- DelegateExecution executionEntity = mock(ExecutionEntity.class);
+ Assert.assertTrue(true);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ Assert.assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testExecuteMethod() {
+
+ DelegateExecution executionEntity = mock(ExecutionEntity.class);
+ HttpUtil httpUtil1 = mock(HttpUtil.class);;
+ try {
PowerMockito.when(executionEntity.getCurrentActivityId()).thenReturn("1111");
HttpResponseMessage msg = new HttpResponseMessage();
msg.setStatusCode(200);
- msg.setResponseBody("success");
+ msg.setResponseBody(null);
PowerMockito.mockStatic(HighLevelRestApi.class);
- PowerMockito.when(HighLevelRestApi.invoke(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(msg);
+ PowerMockito.when(HighLevelRestApi.invoke(Mockito.anyObject())).thenReturn(msg);
- assertThat(httpUtil.executeMethod(executionEntity), is(true));
+ httpUtil1.executeMethod(executionEntity);
+ Assert.assertTrue(true);
} catch (Exception e) {
e.printStackTrace();
+ Assert.assertTrue(false);
+ }
+ }
+
+ @Test
+ public void testHandleParam(){
+
+ try {
+ DelegateExecution executionEntity = mock(ExecutionEntity.class);
+ Parameter param = new Parameter();
+ param.setName("id");
+ param.setPosition("path");
+ param.setType("");
+ param.setValue("abc");
+
+ RestInfo info = new RestInfo();
+ info.setMethod("GET");
+ info.setName("name");
+ info.setPath("/catalog/v1");
+ info.setRealUri("");
+ info.setUrl("csars");
+ info.setVersion("v1");
+
+ httpUtil.handleParam(executionEntity, param, info);
+ Assert.assertTrue(true);
+ } catch (ActivitiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ Assert.assertTrue(true);
}
+
}
}