Search in sources :

Example 6 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class SlingSettingsServiceImplTest method testGetSlingIdFromTooShortData.

@Test
public void testGetSlingIdFromTooShortData() throws IOException {
    // 8 byte long random String
    final String data = RandomStringUtils.randomAscii(8);
    SlingIdUtil.writeSlingId(slingIdFile, data);
    final SlingSettingsService slingSettingsService = createSlingSettingsService(slingIdFile, optionsFile);
    final String slingId = slingSettingsService.getSlingId();
    assertNotNull(slingId);
}
Also used : SlingSettingsService(org.apache.sling.settings.SlingSettingsService) Test(org.junit.Test)

Example 7 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class SlingSettingsServiceImplTest method testGetSlingIdExisting.

@Test
public void testGetSlingIdExisting() throws IOException {
    final String expected = SlingIdUtil.createSlingId();
    SlingIdUtil.writeSlingId(slingIdFile, expected);
    final SlingSettingsService slingSettingsService = createSlingSettingsService(slingIdFile, optionsFile);
    final String slingId = slingSettingsService.getSlingId();
    assertNotNull(slingId);
    assertEquals(expected, slingId);
}
Also used : SlingSettingsService(org.apache.sling.settings.SlingSettingsService) Test(org.junit.Test)

Example 8 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class SlingSettingsServiceImplTest method testGetSlingIdCreating.

@Test
public void testGetSlingIdCreating() throws IOException {
    final SlingSettingsService slingSettingsService = createSlingSettingsService(slingIdFile, optionsFile);
    final String slingId = slingSettingsService.getSlingId();
    assertNotNull(slingId);
}
Also used : SlingSettingsService(org.apache.sling.settings.SlingSettingsService) Test(org.junit.Test)

Example 9 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class ServicesListener method notifyChange.

/**
     * Notify of service changes from the listeners.
     * If all services are available, register listener and pass resources
     * to the OSGi installer.
     */
public synchronized void notifyChange() {
    // check if all services are available
    final OsgiInstaller installer = (OsgiInstaller) this.installerListener.getService();
    final LaunchpadContentProvider lcp = (LaunchpadContentProvider) this.providerListener.getService();
    final StartupHandler handler = (StartupHandler) this.startupListener.getService();
    final SlingSettingsService settings = (SlingSettingsService) this.settingsListener.getService();
    if (installer != null && lcp != null && handler != null && settings != null) {
        if (!this.installed) {
            this.installed = true;
            this.launchpadListener = new LaunchpadListener(handler);
            final Dictionary<String, Object> props = new Hashtable<String, Object>();
            props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Launchpad Startup Listener");
            props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
            this.launchpadListenerReg = this.bundleContext.registerService(InstallationListener.class.getName(), launchpadListener, props);
            LaunchpadConfigInstaller.install(installer, lcp, settings.getRunModes());
        }
    }
}
Also used : LaunchpadContentProvider(org.apache.sling.launchpad.api.LaunchpadContentProvider) Hashtable(java.util.Hashtable) StartupHandler(org.apache.sling.launchpad.api.StartupHandler) OsgiInstaller(org.apache.sling.installer.api.OsgiInstaller) SlingSettingsService(org.apache.sling.settings.SlingSettingsService)

Example 10 with SlingSettingsService

use of org.apache.sling.settings.SlingSettingsService in project sling by apache.

the class DistributingEventHandlerTest method setup.

@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
    final BundleContext bc = Mockito.mock(BundleContext.class);
    Mockito.when(bc.registerService(Mockito.any(String[].class), Mockito.any(), Mockito.any(Dictionary.class))).thenReturn(null);
    final SlingSettingsService otherSettings = Mockito.mock(SlingSettingsService.class);
    Mockito.when(otherSettings.getSlingId()).thenReturn(OTHER_APP_ID);
    final EventAdmin ea = new EventAdmin() {

        @Override
        public void sendEvent(final Event event) {
            this.postEvent(event);
        }

        @Override
        public void postEvent(final Event event) {
            final String topic = event.getTopic();
            if (topic.equals(SlingConstants.TOPIC_RESOURCE_ADDED)) {
                final ResourceChange change = new ResourceChange(ChangeType.ADDED, (String) event.getProperty(SlingConstants.PROPERTY_PATH), false, null, null, null);
                sender.onChange(Collections.singletonList(change));
            } else if (topic.startsWith(TOPIC_PREFIX)) {
                events.add(event);
            }
        }
    };
    final MockResourceResolverFactoryOptions opts = new MockResourceResolverFactoryOptions();
    opts.setEventAdmin(ea);
    final ResourceResolverFactory factory = new MockResourceResolverFactory(opts);
    this.sender = new DistributedEventSender(bc, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH + "/" + MY_APP_ID, factory, ea);
    this.receiver = new DistributedEventReceiver(bc, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH, DistributedEventAdminImpl.DEFAULT_REPOSITORY_PATH + "/" + OTHER_APP_ID, 15, factory, otherSettings);
}
Also used : Dictionary(java.util.Dictionary) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) EventAdmin(org.osgi.service.event.EventAdmin) MockResourceResolverFactoryOptions(org.apache.sling.testing.resourceresolver.MockResourceResolverFactoryOptions) Event(org.osgi.service.event.Event) MockResourceResolverFactory(org.apache.sling.testing.resourceresolver.MockResourceResolverFactory) ResourceChange(org.apache.sling.api.resource.observation.ResourceChange) SlingSettingsService(org.apache.sling.settings.SlingSettingsService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Aggregations

SlingSettingsService (org.apache.sling.settings.SlingSettingsService)24 Test (org.junit.Test)7 URL (java.net.URL)3 HashSet (java.util.HashSet)3 Attributes (java.util.jar.Attributes)2 JarFile (java.util.jar.JarFile)2 Manifest (java.util.jar.Manifest)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 OsgiInstaller (org.apache.sling.installer.api.OsgiInstaller)2 RegisteredResource (org.apache.sling.installer.api.tasks.RegisteredResource)2 TransformationResult (org.apache.sling.installer.api.tasks.TransformationResult)2 DeleteOnCloseFileInputStream (org.apache.sling.installer.factories.subsystems.base.impl.SubsystemBaseTransformer.DeleteOnCloseFileInputStream)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 Set (java.util.Set)1 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)1 ResourceChange (org.apache.sling.api.resource.observation.ResourceChange)1 DiscoveryService (org.apache.sling.discovery.DiscoveryService)1 LaunchpadContentProvider (org.apache.sling.launchpad.api.LaunchpadContentProvider)1