Skip to content

Commit

Permalink
Services not available for system apps scripts #10385
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Jan 15, 2024
1 parent 8aa585c commit 7fccedc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions modules/server/server-deploy/build.gradle
Original file line number Diff line number Diff line change
@@ -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' )

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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 ) );
}
}

0 comments on commit 7fccedc

Please sign in to comment.