Skip to content

Commit

Permalink
fix(sca): get application version (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shmayro authored Oct 23, 2023
1 parent 0e29fd4 commit f76474f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void autoDeployDetectedCustomApplication(PlatformStartedEvent event)
log.info("Bonita now tries to install it automatically...");
applicationInstaller.install(applicationArchive);
} else {
var currentVersion = platformService.getPlatform().getApplicationVersion();
var currentVersion = getInstalledApplicationVersion();
log.info("Detected application version: '{}'; Current deployed version: '{}'",
applicationArchive.getVersion(),
currentVersion);
Expand All @@ -113,6 +113,11 @@ public void autoDeployDetectedCustomApplication(PlatformStartedEvent event)
}
}

String getInstalledApplicationVersion() throws Exception {
return applicationInstaller.inSession(
() -> applicationInstaller.inTransaction(() -> platformService.getPlatform().getApplicationVersion()));
}

boolean isPlatformFirstInitialization() {
return mandatoryLivingApplicationImporter.isFirstRun();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import org.bonitasoft.engine.business.application.importer.DefaultLivingApplicationImporter;
import org.bonitasoft.engine.exception.ApplicationInstallationException;
import org.bonitasoft.engine.platform.PlatformService;
import org.bonitasoft.engine.platform.model.SPlatform;
import org.bonitasoft.engine.tenant.TenantServicesManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -60,10 +58,6 @@ class CustomOrDefaultApplicationInstallerTest {
DefaultLivingApplicationImporter defaultLivingApplicationImporter;
@Mock
TenantServicesManager tenantServicesManager;
@Mock
PlatformService platformService;
@Mock
SPlatform platform;

@Mock
private ApplicationArchiveReader applicationArchiveReader;
Expand All @@ -75,7 +69,6 @@ class CustomOrDefaultApplicationInstallerTest {
void before() throws Exception {
doAnswer(inv -> callableCaptor.getValue().call()).when(tenantServicesManager)
.inTenantSessionTransaction(callableCaptor.capture());
doReturn(platform).when(platformService).getPlatform();
}

@Test
Expand Down Expand Up @@ -170,7 +163,7 @@ void should_update_custom_application_if_detected_version_superior_to_deployed_v
applicationArchive.setVersion("1.0.1");
doReturn(applicationArchive).when(applicationArchiveReader).read(resourceStream1);
doReturn(false).when(listener).isPlatformFirstInitialization();
doReturn("1.0.0").when(platform).getApplicationVersion();
doReturn("1.0.0").when(listener).getInstalledApplicationVersion();
//when
listener.autoDeployDetectedCustomApplication(any());

Expand All @@ -190,7 +183,7 @@ void should_update_conf_if_detected_version_equal_to_deployed_version()
applicationArchive.setVersion("1.0.0");
doReturn(applicationArchive).when(listener).createApplicationArchive(resource1);
doReturn(false).when(listener).isPlatformFirstInitialization();
doReturn("1.0.0").when(platform).getApplicationVersion();
doReturn("1.0.0").when(listener).getInstalledApplicationVersion();
//when
listener.autoDeployDetectedCustomApplication(any());

Expand All @@ -212,7 +205,7 @@ void should_throw_an_exception_if_detected_version_inferior_to_deployed_version(
applicationArchive.setVersion("0.0.9-SNAPSHOT");
doReturn(applicationArchive).when(listener).createApplicationArchive(resource1);
doReturn(false).when(listener).isPlatformFirstInitialization();
doReturn("1.0.0").when(platform).getApplicationVersion();
doReturn("1.0.0").when(listener).getInstalledApplicationVersion();
//when
String exceptionMessage = Assertions.assertThrows(ApplicationInstallationException.class,
() -> listener.autoDeployDetectedCustomApplication(any())).getMessage();
Expand Down

0 comments on commit f76474f

Please sign in to comment.