Merge "JUnit tests for MsoMulticloudUtils"
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / BaseTest.java
index 36a50fd..82b18d8 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * 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
 package org.onap.so;
 
 
-import com.github.tomakehurst.wiremock.client.WireMock;
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.ws.rs.core.MediaType;
+
 import org.apache.http.HttpHeaders;
 import org.apache.http.HttpStatus;
 import org.junit.After;
@@ -31,20 +42,15 @@ import org.onap.so.db.catalog.beans.AuthenticationType;
 import org.onap.so.db.catalog.beans.CloudIdentity;
 import org.onap.so.db.catalog.beans.CloudSite;
 import org.onap.so.db.catalog.beans.ServerType;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import javax.ws.rs.core.MediaType;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-import static com.github.tomakehurst.wiremock.client.WireMock.*;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.client.WireMock;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -54,10 +60,12 @@ public abstract class BaseTest extends TestDataSetup {
 
        @Value("${wiremock.server.port}")
        protected int wireMockPort;
+       @Autowired
+       protected WireMockServer wireMockServer;
        
        @After
        public void after() {
-               WireMock.reset();
+               wireMockServer.resetAll();
        }
 
        protected static String getBody(String body, int port, String urlPath) throws IOException {
@@ -72,21 +80,21 @@ public abstract class BaseTest extends TestDataSetup {
        }
 
        private void mockCloud(CloudIdentity identity, CloudSite cloudSite) throws IOException {
-               stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse()
+               wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse()
                                .withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
                                .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
                                .withStatus(HttpStatus.SC_OK)));
-               stubFor(get(urlPathEqualTo("/cloudSite/default")).willReturn(aResponse()
+               wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse()
                                .withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, ""))
                                .withHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
                                .withStatus(HttpStatus.SC_OK)));
-               stubFor(get(urlPathEqualTo("/cloudIdentity/mtn13")).willReturn(aResponse()
+               wireMockServer.stubFor(get(urlPathEqualTo("/cloudIdentity/mtn13")).willReturn(aResponse()
                                .withBody(getBody(mapper.writeValueAsString(identity),wireMockPort, ""))
                                .withHeader(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON)
                                .withStatus(HttpStatus.SC_OK)));
        }
 
-       private CloudIdentity getCloudIdentity() {
+       protected CloudIdentity getCloudIdentity() {
                CloudIdentity identity = new CloudIdentity();
                identity.setId("mtn13");
                identity.setMsoId("m93945");
@@ -100,7 +108,7 @@ public abstract class BaseTest extends TestDataSetup {
                return identity;
        }
 
-       private CloudSite getCloudSite(CloudIdentity identity) {
+       protected CloudSite getCloudSite(CloudIdentity identity) {
                CloudSite cloudSite = new CloudSite();
                cloudSite.setId("MTN13");
                cloudSite.setCloudVersion("3.0");
@@ -123,4 +131,4 @@ public abstract class BaseTest extends TestDataSetup {
                        return sb.toString();
                }
        }
-}
\ No newline at end of file
+}