Browse Source

Save entity views without validation when the data update unassigns them from a customer

pull/16844/head
Viacheslav Klimov 3 weeks ago
parent
commit
dfd5b6f4c6
Failed to extract signature
  1. 2
      application/src/main/java/org/thingsboard/server/service/install/update/EntityViewGroupAllUpdater.java
  2. 35
      application/src/test/java/org/thingsboard/server/service/install/update/EntityViewGroupAllUpdaterTest.java

2
application/src/main/java/org/thingsboard/server/service/install/update/EntityViewGroupAllUpdater.java

@ -31,7 +31,7 @@ class EntityViewGroupAllUpdater extends EntityGroupAllPaginatedUpdater<EntityVie
@Override
protected void unassignFromCustomer(EntityView entity) {
entity.setCustomerId(new CustomerId(CustomerId.NULL_UUID));
entityViewService.saveEntityView(entity);
entityViewService.saveEntityView(entity, false);
}
@Override

35
application/src/test/java/org/thingsboard/server/service/install/update/EntityViewGroupAllUpdaterTest.java

@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: BUSL-1.1
package org.thingsboard.server.service.install.update;
import org.junit.jupiter.api.Test;
import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.group.EntityGroup;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.group.EntityGroupService;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
class EntityViewGroupAllUpdaterTest {
@Test
void testUnassignFromCustomerSavesWithoutValidation() {
EntityViewService entityViewService = mock(EntityViewService.class);
EntityViewGroupAllUpdater updater = new EntityViewGroupAllUpdater(entityViewService, mock(CustomerService.class),
mock(EntityGroupService.class), new EntityGroup(), true);
EntityView entityView = new EntityView();
entityView.setCustomerId(new CustomerId(UUID.randomUUID()));
updater.unassignFromCustomer(entityView);
verify(entityViewService).saveEntityView(entityView, false);
assertThat(entityView.getCustomerId().isNullUid()).isTrue();
}
}
Loading…
Cancel
Save