refactoring
This commit is contained in:
parent
1ab4c03622
commit
b1d5e89e9c
@ -29,8 +29,10 @@ import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
@Slf4j
|
||||
|
||||
@ -54,7 +54,7 @@ public class ContainerTestSuite {
|
||||
|
||||
private DockerComposeContainer<?> testContainer;
|
||||
private ThingsBoardDbInstaller installTb;
|
||||
public boolean isActive;
|
||||
private boolean isActive;
|
||||
|
||||
private static ContainerTestSuite containerTestSuite;
|
||||
|
||||
|
||||
@ -15,44 +15,49 @@
|
||||
*/
|
||||
package org.thingsboard.server.msa;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TestProperties {
|
||||
public static final String HTTPS_URL = "https://localhost";
|
||||
|
||||
protected static final String WSS_URL = "wss://localhost";
|
||||
private static final String HTTPS_URL = "https://localhost";
|
||||
|
||||
public static final ContainerTestSuite instance = ContainerTestSuite.getInstance();
|
||||
private static final String WSS_URL = "wss://localhost";
|
||||
|
||||
public static String getBaseUrl(){
|
||||
private static final ContainerTestSuite instance = ContainerTestSuite.getInstance();
|
||||
|
||||
private static Properties properties;
|
||||
|
||||
public static String getBaseUrl() {
|
||||
if (instance.isActive()) {
|
||||
return HTTPS_URL;
|
||||
}
|
||||
return getProperty("tb.baseUrl");
|
||||
return getProperties().getProperty("tb.baseUrl");
|
||||
}
|
||||
|
||||
public static String getWebSocketUrl(){
|
||||
public static String getWebSocketUrl() {
|
||||
if (instance.isActive()) {
|
||||
return WSS_URL;
|
||||
}
|
||||
return getProperty("tb.wsUrl");
|
||||
return getProperties().getProperty("tb.wsUrl");
|
||||
}
|
||||
|
||||
private static String getProperty(String propertyName) {
|
||||
|
||||
try (InputStream input = TestProperties.class.getClassLoader().getResourceAsStream("config.properties")) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(input);
|
||||
return prop.getProperty(propertyName);
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
private static Properties getProperties() {
|
||||
if (properties == null) {
|
||||
try (InputStream input = TestProperties.class.getClassLoader().getResourceAsStream("config.properties")) {
|
||||
properties = new Properties();
|
||||
properties.load(input);
|
||||
} catch (IOException ex) {
|
||||
log.error("Exception while reading test properties " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,10 +17,8 @@ package org.thingsboard.server.msa;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.common.mapper.TypeRef;
|
||||
import io.restassured.config.HeaderConfig;
|
||||
import io.restassured.config.HttpClientConfig;
|
||||
import io.restassured.config.RestAssuredConfig;
|
||||
import io.restassured.filter.log.RequestLoggingFilter;
|
||||
import io.restassured.filter.log.ResponseLoggingFilter;
|
||||
@ -28,9 +26,10 @@ import io.restassured.http.ContentType;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -48,8 +47,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT;
|
||||
import static org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.core.AnyOf.anyOf;
|
||||
import static org.thingsboard.server.common.data.StringUtils.isEmpty;
|
||||
@ -59,9 +56,7 @@ public class TestRestClient {
|
||||
private final String baseURL;
|
||||
private String token;
|
||||
private String refreshToken;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
protected static final String ACTIVATE_TOKEN_REGEX = "/api/noauth/activate?activateToken=";
|
||||
private final RequestSpecification requestSpec;
|
||||
|
||||
public TestRestClient(String url) {
|
||||
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
|
||||
@ -78,7 +73,7 @@ public class TestRestClient {
|
||||
}
|
||||
}
|
||||
|
||||
public void login(String username, String password) throws Exception {
|
||||
public void login(String username, String password) {
|
||||
Map<String, String> loginRequest = new HashMap<>();
|
||||
loginRequest.put("username", username);
|
||||
loginRequest.put("password", password);
|
||||
|
||||
@ -25,12 +25,12 @@ import org.thingsboard.server.msa.AbstractContainerTest;
|
||||
import org.thingsboard.server.msa.WsClient;
|
||||
import org.thingsboard.server.msa.mapper.WsTelemetryResponse;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.thingsboard.server.common.data.DataConstants.*;
|
||||
import static org.thingsboard.server.common.data.DataConstants.DEVICE;
|
||||
import static org.thingsboard.server.common.data.DataConstants.SHARED_SCOPE;
|
||||
import static org.thingsboard.server.msa.prototypes.DevicePrototypes.defaultDevicePrototype;
|
||||
|
||||
public class HttpClientTest extends AbstractContainerTest {
|
||||
|
||||
@ -64,7 +64,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.testng.Assert.fail;
|
||||
import static org.thingsboard.server.common.data.DataConstants.DEVICE;
|
||||
import static org.thingsboard.server.common.data.DataConstants.SHARED_SCOPE;
|
||||
import static org.thingsboard.server.msa.TestProperties.HTTPS_URL;
|
||||
import static org.thingsboard.server.msa.prototypes.DevicePrototypes.defaultDevicePrototype;
|
||||
|
||||
@Slf4j
|
||||
|
||||
@ -28,7 +28,6 @@ import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
@ -52,8 +51,15 @@ import org.thingsboard.server.msa.mapper.WsTelemetryResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.thingsboard.server.common.data.DataConstants.DEVICE;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user