diff --git a/modules/server/server-deploy/build.gradle b/modules/server/server-deploy/build.gradle index 74f8a922162..f16301ce2fe 100644 --- a/modules/server/server-deploy/build.gradle +++ b/modules/server/server-deploy/build.gradle @@ -1,5 +1,6 @@ dependencies { implementation project( ':core:core-api' ) + implementation project( ':core:core-internal' ) //TODO Temporary fix. See issue xp#7003 implementation project( ':admin:admin-api' ) diff --git a/modules/server/server-deploy/src/main/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManager.java b/modules/server/server-deploy/src/main/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManager.java index 796a23f2838..1f0fa7411da 100644 --- a/modules/server/server-deploy/src/main/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManager.java +++ b/modules/server/server-deploy/src/main/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManager.java @@ -1,10 +1,13 @@ package com.enonic.xp.server.internal.deploy; +import org.osgi.framework.BundleContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import org.osgi.service.condition.Condition; import com.enonic.xp.admin.tool.AdminToolDescriptorService; +import com.enonic.xp.core.internal.Dictionaries; import com.enonic.xp.export.ExportService; import com.enonic.xp.i18n.LocaleService; import com.enonic.xp.mail.MailService; @@ -30,9 +33,11 @@ public class ApplicationDeployerManager private DeployDirectoryWatcher deployDirectoryWatcher; @Activate - public void activate() + public void activate( final BundleContext bundleContext ) throws Exception { + bundleContext.registerService( Condition.class, Condition.INSTANCE, + Dictionaries.of( Condition.CONDITION_ID, "com.enonic.xp.server.deploy.ready" ) ); storedApplicationsDeployer.deploy(); autoDeployer.deploy(); deployDirectoryWatcher.deploy(); diff --git a/modules/server/server-deploy/src/test/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManagerTest.java b/modules/server/server-deploy/src/test/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManagerTest.java index d8ec610947a..9e7ccb8f23f 100644 --- a/modules/server/server-deploy/src/test/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManagerTest.java +++ b/modules/server/server-deploy/src/test/java/com/enonic/xp/server/internal/deploy/ApplicationDeployerManagerTest.java @@ -2,16 +2,24 @@ import java.net.URL; import java.nio.file.Path; +import java.util.Dictionary; import java.util.HashMap; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.mockito.Mockito; +import org.mockito.ArgumentCaptor; +import org.osgi.framework.BundleContext; +import org.osgi.service.condition.Condition; import com.enonic.xp.app.ApplicationService; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; public class ApplicationDeployerManagerTest { @@ -42,7 +50,7 @@ public void setup() applicationDeployerManager.setAutoDeployer( autoDeployer ); deployDirectoryWatcher = new DeployDirectoryWatcher(); - final DeployConfig deployConfig = Mockito.mock( DeployConfig.class ); + final DeployConfig deployConfig = mock( DeployConfig.class ); System.setProperty( "xp.home", temporaryFolder.toFile().getAbsolutePath() ); deployDirectoryWatcher.activate( deployConfig ); applicationDeployerManager.setDeployDirectoryWatcher( deployDirectoryWatcher ); @@ -52,13 +60,18 @@ public void setup() public void test_activate() throws Exception { - final ApplicationService applicationService = Mockito.mock( ApplicationService.class ); + final ApplicationService applicationService = mock( ApplicationService.class ); storedApplicationsDeployer.setApplicationService( applicationService ); autoDeployer.setApplicationService( applicationService ); deployDirectoryWatcher.setApplicationService( applicationService ); - applicationDeployerManager.activate(); - Mockito.verify( applicationService ).installAllStoredApplications( any() ); - Mockito.verify( applicationService ).installGlobalApplication( new URL( "http://localhost/url1" ) ); + final BundleContext bundleContext = mock( BundleContext.class ); + applicationDeployerManager.activate( bundleContext ); + verify( applicationService ).installAllStoredApplications( any() ); + verify( applicationService ).installGlobalApplication( new URL( "http://localhost/url1" ) ); + + var captor = ArgumentCaptor.forClass( Dictionary.class ); + verify( bundleContext ).registerService( same( Condition.class ), eq(Condition.INSTANCE), captor.capture()); + assertEquals( "com.enonic.xp.server.deploy.ready", captor.getValue().get( Condition.CONDITION_ID ) ); } }