Search in sources :

Example 1 with UserUpdateMsg

use of org.thingsboard.server.gen.edge.v1.UserUpdateMsg in project thingsboard by thingsboard.

the class BaseEdgeTest method testCustomerAndNewUser.

@Test
public void testCustomerAndNewUser() throws Exception {
    // 1
    edgeImitator.expectMessageAmount(1);
    Customer customer = new Customer();
    customer.setTitle("Edge Customer 1");
    Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
    doPost("/api/customer/" + savedCustomer.getUuidId() + "/edge/" + edge.getUuidId(), Edge.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof CustomerUpdateMsg);
    CustomerUpdateMsg customerUpdateMsg = (CustomerUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, customerUpdateMsg.getMsgType());
    Assert.assertEquals(customerUpdateMsg.getIdMSB(), savedCustomer.getUuidId().getMostSignificantBits());
    Assert.assertEquals(customerUpdateMsg.getIdLSB(), savedCustomer.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(customerUpdateMsg.getTitle(), savedCustomer.getTitle());
    testAutoGeneratedCodeByProtobuf(customerUpdateMsg);
    // 2
    edgeImitator.expectMessageAmount(1);
    User customerUser = new User();
    customerUser.setAuthority(Authority.CUSTOMER_USER);
    customerUser.setTenantId(savedTenant.getId());
    customerUser.setCustomerId(savedCustomer.getId());
    customerUser.setEmail("customerUser@thingsboard.org");
    customerUser.setFirstName("John");
    customerUser.setLastName("Edwards");
    User savedUser = doPost("/api/user", customerUser, User.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof UserUpdateMsg);
    UserUpdateMsg userUpdateMsg = (UserUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, userUpdateMsg.getMsgType());
    Assert.assertEquals(userUpdateMsg.getIdMSB(), savedUser.getUuidId().getMostSignificantBits());
    Assert.assertEquals(userUpdateMsg.getIdLSB(), savedUser.getUuidId().getLeastSignificantBits());
    Assert.assertEquals(userUpdateMsg.getEmail(), savedUser.getEmail());
    testAutoGeneratedCodeByProtobuf(userUpdateMsg);
    // 3
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/customer/edge/" + edge.getUuidId(), Edge.class);
    Assert.assertTrue(edgeImitator.waitForMessages());
    latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof CustomerUpdateMsg);
    customerUpdateMsg = (CustomerUpdateMsg) latestMessage;
    Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, customerUpdateMsg.getMsgType());
    Assert.assertEquals(customerUpdateMsg.getIdMSB(), savedCustomer.getUuidId().getMostSignificantBits());
    Assert.assertEquals(customerUpdateMsg.getIdLSB(), savedCustomer.getUuidId().getLeastSignificantBits());
    edgeImitator.expectMessageAmount(1);
    doDelete("/api/customer/" + savedCustomer.getUuidId()).andExpect(status().isOk());
    Assert.assertFalse(edgeImitator.waitForMessages(1));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) User(org.thingsboard.server.common.data.User) Customer(org.thingsboard.server.common.data.Customer) UserUpdateMsg(org.thingsboard.server.gen.edge.v1.UserUpdateMsg) CustomerUpdateMsg(org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

AbstractMessage (com.google.protobuf.AbstractMessage)1 Test (org.junit.Test)1 Customer (org.thingsboard.server.common.data.Customer)1 User (org.thingsboard.server.common.data.User)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 CustomerUpdateMsg (org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg)1 UserUpdateMsg (org.thingsboard.server.gen.edge.v1.UserUpdateMsg)1