refactoring

This commit is contained in:
dashevchenko 2022-11-11 12:33:16 +02:00
parent 62ca7447c4
commit e11b5ffedd
3 changed files with 6 additions and 7 deletions

View File

@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContextBuilder;
@ -40,7 +39,6 @@ import java.util.Random;
public abstract class AbstractContainerTest { public abstract class AbstractContainerTest {
protected static long timeoutMultiplier = 1; protected static long timeoutMultiplier = 1;
protected ObjectMapper mapper = new ObjectMapper(); protected ObjectMapper mapper = new ObjectMapper();
protected JsonParser jsonParser = new JsonParser();
private static final ContainerTestSuite containerTestSuite = ContainerTestSuite.getInstance(); private static final ContainerTestSuite containerTestSuite = ContainerTestSuite.getInstance();
protected static TestRestClient testRestClient; protected static TestRestClient testRestClient;

View File

@ -51,7 +51,7 @@ import static org.thingsboard.server.common.data.StringUtils.isEmpty;
public class TestRestClient { public class TestRestClient {
private static final String JWT_TOKEN_HEADER_PARAM = "X-Authorization"; private static final String JWT_TOKEN_HEADER_PARAM = "X-Authorization";
private final String baseURL; private static final String CONTENT_TYPE_HEADER = "Content-Type";
private final RequestSpecification requestSpec; private final RequestSpecification requestSpec;
private String token; private String token;
private String refreshToken; private String refreshToken;
@ -59,12 +59,11 @@ public class TestRestClient {
public TestRestClient(String url) { public TestRestClient(String url) {
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter()); RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
baseURL = url; requestSpec = given().baseUri(url)
requestSpec = given().baseUri(baseURL)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.config(RestAssuredConfig.config() .config(RestAssuredConfig.config()
.headerConfig(HeaderConfig.headerConfig() .headerConfig(HeaderConfig.headerConfig()
.overwriteHeadersWithName(JWT_TOKEN_HEADER_PARAM))); .overwriteHeadersWithName(JWT_TOKEN_HEADER_PARAM, CONTENT_TYPE_HEADER)));
if (url.matches("^(https)://.*$")) { if (url.matches("^(https)://.*$")) {
requestSpec.relaxedHTTPSValidation(); requestSpec.relaxedHTTPSValidation();
@ -76,7 +75,8 @@ public class TestRestClient {
loginRequest.put("username", username); loginRequest.put("username", username);
loginRequest.put("password", password); loginRequest.put("password", password);
JsonPath jsonPath = given().relaxedHTTPSValidation().body(loginRequest).post(baseURL + "/api/auth/login") JsonPath jsonPath = given().spec(requestSpec).body(loginRequest)
.post( "/api/auth/login")
.getBody().jsonPath(); .getBody().jsonPath();
token = jsonPath.get("token"); token = jsonPath.get("token");
refreshToken = jsonPath.get("refreshToken"); refreshToken = jsonPath.get("refreshToken");

View File

@ -72,6 +72,7 @@ public class MqttGatewayClientTest extends AbstractContainerTest {
private MqttClient mqttClient; private MqttClient mqttClient;
private Device createdDevice; private Device createdDevice;
private MqttMessageListener listener; private MqttMessageListener listener;
private JsonParser jsonParser = new JsonParser();
@BeforeMethod @BeforeMethod
public void createGateway() throws Exception { public void createGateway() throws Exception {