refactoring
This commit is contained in:
parent
b1d5e89e9c
commit
62ca7447c4
@ -16,14 +16,12 @@
|
|||||||
package org.thingsboard.server.msa;
|
package org.thingsboard.server.msa;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
|
||||||
public class TestProperties {
|
public class TestProperties {
|
||||||
|
|
||||||
private static final String HTTPS_URL = "https://localhost";
|
private static final String HTTPS_URL = "https://localhost";
|
||||||
|
|||||||
@ -26,10 +26,6 @@ import io.restassured.http.ContentType;
|
|||||||
import io.restassured.path.json.JsonPath;
|
import io.restassured.path.json.JsonPath;
|
||||||
import io.restassured.response.ValidatableResponse;
|
import io.restassured.response.ValidatableResponse;
|
||||||
import io.restassured.specification.RequestSpecification;
|
import io.restassured.specification.RequestSpecification;
|
||||||
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.Device;
|
||||||
import org.thingsboard.server.common.data.id.DeviceId;
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
@ -47,6 +43,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static io.restassured.RestAssured.given;
|
import static io.restassured.RestAssured.given;
|
||||||
|
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
|
||||||
|
import static java.net.HttpURLConnection.HTTP_OK;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.core.AnyOf.anyOf;
|
import static org.hamcrest.core.AnyOf.anyOf;
|
||||||
import static org.thingsboard.server.common.data.StringUtils.isEmpty;
|
import static org.thingsboard.server.common.data.StringUtils.isEmpty;
|
||||||
@ -54,9 +52,9 @@ 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 final String baseURL;
|
||||||
|
private final RequestSpecification requestSpec;
|
||||||
private String token;
|
private String token;
|
||||||
private String refreshToken;
|
private String refreshToken;
|
||||||
private final RequestSpecification requestSpec;
|
|
||||||
|
|
||||||
public TestRestClient(String url) {
|
public TestRestClient(String url) {
|
||||||
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
|
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
|
||||||
@ -90,7 +88,7 @@ public class TestRestClient {
|
|||||||
.pathParams("accessToken", accessToken)
|
.pathParams("accessToken", accessToken)
|
||||||
.post("/api/device?accessToken={accessToken}")
|
.post("/api/device?accessToken={accessToken}")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(Device.class);
|
.as(Device.class);
|
||||||
}
|
}
|
||||||
@ -103,7 +101,7 @@ public class TestRestClient {
|
|||||||
.statusCode(statusCode);
|
.statusCode(statusCode);
|
||||||
}
|
}
|
||||||
public Device getDeviceById(DeviceId deviceId) {
|
public Device getDeviceById(DeviceId deviceId) {
|
||||||
return getDeviceById(deviceId, HttpStatus.OK.value())
|
return getDeviceById(deviceId, HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(Device.class);
|
.as(Device.class);
|
||||||
}
|
}
|
||||||
@ -111,7 +109,7 @@ public class TestRestClient {
|
|||||||
return given().spec(requestSpec).get("/api/device/{deviceId}/credentials", deviceId.getId())
|
return given().spec(requestSpec).get("/api/device/{deviceId}/credentials", deviceId.getId())
|
||||||
.then()
|
.then()
|
||||||
.assertThat()
|
.assertThat()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(DeviceCredentials.class);
|
.as(DeviceCredentials.class);
|
||||||
}
|
}
|
||||||
@ -120,34 +118,34 @@ public class TestRestClient {
|
|||||||
return given().spec(requestSpec).body(telemetry)
|
return given().spec(requestSpec).body(telemetry)
|
||||||
.post("/api/v1/{credentialsId}/telemetry", credentialsId)
|
.post("/api/v1/{credentialsId}/telemetry", credentialsId)
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value());
|
.statusCode(HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidatableResponse deleteDevice(DeviceId deviceId) {
|
public ValidatableResponse deleteDevice(DeviceId deviceId) {
|
||||||
return given().spec(requestSpec)
|
return given().spec(requestSpec)
|
||||||
.delete("/api/device/{deviceId}", deviceId.getId())
|
.delete("/api/device/{deviceId}", deviceId.getId())
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value());
|
.statusCode(HTTP_OK);
|
||||||
}
|
}
|
||||||
public ValidatableResponse deleteDeviceIfExists(DeviceId deviceId) {
|
public ValidatableResponse deleteDeviceIfExists(DeviceId deviceId) {
|
||||||
return given().spec(requestSpec)
|
return given().spec(requestSpec)
|
||||||
.delete("/api/device/{deviceId}", deviceId.getId())
|
.delete("/api/device/{deviceId}", deviceId.getId())
|
||||||
.then()
|
.then()
|
||||||
.statusCode(anyOf(is(HttpStatus.OK.value()),is(HttpStatus.NOT_FOUND.value())));
|
.statusCode(anyOf(is(HTTP_OK),is(HTTP_NOT_FOUND)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidatableResponse postTelemetryAttribute(String entityType, DeviceId deviceId, String scope, JsonNode attribute) {
|
public ValidatableResponse postTelemetryAttribute(String entityType, DeviceId deviceId, String scope, JsonNode attribute) {
|
||||||
return given().spec(requestSpec).body(attribute)
|
return given().spec(requestSpec).body(attribute)
|
||||||
.post("/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}", entityType, deviceId.getId(), scope)
|
.post("/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}", entityType, deviceId.getId(), scope)
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value());
|
.statusCode(HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidatableResponse postAttribute(String accessToken, JsonNode attribute) {
|
public ValidatableResponse postAttribute(String accessToken, JsonNode attribute) {
|
||||||
return given().spec(requestSpec).body(attribute)
|
return given().spec(requestSpec).body(attribute)
|
||||||
.post("/api/v1/{accessToken}/attributes/", accessToken)
|
.post("/api/v1/{accessToken}/attributes/", accessToken)
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value());
|
.statusCode(HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonNode getAttributes(String accessToken, String clientKeys, String sharedKeys) {
|
public JsonNode getAttributes(String accessToken, String clientKeys, String sharedKeys) {
|
||||||
@ -156,7 +154,7 @@ public class TestRestClient {
|
|||||||
.queryParam("sharedKeys", sharedKeys)
|
.queryParam("sharedKeys", sharedKeys)
|
||||||
.get("/api/v1/{accessToken}/attributes", accessToken)
|
.get("/api/v1/{accessToken}/attributes", accessToken)
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(JsonNode.class);
|
.as(JsonNode.class);
|
||||||
}
|
}
|
||||||
@ -167,7 +165,7 @@ public class TestRestClient {
|
|||||||
return given().spec(requestSpec).queryParams(params)
|
return given().spec(requestSpec).queryParams(params)
|
||||||
.get("/api/ruleChains")
|
.get("/api/ruleChains")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(new TypeRef<PageData<RuleChain>>() {});
|
.as(new TypeRef<PageData<RuleChain>>() {});
|
||||||
}
|
}
|
||||||
@ -177,7 +175,7 @@ public class TestRestClient {
|
|||||||
.body(ruleChain)
|
.body(ruleChain)
|
||||||
.post("/api/ruleChain")
|
.post("/api/ruleChain")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(RuleChain.class);
|
.as(RuleChain.class);
|
||||||
}
|
}
|
||||||
@ -187,7 +185,7 @@ public class TestRestClient {
|
|||||||
.body(ruleChainMetaData)
|
.body(ruleChainMetaData)
|
||||||
.post("/api/ruleChain/metadata")
|
.post("/api/ruleChain/metadata")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(RuleChainMetaData.class);
|
.as(RuleChainMetaData.class);
|
||||||
}
|
}
|
||||||
@ -196,14 +194,14 @@ public class TestRestClient {
|
|||||||
given().spec(requestSpec)
|
given().spec(requestSpec)
|
||||||
.post("/api/ruleChain/{ruleChainId}/root", ruleChainId.getId())
|
.post("/api/ruleChain/{ruleChainId}/root", ruleChainId.getId())
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value());
|
.statusCode(HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteRuleChain(RuleChainId ruleChainId) {
|
public void deleteRuleChain(RuleChainId ruleChainId) {
|
||||||
given().spec(requestSpec)
|
given().spec(requestSpec)
|
||||||
.delete("/api/ruleChain/{ruleChainId}", ruleChainId.getId())
|
.delete("/api/ruleChain/{ruleChainId}", ruleChainId.getId())
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value());
|
.statusCode(HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUrlParams(PageLink pageLink) {
|
private String getUrlParams(PageLink pageLink) {
|
||||||
@ -239,7 +237,7 @@ public class TestRestClient {
|
|||||||
.pathParams(params)
|
.pathParams(params)
|
||||||
.get("/api/relations?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}")
|
.get("/api/relations?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(new TypeRef<List<EntityRelation>>() {});
|
.as(new TypeRef<List<EntityRelation>>() {});
|
||||||
}
|
}
|
||||||
@ -249,7 +247,7 @@ public class TestRestClient {
|
|||||||
.body(serverRpcPayload)
|
.body(serverRpcPayload)
|
||||||
.post("/api/rpc/twoway/{deviceId}", deviceId.getId())
|
.post("/api/rpc/twoway/{deviceId}", deviceId.getId())
|
||||||
.then()
|
.then()
|
||||||
.statusCode(HttpStatus.OK.value())
|
.statusCode(HTTP_OK)
|
||||||
.extract()
|
.extract()
|
||||||
.as(JsonNode.class);
|
.as(JsonNode.class);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user