Refactor: remove unnecessary check tenant entity check
This commit is contained in:
parent
b2c4d8dd27
commit
e32f893fff
@ -66,7 +66,6 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
|
||||
|
||||
@Override
|
||||
public void onMsg(TbContext ctx, TbMsg msg) throws TbNodeException {
|
||||
ctx.checkTenantEntity(msg.getOriginator());
|
||||
var msgDataAsObjectNode = FetchTo.DATA.equals(fetchTo) ? getMsgDataAsObjectNode(msg) : null;
|
||||
withCallback(
|
||||
findEntityIdAsync(ctx, msg),
|
||||
|
||||
@ -40,7 +40,6 @@ public abstract class TbAbstractGetEntityAttrNode<T extends EntityId> extends Tb
|
||||
|
||||
@Override
|
||||
public void onMsg(TbContext ctx, TbMsg msg) {
|
||||
ctx.checkTenantEntity(msg.getOriginator());
|
||||
var msgDataAsObjectNode = FetchTo.DATA.equals(fetchTo) ? getMsgDataAsObjectNode(msg) : null;
|
||||
withCallback(findEntityAsync(ctx, msg.getOriginator()),
|
||||
entityId -> safeGetAttributes(ctx, msg, entityId, msgDataAsObjectNode),
|
||||
|
||||
@ -37,7 +37,6 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti
|
||||
|
||||
@Override
|
||||
public void onMsg(TbContext ctx, TbMsg msg) {
|
||||
ctx.checkTenantEntity(msg.getOriginator());
|
||||
var msgDataAsObjectNode = FetchTo.DATA.equals(fetchTo) ? getMsgDataAsObjectNode(msg) : null;
|
||||
withCallback(getDetails(ctx, msg, msgDataAsObjectNode),
|
||||
ctx::tellSuccess,
|
||||
|
||||
@ -55,7 +55,6 @@ public class TbFetchDeviceCredentialsNode extends TbAbstractNodeWithFetchTo<TbFe
|
||||
@Override
|
||||
public void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException {
|
||||
var originator = msg.getOriginator();
|
||||
ctx.checkTenantEntity(originator);
|
||||
var msgDataAsObjectNode = FetchTo.DATA.equals(fetchTo) ? getMsgDataAsObjectNode(msg) : null;
|
||||
if (!EntityType.DEVICE.equals(originator.getEntityType())) {
|
||||
ctx.tellFailure(msg, new RuntimeException("Unsupported originator type: " + originator.getEntityType() + "!"));
|
||||
|
||||
@ -58,7 +58,6 @@ public class TbGetOriginatorFieldsNode extends TbAbstractNodeWithFetchTo<TbGetOr
|
||||
|
||||
@Override
|
||||
public void onMsg(TbContext ctx, TbMsg msg) {
|
||||
ctx.checkTenantEntity(msg.getOriginator());
|
||||
var msgDataAsObjectNode = FetchTo.DATA.equals(fetchTo) ? getMsgDataAsObjectNode(msg) : null;
|
||||
withCallback(collectMappedEntityFieldsAsync(ctx, msg.getOriginator()),
|
||||
targetKeysToSourceValuesMap -> {
|
||||
|
||||
@ -69,7 +69,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -203,23 +202,6 @@ public class TbGetCustomerAttributeNodeTest {
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntityThatDoesNotBelongToTheCurrentTenant_whenOnMsg_thenException() {
|
||||
// GIVEN
|
||||
var expectedExceptionMessage = "Entity with id: '" + DUMMY_DEVICE_ORIGINATOR +
|
||||
"' specified in the configuration doesn't belong to the current tenant.";
|
||||
|
||||
doThrow(new RuntimeException(expectedExceptionMessage)).when(ctxMock).checkTenantEntity(DUMMY_DEVICE_ORIGINATOR);
|
||||
msg = TbMsg.newMsg("POST_TELEMETRY_REQUEST", DUMMY_DEVICE_ORIGINATOR, new TbMsgMetaData(), "{}");
|
||||
|
||||
// WHEN
|
||||
var exception = assertThrows(RuntimeException.class, () -> node.onMsg(ctxMock, msg));
|
||||
|
||||
// THEN
|
||||
assertThat(exception.getMessage()).isEqualTo(expectedExceptionMessage);
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDidNotFindEntity_whenOnMsg_thenShouldTellFailure() {
|
||||
// GIVEN
|
||||
|
||||
@ -64,7 +64,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -197,23 +196,6 @@ public class TbGetCustomerDetailsNodeTest {
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntityThatDoesNotBelongToTheCurrentTenant_whenOnMsg_thenException() {
|
||||
// GIVEN
|
||||
var expectedExceptionMessage = "Entity with id: '" + DUMMY_DEVICE_ORIGINATOR +
|
||||
"' specified in the configuration doesn't belong to the current tenant.";
|
||||
|
||||
doThrow(new RuntimeException(expectedExceptionMessage)).when(ctxMock).checkTenantEntity(DUMMY_DEVICE_ORIGINATOR);
|
||||
msg = TbMsg.newMsg("SOME_MESSAGE_TYPE", DUMMY_DEVICE_ORIGINATOR, new TbMsgMetaData(), "{}");
|
||||
|
||||
// WHEN
|
||||
var exception = assertThrows(RuntimeException.class, () -> node.onMsg(ctxMock, msg));
|
||||
|
||||
// THEN
|
||||
assertThat(exception.getMessage()).isEqualTo(expectedExceptionMessage);
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAllEntityDetailsAndFetchToData_whenOnMsg_thenShouldTellSuccessAndFetchAllToData() {
|
||||
// GIVEN
|
||||
|
||||
@ -46,7 +46,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -158,24 +157,6 @@ public class TbGetOriginatorFieldsNodeTest {
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntityThatDoesNotBelongToTheCurrentTenant_whenOnMsg_thenException() {
|
||||
// SETUP
|
||||
var expectedExceptionMessage = "Entity with id: '" + DUMMY_DEVICE_ORIGINATOR +
|
||||
"' specified in the configuration doesn't belong to the current tenant.";
|
||||
|
||||
// GIVEN
|
||||
doThrow(new RuntimeException(expectedExceptionMessage)).when(ctxMock).checkTenantEntity(DUMMY_DEVICE_ORIGINATOR);
|
||||
msg = TbMsg.newMsg("SOME_MESSAGE_TYPE", DUMMY_DEVICE_ORIGINATOR, new TbMsgMetaData(), "{}");
|
||||
|
||||
// WHEN
|
||||
var exception = assertThrows(RuntimeException.class, () -> node.onMsg(ctxMock, msg));
|
||||
|
||||
// THEN
|
||||
assertThat(exception.getMessage()).isEqualTo(expectedExceptionMessage);
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValidMsgAndFetchToData_whenOnMsg_thenShouldTellSuccessAndFetchToData() {
|
||||
// GIVEN
|
||||
|
||||
@ -74,7 +74,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -225,23 +224,6 @@ public class TbGetRelatedAttributeNodeTest {
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntityThatDoesNotBelongToTheCurrentTenant_whenOnMsg_thenException() {
|
||||
// GIVEN
|
||||
var expectedExceptionMessage = "Entity with id: '" + DUMMY_DEVICE_ORIGINATOR +
|
||||
"' specified in the configuration doesn't belong to the current tenant.";
|
||||
|
||||
doThrow(new RuntimeException(expectedExceptionMessage)).when(ctxMock).checkTenantEntity(DUMMY_DEVICE_ORIGINATOR);
|
||||
msg = TbMsg.newMsg("POST_TELEMETRY_REQUEST", DUMMY_DEVICE_ORIGINATOR, new TbMsgMetaData(), "{}");
|
||||
|
||||
// WHEN
|
||||
var exception = assertThrows(RuntimeException.class, () -> node.onMsg(ctxMock, msg));
|
||||
|
||||
// THEN
|
||||
assertThat(exception.getMessage()).isEqualTo(expectedExceptionMessage);
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDidNotFindEntity_whenOnMsg_thenShouldTellFailure() {
|
||||
// GIVEN
|
||||
|
||||
@ -57,7 +57,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -184,23 +183,6 @@ public class TbGetTenantAttributeNodeTest {
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntityThatDoesNotBelongToTheCurrentTenant_whenOnMsg_thenException() {
|
||||
// GIVEN
|
||||
var expectedExceptionMessage = "Entity with id: '" + DUMMY_DEVICE_ORIGINATOR +
|
||||
"' specified in the configuration doesn't belong to the current tenant.";
|
||||
|
||||
doThrow(new RuntimeException(expectedExceptionMessage)).when(ctxMock).checkTenantEntity(DUMMY_DEVICE_ORIGINATOR);
|
||||
msg = TbMsg.newMsg("POST_TELEMETRY_REQUEST", DUMMY_DEVICE_ORIGINATOR, new TbMsgMetaData(), "{}");
|
||||
|
||||
// WHEN
|
||||
var exception = assertThrows(RuntimeException.class, () -> node.onMsg(ctxMock, msg));
|
||||
|
||||
// THEN
|
||||
assertThat(exception.getMessage()).isEqualTo(expectedExceptionMessage);
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFetchAttributesToData_whenOnMsg_thenShouldFetchAttributesToData() {
|
||||
// GIVEN
|
||||
|
||||
@ -42,7 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@ -150,23 +149,6 @@ public class TbGetTenantDetailsNodeTest {
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEntityThatDoesNotBelongToTheCurrentTenant_whenOnMsg_thenException() {
|
||||
// GIVEN
|
||||
var expectedExceptionMessage = "Entity with id: '" + DUMMY_DEVICE_ORIGINATOR +
|
||||
"' specified in the configuration doesn't belong to the current tenant.";
|
||||
|
||||
doThrow(new RuntimeException(expectedExceptionMessage)).when(ctxMock).checkTenantEntity(DUMMY_DEVICE_ORIGINATOR);
|
||||
msg = TbMsg.newMsg("SOME_MESSAGE_TYPE", DUMMY_DEVICE_ORIGINATOR, new TbMsgMetaData(), "{}");
|
||||
|
||||
// WHEN
|
||||
var exception = assertThrows(RuntimeException.class, () -> node.onMsg(ctxMock, msg));
|
||||
|
||||
// THEN
|
||||
assertThat(exception.getMessage()).isEqualTo(expectedExceptionMessage);
|
||||
verify(ctxMock, never()).tellSuccess(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAllEntityDetailsAndFetchToData_whenOnMsg_thenShouldTellSuccessAndFetchAllToData() {
|
||||
// GIVEN
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user