@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.extension.ExtendWith ;
import org.mockito.ArgumentCaptor ;
import org.mockito.InOrder ;
import org.mockito.InjectMocks ;
import org.mockito.Mock ;
import org.mockito.junit.jupiter.MockitoExtension ;
@ -16,12 +17,17 @@ import org.mockito.quality.Strictness;
import org.springframework.test.util.ReflectionTestUtils ;
import org.springframework.transaction.support.TransactionCallback ;
import org.springframework.transaction.support.TransactionTemplate ;
import org.springframework.web.client.RestClientException ;
import org.thingsboard.common.util.JacksonUtil ;
import org.thingsboard.server.common.data.Customer ;
import org.thingsboard.server.common.data.Dashboard ;
import org.thingsboard.server.common.data.Device ;
import org.thingsboard.server.common.data.DeviceProfile ;
import org.thingsboard.server.common.data.EntityType ;
import org.thingsboard.server.common.data.HasName ;
import org.thingsboard.server.common.data.User ;
import org.thingsboard.server.common.data.AttributeScope ;
import org.thingsboard.server.common.data.audit.ActionType ;
import org.thingsboard.server.common.data.converter.Converter ;
import org.thingsboard.server.common.data.debug.DebugSettings ;
import org.thingsboard.server.common.data.exception.EntityVersionMismatchException ;
@ -30,23 +36,29 @@ import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DashboardId ;
import org.thingsboard.server.common.data.id.DeviceId ;
import org.thingsboard.server.common.data.id.DeviceProfileId ;
import org.thingsboard.server.common.data.id.EntityGroupId ;
import org.thingsboard.server.common.data.id.EntityId ;
import org.thingsboard.server.common.data.id.IntegrationId ;
import org.thingsboard.server.common.data.id.IotHubInstalledItemId ;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.common.data.id.UserId ;
import org.thingsboard.server.common.data.group.EntityGroup ;
import org.thingsboard.server.common.data.integration.Integration ;
import org.thingsboard.server.common.data.page.PageData ;
import org.thingsboard.server.common.data.security.DeviceCredentials ;
import org.thingsboard.server.common.data.subscription.SubscriptionErrorCode ;
import org.thingsboard.server.common.data.subscription.SubscriptionException ;
import org.thingsboard.rule.engine.api.AttributesSaveRequest ;
import org.thingsboard.server.common.data.iot_hub.DeviceInstalledItemDescriptor ;
import org.thingsboard.server.common.data.iot_hub.IotHubInstalledItem ;
import org.thingsboard.server.dao.converter.ConverterService ;
import org.thingsboard.server.dao.customer.CustomerService ;
import org.thingsboard.server.dao.dashboard.DashboardService ;
import org.thingsboard.server.dao.device.DeviceCredentialsService ;
import org.thingsboard.server.dao.device.DeviceProfileService ;
import org.thingsboard.server.dao.device.DeviceService ;
import org.thingsboard.server.dao.entity.EntityService ;
import org.thingsboard.server.dao.group.EntityGroupService ;
import org.thingsboard.server.dao.integration.IntegrationService ;
import org.thingsboard.server.dao.iot_hub.IotHubInstalledItemService ;
import org.thingsboard.server.dao.subscription.PlatformFeature ;
@ -54,6 +66,7 @@ import org.thingsboard.server.dao.subscription.SubscriptionService;
import org.thingsboard.server.exception.DataValidationException ;
import org.thingsboard.server.service.entitiy.TbLogEntityActionService ;
import org.thingsboard.server.service.entitiy.integration.TbIntegrationService ;
import org.thingsboard.server.service.install.ProjectInfo ;
import org.thingsboard.server.service.security.model.SecurityUser ;
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService ;
@ -62,20 +75,25 @@ import java.util.List;
import java.util.Map ;
import java.util.Optional ;
import java.util.UUID ;
import java.util.concurrent.ExecutionException ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.mockito.ArgumentMatchers.any ;
import static org.mockito.Mockito.mock ;
import static org.mockito.ArgumentMatchers.eq ;
import static org.mockito.ArgumentMatchers.nullable ;
import static org.mockito.Mockito.doAnswer ;
import static org.mockito.Mockito.doThrow ;
import static org.mockito.Mockito.inOrder ;
import static org.mockito.Mockito.never ;
import static org.mockito.Mockito.times ;
import static org.mockito.Mockito.verify ;
import static org.mockito.Mockito.verifyNoInteractions ;
import static org.mockito.Mockito.when ;
@ExtendWith ( MockitoExtension . class )
@MockitoSettings ( strictness = Strictness . LENIENT )
class DefaultDevicePackageUpdate ServiceTest {
class DefaultDevicePackageServiceTest {
private final TenantId tenantId = TenantId . fromUUID ( UUID . randomUUID ( ) ) ;
private final SecurityUser user = mock ( SecurityUser . class ) ;
@ -119,18 +137,30 @@ class DefaultDevicePackageUpdateServiceTest {
private TelemetrySubscriptionService telemetryService ;
@Mock
private IotHubService iotHubService ;
@Mock
private ProjectInfo projectInfo ;
@Mock
private CustomerService customerService ;
@Mock
private EntityGroupService entityGroupService ;
@InjectMocks
private DefaultDevicePackageUpdateService service ;
private DefaultDevicePackageService service ;
private IotHubInstalledItem installedItem ;
// Set when the transaction callback threw, so the transaction would roll back
private final List < RuntimeException > rolledBack = new ArrayList < > ( ) ;
private boolean inTransaction ;
private final List < String > savedInTransaction = new ArrayList < > ( ) ;
// What must run after commit: the audit log, the Hub install report and the attributes, each marked if it ran inside
private final List < String > afterCommitCalls = new ArrayList < > ( ) ;
@BeforeEach
void setUp ( ) {
ReflectionTestUtils . setField ( service , "entityService" , entityService ) ;
ReflectionTestUtils . setField ( service , "logEntityActionService" , logEntityActionService ) ;
ReflectionTestUtils . setField ( service , "customerService" , customerService ) ;
ReflectionTestUtils . setField ( service , "entityGroupService" , entityGroupService ) ;
when ( user . getTenantId ( ) ) . thenReturn ( tenantId ) ;
DeviceInstalledItemDescriptor descriptor = new DeviceInstalledItemDescriptor ( ) ;
@ -158,11 +188,14 @@ class DefaultDevicePackageUpdateServiceTest {
when ( iotHubRestClient . getVersionInfo ( versionId ) ) . thenReturn ( versionInfo ) ;
when ( transactionTemplate . execute ( any ( ) ) ) . thenAnswer ( invocation - > {
inTransaction = true ;
try {
return invocation . < TransactionCallback < ? > > getArgument ( 0 ) . doInTransaction ( null ) ;
} catch ( RuntimeException e ) {
rolledBack . add ( e ) ;
throw e ;
} finally {
inTransaction = false ;
}
} ) ;
when ( packageEntities . checksum ( any ( ) , any ( ) ) ) . thenReturn ( "checksum" ) ;
@ -184,7 +217,7 @@ class DefaultDevicePackageUpdateServiceTest {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ) ;
when ( dashboardService . saveDashboard ( any ( Dashboard . class ) ) ) . thenAnswer ( i - > i . getArgument ( 0 ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
overwrite ( "AM308 profile" , "DEVICE_PROFILE" , profileId , 3L , JacksonUtil . newObjectNode ( ) . put ( "name" , "milesight-iot-am308" ) . put ( "description" , "new" ) ) ,
keep ( "AM308" , "DEVICE" , deviceId ) ,
overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "Template title" ) ) ) ) ;
@ -218,10 +251,10 @@ class DefaultDevicePackageUpdateServiceTest {
dashboardState . set ( "entityOutput" , JacksonUtil . newObjectNode ( ) . put ( "id" , dashboardId . getId ( ) . toString ( ) ) ) ;
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( "Dashboard" , dashboardState ) ) ;
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eRequest request = request ( keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ;
DevicePackag eRequest request = request ( keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ;
request . setSelectedInstallMethod ( "INTEGRATION_CHIRPSTACK" ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -237,10 +270,10 @@ class DefaultDevicePackageUpdateServiceTest {
dashboardState . set ( "entityOutput" , JacksonUtil . newObjectNode ( ) . put ( "id" , dashboardId . getId ( ) . toString ( ) ) ) ;
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( "Dashboard" , dashboardState ) ) ;
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eRequest . Step overview = keep ( "Overview" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step overview = keep ( "Overview" , "DASHBOARD" , dashboardId ) ;
overview . setId ( "main-dashboard" ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( overview ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( overview ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -256,7 +289,7 @@ class DefaultDevicePackageUpdateServiceTest {
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( "Dashboard" , dashboardState ) ) ;
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -266,10 +299,10 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void useExistingOfAPackageEntity_staysThePackages ( ) {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eRequest . Step step = keep ( "Overview" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step step = keep ( "Overview" , "DASHBOARD" , dashboardId ) ;
step . setResolution ( "use-existing" ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -282,10 +315,10 @@ class DefaultDevicePackageUpdateServiceTest {
// At install the user picked their own dashboard: the install adds it to createdEntityIds too
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( "Dashboard" , stateOf ( dashboardId , "use-existing" ) ) ) ;
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eRequest . Step step = keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step step = keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ;
step . setResolution ( "use-existing" ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -295,9 +328,9 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void overwritingAnEntityUsedAtInstall_needsAConfirmation ( ) {
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( "Dashboard" , stateOf ( dashboardId , "use-existing" ) ) ) ;
DeviceUpdat eRequest . Step step = overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 9L , JacksonUtil . newObjectNode ( ) . put ( "title" , "Dashboard" ) ) ;
DevicePackag eRequest . Step step = overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 9L , JacksonUtil . newObjectNode ( ) . put ( "title" , "Dashboard" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
@ -308,7 +341,7 @@ class DefaultDevicePackageUpdateServiceTest {
Dashboard shared = dashboard ( 9L ) ;
DevicePackageEntities . Snapshot snapshot = new DevicePackageEntities . Snapshot ( shared , null ) ;
when ( packageEntities . load ( tenantId , dashboardId ) ) . thenReturn ( snapshot ) ;
when ( iotHubService . findKeptEntities ( tenantId , installedItem . getId ( ) ) ) . thenReturn ( new InstalledItemKeptEntities ( List . of ( ) , 0 , 0 ) ) ;
when ( iotHubService . findKeptEntities ( tenantId , installedItem . getId ( ) ) ) . thenReturn ( new InstalledItemKeptEntities ( List . of ( ) , 0 , 0 , List . of ( ) ) ) ;
// This package recorded the dashboard as it left it; the other one overwrote it since and recorded the new one
ObjectNode own = stateOf ( dashboardId , "created" ) . put ( "checksum" , "as-this-package-left-it" ) ;
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( "Dashboard" , own ) ) ;
@ -327,10 +360,10 @@ class DefaultDevicePackageUpdateServiceTest {
// v2 dropped the dashboard step: the install state no longer has it, createdEntityIds does
( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . setInstallState ( Map . of ( ) ) ;
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eRequest . Step step = keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step step = keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ;
step . setResolution ( "use-existing" ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -343,9 +376,9 @@ class DefaultDevicePackageUpdateServiceTest {
DeviceInstalledItemDescriptor installed = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
installed . setUsedExistingEntityIds ( List . of ( dashboardId ) ) ;
installed . setInstallState ( Map . of ( ) ) ;
DeviceUpdat eRequest . Step step = overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 9L , JacksonUtil . newObjectNode ( ) . put ( "title" , "Dashboard" ) ) ;
DevicePackag eRequest . Step step = overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 9L , JacksonUtil . newObjectNode ( ) . put ( "title" , "Dashboard" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
@ -358,7 +391,7 @@ class DefaultDevicePackageUpdateServiceTest {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
when ( entityService . fetchEntity ( any ( ) , any ( ) ) ) . thenReturn ( Optional . of ( dashboard ( 9L ) ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
assertThat ( ( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . getUsedExistingEntityIds ( ) ) . containsExactly ( dashboardId ) ;
@ -377,13 +410,13 @@ class DefaultDevicePackageUpdateServiceTest {
current . setConfiguration ( configuration ) ;
when ( integrationService . findIntegrationById ( tenantId , integrationId ) ) . thenReturn ( current ) ;
when ( integrationService . saveIntegration ( any ( ) ) ) . thenAnswer ( i - > i . getArgument ( 0 ) ) ;
DeviceUpdat eRequest . Step step = keep ( "TTN" , "INTEGRATION" , integrationId ) ;
DevicePackag eRequest . Step step = keep ( "TTN" , "INTEGRATION" , integrationId ) ;
step . setResolution ( "use-existing" ) ;
ObjectNode entries = JacksonUtil . newObjectNode ( ) . put ( "profile.lansitec-badge" , "Badge" ) ;
entries . putNull ( "profile.milesight-iot-am308" ) ;
step . setMetadata ( entries ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
ArgumentCaptor < Integration > saved = ArgumentCaptor . forClass ( Integration . class ) ;
@ -411,7 +444,7 @@ class DefaultDevicePackageUpdateServiceTest {
integration . setId ( integrationId ) ;
when ( entityService . fetchEntity ( tenantId , integrationId ) ) . thenReturn ( Optional . of ( integration ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -438,11 +471,11 @@ class DefaultDevicePackageUpdateServiceTest {
current . setConfiguration ( configuration ) ;
when ( integrationService . findIntegrationById ( tenantId , tenantsIntegrationId ) ) . thenReturn ( current ) ;
when ( integrationService . saveIntegration ( any ( ) ) ) . thenAnswer ( i - > i . getArgument ( 0 ) ) ;
DeviceUpdat eRequest . Step step = keep ( "TTN" , "INTEGRATION" , tenantsIntegrationId ) ;
DevicePackag eRequest . Step step = keep ( "TTN" , "INTEGRATION" , tenantsIntegrationId ) ;
step . setResolution ( "use-existing" ) ;
step . setMetadata ( JacksonUtil . newObjectNode ( ) . put ( "profile.milesight-iot-am308" , "AM308" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ;
@ -465,10 +498,10 @@ class DefaultDevicePackageUpdateServiceTest {
configuration . set ( "metadata" , JacksonUtil . newObjectNode ( ) . put ( "profile.lansitec-badge" , "Badge" ) ) ;
current . setConfiguration ( configuration ) ;
when ( integrationService . findIntegrationById ( tenantId , integrationId ) ) . thenReturn ( current ) ;
DeviceUpdat eRequest . Step step = keep ( "TTN" , "INTEGRATION" , integrationId ) ;
DevicePackag eRequest . Step step = keep ( "TTN" , "INTEGRATION" , integrationId ) ;
step . setMetadata ( JacksonUtil . newObjectNode ( ) . put ( "profile.lansitec-badge" , "Badge" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
verify ( integrationService , never ( ) ) . saveIntegration ( any ( ) ) ;
@ -476,12 +509,12 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void twoStepsWithOneKey_areRejected ( ) {
DeviceUpdat eRequest . Step first = keep ( "Overview" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step first = keep ( "Overview" , "DASHBOARD" , dashboardId ) ;
first . setId ( "main-dashboard" ) ;
DeviceUpdat eRequest . Step second = keep ( "Details" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step second = keep ( "Details" , "DASHBOARD" , dashboardId ) ;
second . setId ( "main-dashboard" ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( first , second ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( first , second ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
@ -489,25 +522,25 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void twoStepsOfOneTypeAndName_areRejected ( ) {
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
keep ( "Dashboard" , "DASHBOARD" , dashboardId ) , keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Duplicate update step: DASHBOARD:Dashboard" ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Duplicate step: DASHBOARD:Dashboard" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
}
@Test
void stepWithTheKeyOfAForm_isRejected ( ) {
DeviceUpdat eRequest . Step step = keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ;
DevicePackag eRequest . Step step = keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ;
step . setId ( "Settings" ) ;
DeviceUpdat eRequest request = request ( step ) ;
DevicePackag eRequest request = request ( step ) ;
request . setInstallState ( Map . of ( "Settings" , JacksonUtil . newObjectNode ( ) . set ( "formValues" , JacksonUtil . newObjectNode ( ) . put ( "interval" , 10 ) ) ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Duplicate update step: Settings" ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Duplicate step: Settings" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
}
@ -532,14 +565,14 @@ class DefaultDevicePackageUpdateServiceTest {
legacy . set ( "metadata" , JacksonUtil . newObjectNode ( ) . put ( "profile.milesight-iot-am308" , "AM308" ) ) ;
installed . setInstallState ( Map . of ( "${integrationName}" , legacy , "${profileName}" , stateOf ( profileId , "created" ) ,
"Configuration" , JacksonUtil . newObjectNode ( ) . set ( "formValues" , JacksonUtil . newObjectNode ( ) . put ( "integrationName" , "TTN my-app" ) ) ) ) ;
DeviceUpdat eRequest . Step uplink = keep ( "${integrationName}" , "UPLINK_CONVERTER" , converterId ) ;
DevicePackag eRequest . Step uplink = keep ( "${integrationName}" , "UPLINK_CONVERTER" , converterId ) ;
uplink . setDefaultConverter ( true ) ;
DeviceUpdat eRequest . Step ttn = keep ( "${integrationName}" , "INTEGRATION" , integrationId ) ;
DevicePackag eRequest . Step ttn = keep ( "${integrationName}" , "INTEGRATION" , integrationId ) ;
ttn . setMetadata ( JacksonUtil . newObjectNode ( ) . put ( "profile.milesight-iot-am308" , "AM308" ) ) ;
DeviceUpdat eRequest request = request ( uplink , ttn ) ;
DevicePackag eRequest request = request ( uplink , ttn ) ;
request . setInstallState ( Map . of ( "Configuration" , installed . getInstallState ( ) . get ( "Configuration" ) ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
Map < String , JsonNode > state = ( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . getInstallState ( ) ;
@ -563,7 +596,7 @@ class DefaultDevicePackageUpdateServiceTest {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 7L ) ) ;
when ( dashboardService . saveDashboard ( any ( Dashboard . class ) ) ) . thenThrow ( new DataValidationException ( "Dashboards limit reached" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
overwrite ( "AM308 profile" , "DEVICE_PROFILE" , profileId , 3L , JacksonUtil . newObjectNode ( ) . put ( "name" , "p" ) ) ,
overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ) ;
@ -580,12 +613,12 @@ class DefaultDevicePackageUpdateServiceTest {
void entityChangedSinceTheCheck_isAVersionConflict ( ) {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 8L ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getFailedStep ( ) ) . isEqualTo ( "DASHBOARD:Dashboard" ) ;
assertThat ( result . getErrorMessage ( ) ) . contains ( "Check the updat e again" ) ;
assertThat ( result . getErrorMessage ( ) ) . contains ( "Check the packag e again" ) ;
verify ( dashboardService , never ( ) ) . saveDashboard ( any ( Dashboard . class ) ) ;
}
@ -608,7 +641,7 @@ class DefaultDevicePackageUpdateServiceTest {
ObjectNode integration = JacksonUtil . newObjectNode ( ) . put ( "name" , "Template name" ) . put ( "type" , "TTN" ) . put ( "edgeTemplate" , true ) ;
integration . set ( "defaultConverterId" , JacksonUtil . newObjectNode ( ) . put ( "entityType" , "CONVERTER" ) . put ( "id" , "${uplinkConverter.id}" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
create ( "Uplink" , "UPLINK_CONVERTER" , JacksonUtil . newObjectNode ( ) . put ( "name" , "Uplink for TTN" ) ) ,
overwrite ( "TTN" , "INTEGRATION" , integrationId , 2L , integration ) ) ) ;
@ -640,12 +673,12 @@ class DefaultDevicePackageUpdateServiceTest {
IotHubInstalledItem taker = otherPackage ( Map . of ( "Uplink" , usedExisting ) ) ;
when ( installedItemService . findByTenantId ( any ( ) , any ( ) , any ( ) , any ( ) ) )
. thenReturn ( new PageData < > ( List . of ( installedItem , creator , taker ) , 1 , 3 , false ) ) ;
DeviceUpdat eRequest . Step step = overwrite ( "Uplink" , "UPLINK_CONVERTER" , converterId , 4L ,
DevicePackag eRequest . Step step = overwrite ( "Uplink" , "UPLINK_CONVERTER" , converterId , 4L ,
JacksonUtil . newObjectNode ( ) . put ( "name" , "Uplink" ) . set ( "configuration" , JacksonUtil . newObjectNode ( ) . put ( "tbelDecoder" , "return {};" ) ) ) ;
step . setConfirmed ( true ) ;
step . setDefaultConverter ( true ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
JsonNode state = ( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . getInstallState ( ) . get ( "UPLINK_CONVERTER:Uplink" ) ;
@ -672,14 +705,14 @@ class DefaultDevicePackageUpdateServiceTest {
ObjectNode versionInfo = JacksonUtil . newObjectNode ( ) . put ( "itemId" , itemId . toString ( ) ) . put ( "name" , "AM308" ) . put ( "version" , "1.0.0" ) ;
when ( iotHubRestClient . getVersionInfo ( installedVersionId . toString ( ) ) ) . thenReturn ( versionInfo ) ;
// ThingsBoard's default converter changed: only the converter step is sent
DeviceUpdat eRequest . Step step = overwrite ( "Uplink data converter" , "UPLINK_CONVERTER" , converterId , 4L ,
DevicePackag eRequest . Step step = overwrite ( "Uplink data converter" , "UPLINK_CONVERTER" , converterId , 4L ,
JacksonUtil . newObjectNode ( ) . put ( "name" , "Uplink" ) . set ( "configuration" , JacksonUtil . newObjectNode ( ) . put ( "tbelDecoder" , "return {};" ) ) ) ;
step . setId ( "uplink" ) ;
step . setDefaultConverter ( true ) ;
DeviceUpdat eRequest request = request ( step ) ;
DevicePackag eRequest request = request ( step ) ;
request . setVersionId ( installedVersionId . toString ( ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
Map < String , JsonNode > state = ( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . getInstallState ( ) ;
@ -697,7 +730,7 @@ class DefaultDevicePackageUpdateServiceTest {
void updateToAnotherVersion_dropsTheInstallStateOfTheStepsItLeavesOut ( ) {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 9L ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "Dashboard" , "DASHBOARD" , dashboardId ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
assertThat ( ( ( DeviceInstalledItemDescriptor ) installedItem . getDescriptor ( ) ) . getInstallState ( ) ) . containsOnlyKeys ( "DASHBOARD:Dashboard" ) ;
@ -707,7 +740,7 @@ class DefaultDevicePackageUpdateServiceTest {
void overwritingAnEntityOfAnotherPackage_needsAConfirmation ( ) {
DashboardId foreign = new DashboardId ( UUID . randomUUID ( ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
overwrite ( "Dashboard" , "DASHBOARD" , foreign , 1L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
@ -716,7 +749,7 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void theDeviceIsNeverOverwritten ( ) {
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
overwrite ( "AM308" , "DEVICE" , deviceId , 1L , JacksonUtil . newObjectNode ( ) . put ( "name" , "d" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
@ -729,7 +762,7 @@ class DefaultDevicePackageUpdateServiceTest {
ObjectNode other = JacksonUtil . newObjectNode ( ) . put ( "itemId" , UUID . randomUUID ( ) . toString ( ) ) ;
when ( iotHubRestClient . getVersionInfo ( versionId ) ) . thenReturn ( other ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
@ -743,7 +776,7 @@ class DefaultDevicePackageUpdateServiceTest {
updated . setItemVersionId ( UUID . fromString ( versionId ) ) ;
when ( installedItemService . findByIdForUpdate ( tenantId , installedItem . getId ( ) ) ) . thenReturn ( updated ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
create ( "Uplink" , "UPLINK_CONVERTER" , JacksonUtil . newObjectNode ( ) . put ( "name" , "Uplink for TTN" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
@ -754,10 +787,10 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void planOfAnotherInstalledVersion_isRejected ( ) {
DeviceUpdat eRequest request = request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ;
DevicePackag eRequest request = request ( keep ( "AM308" , "DEVICE" , deviceId ) ) ;
request . setFromVersionId ( UUID . randomUUID ( ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
@ -768,7 +801,7 @@ class DefaultDevicePackageUpdateServiceTest {
doThrow ( new SubscriptionException ( "Integrations feature is disabled!" , SubscriptionErrorCode . FEATURE_DISABLED ) )
. when ( subscriptionService ) . checkFeatureAllowed ( tenantId , PlatformFeature . INTEGRATIONS ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request (
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request (
create ( "Uplink" , "UPLINK_CONVERTER" , JacksonUtil . newObjectNode ( ) . put ( "name" , "Uplink for TTN" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
@ -780,10 +813,10 @@ class DefaultDevicePackageUpdateServiceTest {
void attributesOfAnOverwrittenEntity_areSavedAfterCommit ( ) {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 7L ) ) ;
when ( dashboardService . saveDashboard ( any ( Dashboard . class ) ) ) . thenAnswer ( i - > i . getArgument ( 0 ) ) ;
DeviceUpdat eRequest . Step step = overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ;
DevicePackag eRequest . Step step = overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ;
step . setServerAttributes ( JacksonUtil . newObjectNode ( ) . put ( "deviceId" , "${device.id}" ) ) ;
DeviceUpdat eResult result = service . apply ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) , step ) ) ;
DevicePackag eResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) , step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
ArgumentCaptor < AttributesSaveRequest > saved = ArgumentCaptor . forClass ( AttributesSaveRequest . class ) ;
@ -829,12 +862,12 @@ class DefaultDevicePackageUpdateServiceTest {
@Test
void userMessage_showsValidationMessagesAndHidesInternalOnes ( ) {
assertThat ( DefaultDevicePackageUpdate Service . userMessage ( new DataValidationException ( "Rule chains limit reached" ) ) )
assertThat ( DefaultDevicePackageService . userMessage ( new DataValidationException ( "Rule chains limit reached" ) ) )
. isEqualTo ( "Rule chains limit reached" ) ;
assertThat ( DefaultDevicePackageUpdate Service . userMessage ( new EntityVersionMismatchException ( EntityType . DASHBOARD , null ) ) )
. contains ( "Check the updat e again" ) ;
assertThat ( DefaultDevicePackageUpdate Service . userMessage ( new IllegalStateException ( "could not execute statement; SQL [n/a]" ) ) )
. isEqualTo ( "Failed to updat e the device package" ) ;
assertThat ( DefaultDevicePackageService . userMessage ( new EntityVersionMismatchException ( EntityType . DASHBOARD , null ) ) )
. contains ( "Check the packag e again" ) ;
assertThat ( DefaultDevicePackageService . userMessage ( new IllegalStateException ( "could not execute statement; SQL [n/a]" ) ) )
. isEqualTo ( "Failed to sav e the device package" ) ;
}
@Test
@ -842,12 +875,431 @@ class DefaultDevicePackageUpdateServiceTest {
ObjectNode device = JacksonUtil . newObjectNode ( ) . put ( "id" , "123" ) ;
ObjectNode node = JacksonUtil . newObjectNode ( ) . put ( "a" , "${device.id}" ) . put ( "b" , "x ${device.id} ${gateway.id}" ) ;
ObjectNode resolved = ( ObjectNode ) DefaultDevicePackageUpdate Service . resolvePlaceholders ( node , Map . of ( "device" , device ) ) ;
ObjectNode resolved = ( ObjectNode ) DefaultDevicePackageService . resolvePlaceholders ( node , Map . of ( "device" , device ) ) ;
assertThat ( resolved . get ( "a" ) . asText ( ) ) . isEqualTo ( "123" ) ;
assertThat ( resolved . get ( "b" ) . asText ( ) ) . isEqualTo ( "x 123 ${gateway.id}" ) ;
}
@Test
void installSavesTheEntitiesAndTheInstalledItemInOneTransaction ( ) {
mockInstall ( ) ;
DevicePackageRequest . Step integrationStep = keep ( "TTN" , "INTEGRATION" , integrationId ) ;
integrationStep . setResolution ( "use-existing" ) ;
DevicePackageResult result = service . install ( user , request (
create ( "AM308 profile" , "DEVICE_PROFILE" , JacksonUtil . newObjectNode ( ) . put ( "name" , "milesight-iot-am308" ) ) ,
integrationStep ,
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
verify ( transactionTemplate ) . execute ( any ( ) ) ;
assertThat ( savedInTransaction ) . containsExactly ( "DEVICE_PROFILE" , "DASHBOARD" , "INSTALLED_ITEM" ) ;
ArgumentCaptor < IotHubInstalledItem > saved = ArgumentCaptor . forClass ( IotHubInstalledItem . class ) ;
verify ( installedItemService ) . save ( eq ( tenantId ) , saved . capture ( ) ) ;
IotHubInstalledItem item = saved . getValue ( ) ;
assertThat ( item . getTenantId ( ) ) . isEqualTo ( tenantId ) ;
assertThat ( item . getItemId ( ) ) . isEqualTo ( itemId ) ;
assertThat ( item . getItemVersionId ( ) ) . isEqualTo ( UUID . fromString ( versionId ) ) ;
assertThat ( item . getVersion ( ) ) . isEqualTo ( "1.0.1" ) ;
assertThat ( item . getItemName ( ) ) . isEqualTo ( "AM308" ) ;
assertThat ( item . getItemType ( ) ) . isEqualTo ( "DEVICE" ) ;
DeviceInstalledItemDescriptor descriptor = ( DeviceInstalledItemDescriptor ) item . getDescriptor ( ) ;
assertThat ( descriptor . getCreatedEntityIds ( ) ) . containsExactly ( profileId , integrationId , dashboardId ) ;
assertThat ( descriptor . getUsedExistingEntityIds ( ) ) . containsExactly ( integrationId ) ;
assertThat ( descriptor . getDashboardId ( ) ) . isEqualTo ( dashboardId ) ;
Map < String , JsonNode > state = descriptor . getInstallState ( ) ;
assertThat ( state . get ( "DEVICE_PROFILE:AM308 profile" ) . get ( "entityOutput" ) . get ( "id" ) . asText ( ) ) . isEqualTo ( profileId . getId ( ) . toString ( ) ) ;
assertThat ( state . get ( "DEVICE_PROFILE:AM308 profile" ) . get ( "checksum" ) . isTextual ( ) ) . isTrue ( ) ;
assertThat ( state . get ( "DASHBOARD:Dashboard" ) . get ( "entityOutput" ) . get ( "id" ) . asText ( ) ) . isEqualTo ( dashboardId . getId ( ) . toString ( ) ) ;
assertThat ( state . get ( "DASHBOARD:Dashboard" ) . get ( "checksum" ) . isTextual ( ) ) . isTrue ( ) ;
assertThat ( state . get ( "INTEGRATION:TTN" ) . get ( "entityOutput" ) . get ( "id" ) . asText ( ) ) . isEqualTo ( integrationId . getId ( ) . toString ( ) ) ;
assertThat ( state . get ( "INTEGRATION:TTN" ) . get ( "resolution" ) . asText ( ) ) . isEqualTo ( "use-existing" ) ;
assertThat ( result . getDescriptor ( ) ) . isSameAs ( descriptor ) ;
assertThat ( result . getOutputs ( ) ) . containsOnlyKeys ( "DEVICE_PROFILE:AM308 profile" , "INTEGRATION:TTN" , "DASHBOARD:Dashboard" ) ;
assertThat ( afterCommitCalls ) . containsExactly ( "AUDIT" , "AUDIT" , "REPORT" ) ;
}
@Test
void installFailureOnALaterStepSavesNothing ( ) {
mockInstall ( ) ;
when ( dashboardService . saveDashboard ( any ( Dashboard . class ) ) ) . thenThrow ( new DataValidationException ( "Dashboards limit reached" ) ) ;
DevicePackageResult result = service . install ( user , request (
create ( "AM308 profile" , "DEVICE_PROFILE" , JacksonUtil . newObjectNode ( ) . put ( "name" , "milesight-iot-am308" ) ) ,
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getFailedStep ( ) ) . isEqualTo ( "DASHBOARD:Dashboard" ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Dashboards limit reached" ) ;
assertThat ( rolledBack ) . hasSize ( 1 ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
verifyNoInteractions ( logEntityActionService , telemetryService ) ;
verify ( iotHubRestClient , never ( ) ) . reportVersionInstalled ( any ( ) , any ( ) ) ;
}
@Test
void installOverwriteOfAnExistingEntityNeedsAConfirmation ( ) {
mockInstall ( ) ;
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 7L ) ) ;
DevicePackageResult result = service . install ( user , request (
overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Overwriting an entity of another package needs a confirmation: Dashboard" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( dashboardService , never ( ) ) . saveDashboard ( any ( Dashboard . class ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void installWithBadIntegrationCredentialsSavesNothing ( ) throws Exception {
mockInstall ( ) ;
doThrow ( new ExecutionException ( new IllegalStateException ( "Wrong API key" ) ) )
. when ( tbIntegrationService ) . validateIntegrationConfiguration ( eq ( tenantId ) , any ( ) ) ;
DevicePackageResult result = service . install ( user , request (
create ( "TTN" , "INTEGRATION" , JacksonUtil . newObjectNode ( ) . put ( "name" , "TTN" ) . put ( "type" , "TTN" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getFailedStep ( ) ) . isEqualTo ( "INTEGRATION:TTN" ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Wrong API key" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void installWhenHubIsUnavailableSavesNothing ( ) {
mockInstall ( ) ;
when ( iotHubRestClient . getVersionInfo ( versionId ) ) . thenThrow ( new RestClientException ( "Connection refused" ) ) ;
DevicePackageResult result = service . install ( user , request (
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "IoT Hub is unavailable. Try again later." ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void installReportsToTheHubAfterCommitAndIgnoresAReportFailure ( ) {
mockInstall ( ) ;
doAnswer ( i - > {
recordAfterCommit ( "REPORT" ) ;
throw new RestClientException ( "Connection refused" ) ;
} ) . when ( iotHubRestClient ) . reportVersionInstalled ( eq ( versionId ) , any ( ) ) ;
DevicePackageResult result = service . install ( user , request (
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
InOrder order = inOrder ( installedItemService , logEntityActionService , iotHubRestClient ) ;
order . verify ( installedItemService ) . save ( eq ( tenantId ) , any ( ) ) ;
order . verify ( logEntityActionService ) . logEntityAction ( eq ( tenantId ) , eq ( dashboardId ) , any ( ) , any ( ) , eq ( ActionType . ADDED ) , eq ( user ) ) ;
order . verify ( iotHubRestClient ) . reportVersionInstalled ( eq ( versionId ) , any ( ) ) ;
assertThat ( afterCommitCalls ) . containsExactly ( "AUDIT" , "REPORT" ) ;
}
@Test
void installRejectsAFromVersion ( ) {
mockInstall ( ) ;
DevicePackageRequest request = request ( create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ;
request . setFromVersionId ( installedVersionId ) ;
DevicePackageResult result = service . install ( user , request ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Invalid install request" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void installKeepStepMustUseExisting ( ) {
mockInstall ( ) ;
DevicePackageRequest . Step integrationStep = keep ( "TTN" , "INTEGRATION" , integrationId ) ;
integrationStep . setResolution ( "created" ) ;
DevicePackageResult result = service . install ( user , request ( integrationStep ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Invalid install step: TTN" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void installRejectsAMalformedVersionId ( ) {
mockInstall ( ) ;
DevicePackageRequest request = request ( create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ;
request . setVersionId ( "not-a-uuid" ) ;
DevicePackageResult result = service . install ( user , request ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Invalid install request" ) ;
verify ( iotHubRestClient , never ( ) ) . getVersionInfo ( any ( ) ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
}
@Test
void installAssignsTheCustomerToTheDeviceAndTheDashboard ( ) {
mockInstall ( ) ;
CustomerId customerId = customerOf ( tenantId ) ;
DevicePackageRequest request = request (
create ( "AM308" , "DEVICE" , JacksonUtil . newObjectNode ( ) . put ( "name" , "AM308" ) ) ,
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ;
request . setCustomerId ( customerId . getId ( ) ) ;
DevicePackageResult result = service . install ( user , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
ArgumentCaptor < Device > device = ArgumentCaptor . forClass ( Device . class ) ;
verify ( deviceService ) . saveDevice ( device . capture ( ) ) ;
assertThat ( device . getValue ( ) . getCustomerId ( ) ) . isEqualTo ( customerId ) ;
ArgumentCaptor < Dashboard > dashboard = ArgumentCaptor . forClass ( Dashboard . class ) ;
verify ( dashboardService ) . saveDashboard ( dashboard . capture ( ) ) ;
assertThat ( dashboard . getValue ( ) . getCustomerId ( ) ) . isEqualTo ( customerId ) ;
}
@Test
void installAddsTheDeviceToTheEntityGroup ( ) {
mockInstall ( ) ;
EntityGroup group = new EntityGroup ( ) ;
group . setId ( new EntityGroupId ( UUID . randomUUID ( ) ) ) ;
group . setType ( EntityType . DEVICE ) ;
group . setName ( "Warehouse sensors" ) ;
group . setOwnerId ( tenantId ) ;
when ( entityGroupService . findEntityGroupById ( tenantId , group . getId ( ) ) ) . thenReturn ( group ) ;
DevicePackageRequest request = request (
create ( "AM308" , "DEVICE" , JacksonUtil . newObjectNode ( ) . put ( "name" , "AM308" ) ) ,
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ;
request . setEntityGroupId ( group . getId ( ) . getId ( ) ) ;
DevicePackageResult result = service . install ( user , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
verify ( entityGroupService ) . addEntityToEntityGroup ( tenantId , group . getId ( ) , deviceId ) ;
verify ( entityGroupService , never ( ) ) . addEntityToEntityGroup ( any ( ) , any ( ) , eq ( dashboardId ) ) ;
assertThat ( savedInTransaction ) . contains ( "ENTITY_GROUP" ) ;
verify ( logEntityActionService ) . logEntityAction ( eq ( tenantId ) , eq ( deviceId ) , any ( Device . class ) , any ( ) , eq ( ActionType . ADDED_TO_ENTITY_GROUP ) ,
eq ( user ) , eq ( deviceId . toString ( ) ) , eq ( group . getId ( ) . toString ( ) ) , eq ( "Warehouse sensors" ) ) ;
assertThat ( afterCommitCalls ) . containsExactly ( "AUDIT" , "AUDIT" , "AUDIT" , "REPORT" ) ;
}
@Test
void installRejectsACustomerOfAnotherTenant ( ) {
mockInstall ( ) ;
CustomerId customerId = customerOf ( TenantId . fromUUID ( UUID . randomUUID ( ) ) ) ;
DevicePackageRequest request = request ( create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ;
request . setCustomerId ( customerId . getId ( ) ) ;
DevicePackageResult result = service . install ( user , request ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Invalid install request" ) ;
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void updateIgnoresCustomerAndEntityGroup ( ) {
when ( dashboardService . findDashboardById ( tenantId , dashboardId ) ) . thenReturn ( dashboard ( 7L ) ) ;
when ( dashboardService . saveDashboard ( any ( Dashboard . class ) ) ) . thenAnswer ( i - > i . getArgument ( 0 ) ) ;
DevicePackageRequest request = request ( overwrite ( "Dashboard" , "DASHBOARD" , dashboardId , 7L , JacksonUtil . newObjectNode ( ) . put ( "title" , "d" ) ) ) ;
request . setCustomerId ( UUID . randomUUID ( ) ) ;
request . setEntityGroupId ( UUID . randomUUID ( ) ) ;
DevicePackageResult result = service . update ( user , installedItem . getId ( ) , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
ArgumentCaptor < Dashboard > dashboard = ArgumentCaptor . forClass ( Dashboard . class ) ;
verify ( dashboardService ) . saveDashboard ( dashboard . capture ( ) ) ;
assertThat ( dashboard . getValue ( ) . getCustomerId ( ) ) . isNull ( ) ;
verifyNoInteractions ( customerService , entityGroupService ) ;
}
@Test
void updateOverwriteOfACustomerDeviceThatChangesItsOwnerFails ( ) {
DeviceId otherId = new DeviceId ( UUID . randomUUID ( ) ) ;
Device current = new Device ( otherId ) ;
current . setTenantId ( tenantId ) ;
current . setName ( "AM308 spare" ) ;
current . setCustomerId ( customerOf ( tenantId ) ) ;
when ( deviceService . findDeviceById ( tenantId , otherId ) ) . thenReturn ( current ) ;
DevicePackageRequest . Step step = overwrite ( "AM308 spare" , "DEVICE" , otherId , null , JacksonUtil . newObjectNode ( ) . put ( "name" , "AM308 spare" ) ) ;
step . setConfirmed ( true ) ;
DevicePackageResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) , step ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getFailedStep ( ) ) . isEqualTo ( "DEVICE:AM308 spare" ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "AM308 spare belongs to another owner" ) ;
verify ( deviceService , never ( ) ) . saveDevice ( any ( Device . class ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void updateOverwriteOfAnotherDeviceKeepsItsCredentials ( ) {
DeviceId otherId = new DeviceId ( UUID . randomUUID ( ) ) ;
Device current = new Device ( otherId ) ;
current . setTenantId ( tenantId ) ;
current . setName ( "AM308 spare" ) ;
when ( deviceService . findDeviceById ( tenantId , otherId ) ) . thenReturn ( current ) ;
when ( deviceService . saveDevice ( any ( Device . class ) ) ) . thenAnswer ( i - > i . getArgument ( 0 ) ) ;
DeviceCredentials credentials = new DeviceCredentials ( ) ;
credentials . setDeviceId ( otherId ) ;
credentials . setCredentialsId ( "existing-token" ) ;
when ( deviceCredentialsService . findDeviceCredentialsByDeviceId ( tenantId , otherId ) ) . thenReturn ( credentials ) ;
DevicePackageRequest . Step step = overwrite ( "AM308 spare" , "DEVICE" , otherId , null , JacksonUtil . newObjectNode ( ) . put ( "name" , "AM308 spare" ) ) ;
step . setConfirmed ( true ) ;
step . setCredentials ( JacksonUtil . newObjectNode ( ) . put ( "credentialsType" , "ACCESS_TOKEN" ) . put ( "credentialsId" , "package-token" ) ) ;
DevicePackageResult result = service . update ( user , installedItem . getId ( ) , request ( keep ( "AM308" , "DEVICE" , deviceId ) , step ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
verify ( deviceService ) . saveDevice ( any ( Device . class ) ) ;
verify ( deviceCredentialsService , never ( ) ) . updateDeviceCredentials ( any ( ) , any ( ) ) ;
assertThat ( result . getOutputs ( ) . get ( "DEVICE:AM308 spare" ) . get ( "token" ) . asText ( ) ) . isEqualTo ( "existing-token" ) ;
}
@Test
void installRejectsAnOverwriteOfADeviceOrGateway ( ) {
mockInstall ( ) ;
for ( String type : new String [ ] { "DEVICE" , "GATEWAY" } ) {
DevicePackageRequest . Step step = overwrite ( "AM308" , type , deviceId , 1L , JacksonUtil . newObjectNode ( ) . put ( "name" , "AM308" ) ) ;
step . setConfirmed ( true ) ;
DevicePackageResult result = service . install ( user , request ( step ) ) ;
assertThat ( result . isSuccess ( ) ) . isFalse ( ) ;
assertThat ( result . getErrorMessage ( ) ) . isEqualTo ( "Invalid install step: AM308" ) ;
}
verify ( transactionTemplate , never ( ) ) . execute ( any ( ) ) ;
verify ( deviceService , never ( ) ) . saveDevice ( any ( Device . class ) ) ;
verify ( installedItemService , never ( ) ) . save ( any ( ) , any ( ) ) ;
}
@Test
void installWritesStepAttributesOnAUsedExistingEntityAfterCommit ( ) {
mockInstall ( ) ;
DevicePackageRequest . Step deviceStep = keep ( "AM308" , "DEVICE" , deviceId ) ;
deviceStep . setResolution ( "use-existing" ) ;
deviceStep . setServerAttributes ( JacksonUtil . newObjectNode ( ) . put ( "model" , "AM308" ) ) ;
deviceStep . setSharedAttributes ( JacksonUtil . newObjectNode ( ) . put ( "deviceId" , "${device.id}" ) ) ;
DevicePackageResult result = service . install ( user , request ( deviceStep ,
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
ArgumentCaptor < AttributesSaveRequest > saved = ArgumentCaptor . forClass ( AttributesSaveRequest . class ) ;
verify ( telemetryService , times ( 2 ) ) . saveAttributes ( saved . capture ( ) ) ;
assertThat ( saved . getAllValues ( ) ) . extracting ( AttributesSaveRequest : : getEntityId ) . containsOnly ( deviceId ) ;
assertThat ( saved . getAllValues ( ) ) . extracting ( AttributesSaveRequest : : getScope ) . containsExactly ( AttributeScope . SERVER_SCOPE , AttributeScope . SHARED_SCOPE ) ;
assertThat ( saved . getAllValues ( ) . get ( 0 ) . getEntries ( ) . get ( 0 ) . getValueAsString ( ) ) . isEqualTo ( "AM308" ) ;
assertThat ( saved . getAllValues ( ) . get ( 1 ) . getEntries ( ) . get ( 0 ) . getValueAsString ( ) ) . isEqualTo ( deviceId . getId ( ) . toString ( ) ) ;
// The kept device isn't saved, so only the dashboard is audited
assertThat ( afterCommitCalls ) . containsExactly ( "AUDIT" , "ATTRIBUTES" , "ATTRIBUTES" , "REPORT" ) ;
}
@Test
void installIntoACustomerGroupGivesTheDeviceTheGroupsCustomer ( ) {
mockInstall ( ) ;
CustomerId groupCustomer = customerOf ( tenantId ) ;
EntityGroup group = new EntityGroup ( ) ;
group . setId ( new EntityGroupId ( UUID . randomUUID ( ) ) ) ;
group . setType ( EntityType . DEVICE ) ;
group . setName ( "Customer sensors" ) ;
group . setOwnerId ( groupCustomer ) ;
when ( entityGroupService . findEntityGroupById ( tenantId , group . getId ( ) ) ) . thenReturn ( group ) ;
DevicePackageRequest request = request (
create ( "AM308" , "DEVICE" , JacksonUtil . newObjectNode ( ) . put ( "name" , "AM308" ) ) ,
create ( "Dashboard" , "DASHBOARD" , JacksonUtil . newObjectNode ( ) . put ( "title" , "AM308 dashboard" ) ) ) ;
request . setEntityGroupId ( group . getId ( ) . getId ( ) ) ;
DevicePackageResult result = service . install ( user , request ) ;
assertThat ( result . isSuccess ( ) ) . isTrue ( ) ;
ArgumentCaptor < Device > device = ArgumentCaptor . forClass ( Device . class ) ;
verify ( deviceService ) . saveDevice ( device . capture ( ) ) ;
assertThat ( device . getValue ( ) . getCustomerId ( ) ) . isEqualTo ( groupCustomer ) ;
ArgumentCaptor < Dashboard > dashboard = ArgumentCaptor . forClass ( Dashboard . class ) ;
verify ( dashboardService ) . saveDashboard ( dashboard . capture ( ) ) ;
assertThat ( dashboard . getValue ( ) . getOwnerId ( ) ) . isEqualTo ( tenantId ) ;
verify ( entityGroupService ) . addEntityToEntityGroup ( tenantId , group . getId ( ) , deviceId ) ;
verify ( logEntityActionService ) . logEntityAction ( eq ( tenantId ) , eq ( deviceId ) , any ( Device . class ) , eq ( groupCustomer ) , eq ( ActionType . ADDED ) , eq ( user ) ) ;
}
private CustomerId customerOf ( TenantId owner ) {
Customer customer = new Customer ( new CustomerId ( UUID . randomUUID ( ) ) ) ;
customer . setTenantId ( owner ) ;
when ( customerService . findCustomerById ( tenantId , customer . getId ( ) ) ) . thenReturn ( customer ) ;
return customer . getId ( ) ;
}
/** The new entities get these ids; each save records that it ran inside the transaction. */
private void mockInstall ( ) {
when ( user . getId ( ) ) . thenReturn ( new UserId ( UUID . randomUUID ( ) ) ) ;
when ( projectInfo . getProjectVersion ( ) ) . thenReturn ( "4.4.1" ) ;
when ( projectInfo . getProductType ( ) ) . thenReturn ( "PE" ) ;
when ( deviceProfileService . saveDeviceProfile ( any ( ) ) ) . thenAnswer ( i - > {
recordSave ( "DEVICE_PROFILE" ) ;
DeviceProfile profile = i . getArgument ( 0 ) ;
profile . setId ( profileId ) ;
return profile ;
} ) ;
when ( dashboardService . saveDashboard ( any ( Dashboard . class ) ) ) . thenAnswer ( i - > {
recordSave ( "DASHBOARD" ) ;
Dashboard dashboard = i . getArgument ( 0 ) ;
dashboard . setId ( dashboardId ) ;
return dashboard ;
} ) ;
when ( deviceService . saveDevice ( any ( Device . class ) ) ) . thenAnswer ( i - > {
recordSave ( "DEVICE" ) ;
Device device = i . getArgument ( 0 ) ;
device . setId ( deviceId ) ;
return device ;
} ) ;
doAnswer ( i - > {
recordSave ( "ENTITY_GROUP" ) ;
return null ;
} ) . when ( entityGroupService ) . addEntityToEntityGroup ( any ( ) , any ( ) , any ( ) ) ;
when ( installedItemService . save ( any ( ) , any ( ) ) ) . thenAnswer ( i - > {
recordSave ( "INSTALLED_ITEM" ) ;
return i . getArgument ( 1 ) ;
} ) ;
Integration integration = new Integration ( ) ;
integration . setId ( integrationId ) ;
integration . setTenantId ( tenantId ) ;
integration . setName ( "TTN my-app" ) ;
when ( integrationService . findIntegrationById ( tenantId , integrationId ) ) . thenReturn ( integration ) ;
doAnswer ( i - > {
recordAfterCommit ( "AUDIT" ) ;
return null ;
} ) . when ( logEntityActionService ) . logEntityAction ( any ( TenantId . class ) , any ( EntityId . class ) , any ( HasName . class ) , nullable ( CustomerId . class ) ,
any ( ActionType . class ) , any ( User . class ) , any ( Object [ ] . class ) ) ;
doAnswer ( i - > {
recordAfterCommit ( "REPORT" ) ;
return null ;
} ) . when ( iotHubRestClient ) . reportVersionInstalled ( any ( ) , any ( ) ) ;
doAnswer ( i - > {
recordAfterCommit ( "ATTRIBUTES" ) ;
return null ;
} ) . when ( telemetryService ) . saveAttributes ( any ( AttributesSaveRequest . class ) ) ;
}
private void recordSave ( String what ) {
if ( inTransaction ) {
savedInTransaction . add ( what ) ;
}
}
private void recordAfterCommit ( String what ) {
afterCommitCalls . add ( inTransaction ? what + " in transaction" : what ) ;
}
private IotHubInstalledItem otherPackage ( Map < String , JsonNode > installState ) {
DeviceInstalledItemDescriptor descriptor = new DeviceInstalledItemDescriptor ( ) ;
descriptor . setInstallState ( installState ) ;
@ -875,35 +1327,35 @@ class DefaultDevicePackageUpdateServiceTest {
return dashboard ;
}
private DeviceUpdateRequest request ( DeviceUpdat eRequest . Step . . . steps ) {
DeviceUpdat eRequest request = new DeviceUpdat eRequest ( ) ;
private DevicePackageRequest request ( DevicePackag eRequest . Step . . . steps ) {
DevicePackag eRequest request = new DevicePackag eRequest ( ) ;
request . setVersionId ( versionId ) ;
request . setSteps ( List . of ( steps ) ) ;
return request ;
}
private static DeviceUpdat eRequest . Step keep ( String name , String type , EntityId id ) {
DeviceUpdat eRequest . Step step = step ( name , type , DeviceUpdat eRequest . Action . KEEP ) ;
private static DevicePackag eRequest . Step keep ( String name , String type , EntityId id ) {
DevicePackag eRequest . Step step = step ( name , type , DevicePackag eRequest . Action . KEEP ) ;
step . setEntityId ( id . getId ( ) ) ;
return step ;
}
private static DeviceUpdat eRequest . Step overwrite ( String name , String type , EntityId id , Long version , ObjectNode entity ) {
DeviceUpdat eRequest . Step step = step ( name , type , DeviceUpdat eRequest . Action . OVERWRITE ) ;
private static DevicePackag eRequest . Step overwrite ( String name , String type , EntityId id , Long version , ObjectNode entity ) {
DevicePackag eRequest . Step step = step ( name , type , DevicePackag eRequest . Action . OVERWRITE ) ;
step . setEntityId ( id . getId ( ) ) ;
step . setExpectedVersion ( version ) ;
step . setEntity ( entity ) ;
return step ;
}
private static DeviceUpdat eRequest . Step create ( String name , String type , ObjectNode entity ) {
DeviceUpdat eRequest . Step step = step ( name , type , DeviceUpdat eRequest . Action . CREATE ) ;
private static DevicePackag eRequest . Step create ( String name , String type , ObjectNode entity ) {
DevicePackag eRequest . Step step = step ( name , type , DevicePackag eRequest . Action . CREATE ) ;
step . setEntity ( entity ) ;
return step ;
}
private static DeviceUpdat eRequest . Step step ( String name , String type , DeviceUpdat eRequest . Action action ) {
DeviceUpdat eRequest . Step step = new DeviceUpdat eRequest . Step ( ) ;
private static DevicePackag eRequest . Step step ( String name , String type , DevicePackag eRequest . Action action ) {
DevicePackag eRequest . Step step = new DevicePackag eRequest . Step ( ) ;
step . setName ( name ) ;
step . setType ( type ) ;
step . setAction ( action ) ;