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 org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Listeners;
+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 {
protected static final Logger LOGGER = LogManager.getLogger(BaseApiTest.class);
@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();
}
private URI getUri() {
- String host = System.getProperty("VID_HOST", "10.0.0.10");
+ 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() {
}
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 {
}
}
});
-
- restTemplateErrorAgnostic.setInterceptors(interceptors);
- restTemplateErrorAgnostic.setErrorHandler(new DefaultResponseErrorHandler() {
- @Override
- public boolean hasError(ClientHttpResponse response) {
- return false;
- }
- });
+ return interceptors;
}