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;
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 {
@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 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();
import vid.automation.test.services.UsersService;
import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor;
import vid.automation.test.utils.DB_CONFIG;
+import vid.automation.test.utils.InsecureHttpsClient;
import vid.automation.test.utils.TestConfigurationHelper;
import vid.automation.test.utils.TestHelper;
protected final UsersService usersService = new UsersService();
protected final CategoryParamsService categoryParamsService = new CategoryParamsService();
- protected final RestTemplate restTemplate = new RestTemplate();
+ protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate();
protected final URI uri;
protected final URI envUrI;
package vid.automation.test.utils;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
import org.junit.Assert;
import org.onap.sdc.ci.tests.datatypes.UserCredentials;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpRequest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.support.HttpRequestWrapper;
import org.springframework.web.client.RestTemplate;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-
public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInterceptor {
private final HttpHeaders cookieAndJsonHttpHeaders;
protected HttpHeaders getCookieAndJsonHttpHeaders(URI uri, UserCredentials userCredentials) {
HttpHeaders loginRequestHeaders = new HttpHeaders();
loginRequestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
- RestTemplate restTemplate = new RestTemplate();
+ RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate();
ResponseEntity<String> loginRes = restTemplate.postForEntity(uri.toASCIIString() + "/login_external.htm", new HttpEntity<>("loginId=" + userCredentials.getUserId() + "&password=" + userCredentials.getPassword(), loginRequestHeaders), String.class);
Assert.assertEquals("Login failed - wrong http status with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), HttpStatus.FOUND, loginRes.getStatusCode());
Assert.assertNull("Failed to login with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), loginRes.getBody());
--- /dev/null
+package vid.automation.test.utils;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
+
+public class InsecureHttpsClient {
+
+ public static RestTemplate newRestTemplate() {
+ CloseableHttpClient insecureTLSHttpClient
+ = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
+ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(insecureTLSHttpClient);
+ return new RestTemplate(factory);
+ }
+
+ public static Client newJaxrsClient() {
+ return ClientBuilder.newBuilder()
+ .hostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .build();
+ }
+
+}