Move some tests from group 3 to group 5
[vid.git] / vid-automation / src / main / java / org / onap / vid / api / BaseApiTest.java
index 3778e4b..48ca526 100644 (file)
@@ -8,7 +8,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.isEmptyOrNullString;
 import static org.hamcrest.Matchers.not;
 
-//import com.automation.common.report_portal_integration.listeners.ReportPortalListener;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
@@ -21,7 +20,6 @@ import java.util.Properties;
 import java.util.Random;
 import java.util.TimeZone;
 import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
 import org.apache.commons.io.IOUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -39,6 +37,7 @@ import vid.automation.reportportal.ReportPortalListenerDelegator;
 import vid.automation.test.infra.FeaturesTogglingConfiguration;
 import vid.automation.test.services.UsersService;
 import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor;
+import vid.automation.test.utils.InsecureHttpsClient;
 
 @Listeners(ReportPortalListenerDelegator.class)
 public class BaseApiTest {
@@ -51,16 +50,16 @@ public class BaseApiTest {
     @SuppressWarnings("WeakerAccess")
     protected Client client;
     protected Random random;
-    protected final RestTemplate restTemplate = new RestTemplate();
+    protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate();
 
-    protected final UsersService usersService = new UsersService();
-    protected final RestTemplate restTemplateErrorAgnostic = new RestTemplate();
+    protected static final UsersService usersService = new UsersService();
+    protected final RestTemplate restTemplateErrorAgnostic = InsecureHttpsClient.newRestTemplate();
 
     @BeforeClass
     public void init() {
         uri = getUri();
         objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
-        client = ClientBuilder.newClient();
+        client = InsecureHttpsClient.newJaxrsClient();
         client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
         random = new Random(System.currentTimeMillis());
         FeaturesTogglingConfiguration.initializeFeatureManager();
@@ -69,7 +68,8 @@ public class BaseApiTest {
     private URI getUri() {
         String host = System.getProperty("VID_HOST", "127.0.0.1");
         int port = Integer.valueOf(System.getProperty("VID_PORT", "8080"));
-        return new JerseyUriBuilder().host(host).port(port).scheme("http").path("vid").build();
+        String protocol = System.getProperty("VID_PROTOCOL", "http");
+        return new JerseyUriBuilder().host(host).port(port).scheme(protocol).path("vid").build();
     }
 
     public void login() {
@@ -77,9 +77,20 @@ public class BaseApiTest {
     }
 
     public void login(UserCredentials userCredentials) {
+        final List<ClientHttpRequestInterceptor> interceptors = loginWithChosenRESTClient(userCredentials, restTemplate);
+        restTemplateErrorAgnostic.setInterceptors(interceptors);
+        restTemplateErrorAgnostic.setErrorHandler(new DefaultResponseErrorHandler() {
+            @Override
+            public boolean hasError(ClientHttpResponse response) {
+                return false;
+            }
+        });
+    }
+
+    public List<ClientHttpRequestInterceptor> loginWithChosenRESTClient(UserCredentials userCredentials,RestTemplate givenRestTemplate) {
         final List<ClientHttpRequestInterceptor> interceptors = singletonList(new CookieAndJsonHttpHeadersInterceptor(getUri(), userCredentials));
-        restTemplate.setInterceptors(interceptors);
-        restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
+        givenRestTemplate.setInterceptors(interceptors);
+        givenRestTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
             @Override
             public void handleError(ClientHttpResponse response) throws IOException {
                 try {
@@ -90,14 +101,7 @@ public class BaseApiTest {
                 }
             }
         });
-
-        restTemplateErrorAgnostic.setInterceptors(interceptors);
-        restTemplateErrorAgnostic.setErrorHandler(new DefaultResponseErrorHandler() {
-            @Override
-            public boolean hasError(ClientHttpResponse response) {
-                return false;
-            }
-        });
+        return interceptors;
     }