Search in sources :

Example 1 with ClaimRequest

use of org.thingsboard.server.common.data.ClaimRequest in project thingsboard by thingsboard.

the class AbstractCoapClaimDeviceTest method validateClaimResponse.

protected void validateClaimResponse(boolean emptyPayload, CoapClient client, byte[] payloadBytes, byte[] failurePayloadBytes) throws Exception {
    postClaimRequest(client, failurePayloadBytes);
    loginUser(customerAdmin.getName(), CUSTOMER_USER_PASSWORD);
    ClaimRequest claimRequest;
    if (!emptyPayload) {
        claimRequest = new ClaimRequest("value");
    } else {
        claimRequest = new ClaimRequest(null);
    }
    ClaimResponse claimResponse = doExecuteWithRetriesAndInterval(() -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest()), 100, 200);
    assertEquals(claimResponse, ClaimResponse.FAILURE);
    postClaimRequest(client, payloadBytes);
    ClaimResult claimResult = doExecuteWithRetriesAndInterval(() -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResult.class, status().isOk()), 100, 200);
    assertEquals(claimResult.getResponse(), ClaimResponse.SUCCESS);
    Device claimedDevice = claimResult.getDevice();
    assertNotNull(claimedDevice);
    assertNotNull(claimedDevice.getCustomerId());
    assertEquals(customerAdmin.getCustomerId(), claimedDevice.getCustomerId());
    claimResponse = doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest());
    assertEquals(claimResponse, ClaimResponse.CLAIMED);
}
Also used : ClaimResult(org.thingsboard.server.dao.device.claim.ClaimResult) ClaimRequest(org.thingsboard.server.common.data.ClaimRequest) ClaimResponse(org.thingsboard.server.dao.device.claim.ClaimResponse) Device(org.thingsboard.server.common.data.Device)

Example 2 with ClaimRequest

use of org.thingsboard.server.common.data.ClaimRequest in project thingsboard by thingsboard.

the class AbstractMqttClaimDeviceTest method validateGatewayClaimResponse.

protected void validateGatewayClaimResponse(String deviceName, boolean emptyPayload, MqttAsyncClient client, byte[] failurePayloadBytes, byte[] payloadBytes) throws Exception {
    client.publish(MqttTopics.GATEWAY_CLAIM_TOPIC, new MqttMessage(failurePayloadBytes));
    Device savedDevice = doExecuteWithRetriesAndInterval(() -> doGet("/api/tenant/devices?deviceName=" + deviceName, Device.class), 20, 100);
    assertNotNull(savedDevice);
    loginUser(customerAdmin.getName(), CUSTOMER_USER_PASSWORD);
    ClaimRequest claimRequest;
    if (!emptyPayload) {
        claimRequest = new ClaimRequest("value");
    } else {
        claimRequest = new ClaimRequest(null);
    }
    ClaimResponse claimResponse = doPostClaimAsync("/api/customer/device/" + deviceName + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest());
    assertEquals(claimResponse, ClaimResponse.FAILURE);
    client.publish(MqttTopics.GATEWAY_CLAIM_TOPIC, new MqttMessage(payloadBytes));
    ClaimResult claimResult = doExecuteWithRetriesAndInterval(() -> doPostClaimAsync("/api/customer/device/" + deviceName + "/claim", claimRequest, ClaimResult.class, status().isOk()), 20, 100);
    assertEquals(claimResult.getResponse(), ClaimResponse.SUCCESS);
    Device claimedDevice = claimResult.getDevice();
    assertNotNull(claimedDevice);
    assertNotNull(claimedDevice.getCustomerId());
    assertEquals(customerAdmin.getCustomerId(), claimedDevice.getCustomerId());
    claimResponse = doPostClaimAsync("/api/customer/device/" + deviceName + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest());
    assertEquals(claimResponse, ClaimResponse.CLAIMED);
}
Also used : ClaimResult(org.thingsboard.server.dao.device.claim.ClaimResult) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) ClaimRequest(org.thingsboard.server.common.data.ClaimRequest) ClaimResponse(org.thingsboard.server.dao.device.claim.ClaimResponse) Device(org.thingsboard.server.common.data.Device)

Example 3 with ClaimRequest

use of org.thingsboard.server.common.data.ClaimRequest in project thingsboard by thingsboard.

the class AbstractMqttClaimDeviceTest method validateClaimResponse.

protected void validateClaimResponse(boolean emptyPayload, MqttAsyncClient client, byte[] payloadBytes, byte[] failurePayloadBytes) throws Exception {
    client.publish(MqttTopics.DEVICE_CLAIM_TOPIC, new MqttMessage(failurePayloadBytes));
    loginUser(customerAdmin.getName(), CUSTOMER_USER_PASSWORD);
    ClaimRequest claimRequest;
    if (!emptyPayload) {
        claimRequest = new ClaimRequest("value");
    } else {
        claimRequest = new ClaimRequest(null);
    }
    ClaimResponse claimResponse = doExecuteWithRetriesAndInterval(() -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest()), 20, 100);
    assertEquals(claimResponse, ClaimResponse.FAILURE);
    client.publish(MqttTopics.DEVICE_CLAIM_TOPIC, new MqttMessage(payloadBytes));
    ClaimResult claimResult = doExecuteWithRetriesAndInterval(() -> doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResult.class, status().isOk()), 20, 100);
    assertEquals(claimResult.getResponse(), ClaimResponse.SUCCESS);
    Device claimedDevice = claimResult.getDevice();
    assertNotNull(claimedDevice);
    assertNotNull(claimedDevice.getCustomerId());
    assertEquals(customerAdmin.getCustomerId(), claimedDevice.getCustomerId());
    claimResponse = doPostClaimAsync("/api/customer/device/" + savedDevice.getName() + "/claim", claimRequest, ClaimResponse.class, status().isBadRequest());
    assertEquals(claimResponse, ClaimResponse.CLAIMED);
}
Also used : ClaimResult(org.thingsboard.server.dao.device.claim.ClaimResult) MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) ClaimRequest(org.thingsboard.server.common.data.ClaimRequest) ClaimResponse(org.thingsboard.server.dao.device.claim.ClaimResponse) Device(org.thingsboard.server.common.data.Device)

Aggregations

ClaimRequest (org.thingsboard.server.common.data.ClaimRequest)3 Device (org.thingsboard.server.common.data.Device)3 ClaimResponse (org.thingsboard.server.dao.device.claim.ClaimResponse)3 ClaimResult (org.thingsboard.server.dao.device.claim.ClaimResult)3 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)2