use of org.openhab.core.service.ReadyService in project openhab-core by openhab.
the class DSLRuleProviderTest method setup.
@BeforeEach
public void setup() {
registerVolatileStorageService();
EventPublisher eventPublisher = event -> {
};
registerService(eventPublisher);
dslRuleProvider = getService(RuleProvider.class, DSLRuleProvider.class);
assertNotNull(dslRuleProvider);
modelRepository = getService(ModelRepository.class);
assertThat(modelRepository, is(notNullValue()));
modelRepository.removeModel(TESTMODEL_NAME);
readyService = getService(ReadyService.class);
assertThat(readyService, is(notNullValue()));
readyService.markReady(new ReadyMarker("rules", RulesRefresher.RULES_REFRESH));
}
use of org.openhab.core.service.ReadyService in project openhab-core by openhab.
the class ThingManagerOSGiJavaTest method setUp.
@BeforeEach
public void setUp() throws Exception {
configDescriptionChannel = new URI("test:channel");
configDescriptionThing = new URI("test:test");
thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(//
List.of(ChannelBuilder.create(CHANNEL_UID, CoreItemFactory.SWITCH).withLabel("Test Label").withDescription("Test Description").withType(CHANNEL_TYPE_UID).withDefaultTags(Set.of("Test Tag")).build())).build();
registerVolatileStorageService();
managedThingProvider = getService(ManagedThingProvider.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
thingRegistry = getService(ThingRegistry.class);
assertNotNull(thingRegistry);
StorageService storageService;
storageService = getService(StorageService.class);
assertNotNull(storageService);
storage = storageService.getStorage("thing_status_storage");
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
thingManager = getService(ThingManager.class);
assertNotNull(thingManager);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(openhab.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(e);
}
});
}
use of org.openhab.core.service.ReadyService in project openhab-core by openhab.
the class ThingManagerOSGiTest method setUp.
@BeforeEach
@SuppressWarnings("null")
public void setUp() {
thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(ChannelBuilder.create(CHANNEL_UID, CoreItemFactory.SWITCH).withKind(ChannelKind.STATE).withType(CHANNEL_TYPE_UID).build()).build();
registerVolatileStorageService();
configurationAdmin = getService(ConfigurationAdmin.class);
assertNotNull(configurationAdmin);
channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).thenReturn(ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
managedThingProvider = getService(ManagedThingProvider.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(" + ThingManagerImpl.XML_THING_TYPE + "=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
fail("Failed to get service reference: " + e.getMessage());
}
});
Bundle bundle = mock(Bundle.class);
when(bundle.getSymbolicName()).thenReturn("org.openhab.core.thing");
BundleResolver bundleResolver = mock(BundleResolver.class);
when(bundleResolver.resolveBundle(any())).thenReturn(bundle);
ThingManagerImpl thingManager = (ThingManagerImpl) getService(ThingTypeMigrationService.class);
thingManager.setBundleResolver(bundleResolver);
}
use of org.openhab.core.service.ReadyService in project openhab-core by openhab.
the class GenericThingProviderTest4 method setUp.
@BeforeEach
public void setUp() {
registerVolatileStorageService();
readyService = getService(ReadyService.class);
assertThat(readyService, is(notNullValue()));
thingRegistry = getService(ThingRegistry.class);
assertThat(thingRegistry, is(notNullValue()));
modelRepository = getService(ModelRepository.class);
assertThat(modelRepository, is(notNullValue()));
modelRepository.removeModel(TESTMODEL_NAME);
ComponentContext componentContextMock = mock(ComponentContext.class);
when(componentContextMock.getBundleContext()).thenReturn(bundleContext);
hueThingHandlerFactory = new TestHueThingHandlerFactoryX(componentContextMock) {
@Override
@Nullable
protected ThingHandler createHandler(final Thing thing) {
if (thing instanceof Bridge) {
return new TestBridgeHandler((Bridge) thing);
} else {
return new BaseThingHandler(thing) {
@Override
public void handleCommand(ChannelUID arg0, Command arg1) {
}
@Override
public void initialize() {
updateStatus(ThingStatus.ONLINE);
}
};
}
}
};
bundle = FrameworkUtil.getBundle(TestHueThingHandlerFactoryX.class);
removeReadyMarker();
}
use of org.openhab.core.service.ReadyService in project openhab-core by openhab.
the class SyntheticBundleInstaller method waitForReadyMarker.
private static void waitForReadyMarker(BundleContext context, String marker, Bundle bundle) {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null) {
return;
}
final String identifier = ReadyMarkerUtils.getIdentifier(bundle);
long startTime = System.nanoTime();
ServiceReference<?> readyServiceRef = context.getServiceReference(ReadyService.class.getName());
ReadyService readyService = (ReadyService) context.getService(readyServiceRef);
ReadyMarker expected = new ReadyMarker(marker, identifier);
while (!readyService.isReady(expected)) {
if (System.nanoTime() - startTime > TimeUnit.SECONDS.toNanos(WAIT_TIMOUT)) {
fail(MessageFormat.format("Timout waiting for marker {0} at bundle {1}", marker, identifier));
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
context.ungetService(readyServiceRef);
}
Aggregations