summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorabhishek.c92 <abhishek.c92@samsung.com>2022-05-11 15:48:26 +0530
committerabhishek.c92 <abhishek.c92@samsung.com>2022-05-11 15:57:43 +0530
commit4c92a51c0f81f1bcb5d85a2d7ec2b827904df036 (patch)
tree8051e0513073e5c99791cf1fa67a63788bce9014
parent80eadcf431c89268222ac6c1e256cd5180d4aa65 (diff)
Test cases for mdsal-resource RestService
Junit test cases for methods in RestService class Issue-ID: CCSDK-3654 Signed-off-by: abhishek.c92 <abhishek.c92@samsung.com> Change-Id: I75484452a7912e13efe71b8d47dd02112fdc1f66
-rw-r--r--adaptors/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestRestService.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/adaptors/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestRestService.java b/adaptors/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestRestService.java
new file mode 100644
index 000000000..c907a2ac0
--- /dev/null
+++ b/adaptors/mdsal-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/TestRestService.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK
+ * ================================================================================
+ * Copyright (C) 2022 Samsung Electronics
+ * =============================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.resource.mdsal;
+
+import org.apache.commons.codec.binary.Base64;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.lang.reflect.Method;
+import java.net.HttpURLConnection;
+
+public class TestRestService {
+ @Test
+ public void testGetRestConnection() throws Exception {
+ RestService service = new RestService("HTTP", "1.1.1.1", "80",
+ "user", "pass", "JSON", "JSON");
+ Method method = RestService.class.getDeclaredMethod("getRestConnection", String.class, String.class);
+ method.setAccessible(true);
+ String url = "http" + "://" + "1.1.1.1" + ":" + "80" + "/" + "urlString";
+ HttpURLConnection urlConn = (HttpURLConnection) method.invoke(service,
+ url, "GET");
+ String authStr = "user" + ":" + "pass";
+ String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes()));
+ Assert.assertEquals("GET", urlConn.getRequestMethod());
+ Assert.assertEquals(url, urlConn.getURL().toString());
+ Assert.assertEquals("application/json", urlConn.getRequestProperty("Accept"));
+ Assert.assertEquals("Basic " + encodedAuthStr, urlConn.getRequestProperty("Authentication"));
+ }
+}