Fix the docker build error for vfc-nfvo-wfengine
[vfc/nfvo/wfengine.git] / activiti-extension / src / test / java / org / onap / workflow / activitiext / restservicetask / HighLevelRestApiTest.java
index 0f20a1e..2cc438a 100644 (file)
-/**
- * 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.HttpMethodBase;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.Assert;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-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;
-
-@PrepareForTest({LowLevelRestApi.class})
-@RunWith(PowerMockRunner.class)
-public class HighLevelRestApiTest {
-
-  private HighLevelRestApi highLevelRestApi;
-
-  @Before
-  public void setUp() {
-    highLevelRestApi = new HighLevelRestApi();
-  }
-
-  @Test
-  public void testInvoke() {
-
-    try {
-      RestInfo info = new RestInfo();
-      info.setMethod("GET");
-      info.setName("name");
-      info.setPath("/catalog/v1");
-      info.setUrl("csars");
-      info.setRealUri("");
-      info.setVersion("v1");
-
-      HttpResponseMessage msg = new HttpResponseMessage();
-      msg.setStatusCode(200);
-      msg.setResponseBody(null);
-      PowerMockito.mockStatic(LowLevelRestApi.class);
-      PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
-
-      assertThat(HighLevelRestApi.invoke(info), is(msg));;
-    } catch (Exception e) {
-      assert (false);
-    }
-  }
-
-  @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/dbtest?id=5";
-      String acceptValue = "application/json";
-      String contentTypeValue = "application/json";
-
-      assertThat(HighLevelRestApi.Get(uri, acceptValue, contentTypeValue), is(msg));
-    } catch (Exception e) {
-      assert (false);
-    }
-  }
-
-  @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/dbtest?id=5";
-      String requestBody = "{'type':'NFAR'}";
-      String acceptValue = "application/json";
-      String contentTypeValue = "application/json";
-
-      assertThat(HighLevelRestApi.Post(uri, requestBody, acceptValue, contentTypeValue), is(msg));
-    } catch (Exception e) {
-      assert (false);
-    }
-  }
-
-  @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) {
-      assert (false);
-    }
-  }
-
-  @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) {
-      assert (false);
-    }
-  }
-
-  @SuppressWarnings("static-access")
-  @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));
-  }
-
-  @Test
-  public void testSetAcceptHeader() {
-    try {
-      HttpMethodBase method = new GetMethod();
-      HighLevelRestApi.setAcceptHeader(method, "[application/json]");
-      Assert.assertTrue(true);
-    } catch (Exception e) {
-      Assert.assertTrue(false);
-    }
-  }
-
-  @Test
-  public void testSetContentTypeHeader() {
-
-    try {
-      HttpMethodBase method = new GetMethod();
-      HighLevelRestApi.setContentTypeHeader(method, "[application/json]");
-      Assert.assertTrue(true);
-    } catch (Exception e) {
-      Assert.assertTrue(false);
-    }
-  }
-
-}
+/**\r
+ * Copyright 2017 ZTE Corporation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.onap.workflow.activitiext.restservicetask;\r
+\r
+import static org.hamcrest.CoreMatchers.is;\r
+import static org.hamcrest.MatcherAssert.assertThat;\r
+\r
+import org.apache.commons.httpclient.HttpMethodBase;\r
+import org.apache.commons.httpclient.NameValuePair;\r
+import org.apache.commons.httpclient.methods.GetMethod;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mockito;\r
+import org.onap.workflow.activitiext.common.RestInfo;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+@PrepareForTest({LowLevelRestApi.class})\r
+@RunWith(PowerMockRunner.class)\r
+public class HighLevelRestApiTest {\r
+\r
+  @Test\r
+  public void testInvoke() {\r
+\r
+    try {\r
+      RestInfo info = new RestInfo();\r
+      info.setMethod("GET");\r
+      info.setName("name");\r
+      info.setPath("/catalog/v1");\r
+      info.setUrl("csars");\r
+      info.setRealUri("");\r
+      info.setVersion("v1");\r
+\r
+      HttpResponseMessage msg = new HttpResponseMessage();\r
+      msg.setStatusCode(200);\r
+      msg.setResponseBody(null);\r
+      PowerMockito.mockStatic(LowLevelRestApi.class);\r
+      PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);\r
+\r
+      assertThat(HighLevelRestApi.invoke(info), is(msg));;\r
+    } catch (Exception e) {\r
+      assert (false);\r
+    }\r
+  }\r
+\r
+  @Test\r
+  public void testGet() {\r
+\r
+    try {\r
+      HttpResponseMessage msg = new HttpResponseMessage();\r
+      msg.setStatusCode(200);\r
+      msg.setResponseBody(null);\r
+      PowerMockito.mockStatic(LowLevelRestApi.class);\r
+      PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);\r
+\r
+      String uri = "10.74.148.107/openoapi/catalog/v1/dbtest?id=5";\r
+      String acceptValue = "application/json";\r
+      String contentTypeValue = "application/json";\r
+\r
+      assertThat(HighLevelRestApi.Get(uri, acceptValue, contentTypeValue), is(msg));\r
+    } catch (Exception e) {\r
+      assert (false);\r
+    }\r
+  }\r
+\r
+  @Test\r
+  public void testPost() {\r
+\r
+    try {\r
+      HttpResponseMessage msg = new HttpResponseMessage();\r
+      msg.setStatusCode(200);\r
+      msg.setResponseBody(null);\r
+      PowerMockito.mockStatic(LowLevelRestApi.class);\r
+      PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);\r
+\r
+      String uri = "10.74.148.107/openoapi/catalog/v1/dbtest?id=5";\r
+      String requestBody = "{'type':'NFAR'}";\r
+      String acceptValue = "application/json";\r
+      String contentTypeValue = "application/json";\r
+\r
+      assertThat(HighLevelRestApi.Post(uri, requestBody, acceptValue, contentTypeValue), is(msg));\r
+    } catch (Exception e) {\r
+      assert (false);\r
+    }\r
+  }\r
+\r
+  @Test\r
+  public void testDelete() {\r
+\r
+    try {\r
+      HttpResponseMessage msg = new HttpResponseMessage();\r
+      msg.setStatusCode(200);\r
+      msg.setResponseBody(null);\r
+      PowerMockito.mockStatic(LowLevelRestApi.class);\r
+      PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);\r
+\r
+      String uri = "10.74.148.107/openoapi/catalog/v1/csars/aa1bc611c9fbc08247d5ea71fd67ec3f";\r
+      String acceptValue = "application/json";\r
+      String contentTypeValue = "application/json";\r
+\r
+      assertThat(HighLevelRestApi.Delete(uri, acceptValue, contentTypeValue), is(msg));\r
+    } catch (Exception e) {\r
+      assert (false);\r
+    }\r
+  }\r
+\r
+  @Test\r
+  public void testPut() {\r
+\r
+    try {\r
+      HttpResponseMessage msg = new HttpResponseMessage();\r
+      msg.setStatusCode(200);\r
+      msg.setResponseBody(null);\r
+      PowerMockito.mockStatic(LowLevelRestApi.class);\r
+      PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);\r
+\r
+      String uri = "10.74.148.107/openoapi/catalog/v1/csars";\r
+      String requestBody = "{'type':'NFAR'}";\r
+      String acceptValue = "application/json";\r
+      String contentTypeValue = "application/json";\r
+\r
+      assertThat(HighLevelRestApi.Put(uri, requestBody, acceptValue, contentTypeValue), is(msg));\r
+    } catch (Exception e) {\r
+      assert (false);\r
+    }\r
+  }\r
+\r
+  @SuppressWarnings("static-access")\r
+  @Test\r
+  public void testCreateNameValuePairArrayFromQuery() {\r
+    NameValuePair[] pair = new NameValuePair[2];\r
+    NameValuePair p1 = new NameValuePair();\r
+    p1.setName("name");\r
+    p1.setValue("liuyao");\r
+    NameValuePair p2 = new NameValuePair();\r
+    p2.setName("pwd");\r
+    p2.setValue("zte");\r
+\r
+    pair[0] = p1;\r
+    pair[1] = p2;\r
+\r
+    String query = "name=liuyao&pwd=zte";\r
+\r
+    assertThat(HighLevelRestApi.createNameValuePairArrayFromQuery(query), is(pair));\r
+  }\r
+\r
+  @Test\r
+  public void testSetAcceptHeader() {\r
+    try {\r
+      HttpMethodBase method = new GetMethod();\r
+      HighLevelRestApi.setAcceptHeader(method, "[application/json]");\r
+      Assert.assertTrue(true);\r
+    } catch (Exception e) {\r
+      Assert.assertTrue(false);\r
+    }\r
+  }\r
+\r
+  @Test\r
+  public void testSetContentTypeHeader() {\r
+\r
+    try {\r
+      HttpMethodBase method = new GetMethod();\r
+      HighLevelRestApi.setContentTypeHeader(method, "[application/json]");\r
+      Assert.assertTrue(true);\r
+    } catch (Exception e) {\r
+      Assert.assertTrue(false);\r
+    }\r
+  }\r
+\r
+}\r