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);
}
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);
}
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);
}
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());
}
}
}
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);
}
Aggregations