Search in sources :

Example 1 with ReadyService

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));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) AbstractScriptModuleHandler(org.openhab.core.automation.module.script.internal.handler.AbstractScriptModuleHandler) RulesRefresher(org.openhab.core.model.rule.jvmmodel.RulesRefresher) SystemTriggerHandler(org.openhab.core.automation.internal.module.handler.SystemTriggerHandler) ItemStateTriggerHandler(org.openhab.core.automation.internal.module.handler.ItemStateTriggerHandler) BigDecimal(java.math.BigDecimal) ByteArrayInputStream(java.io.ByteArrayInputStream) ThingStatusTriggerHandler(org.openhab.core.automation.internal.module.handler.ThingStatusTriggerHandler) GroupCommandTriggerHandler(org.openhab.core.automation.internal.module.handler.GroupCommandTriggerHandler) DSLRuleProvider(org.openhab.core.model.rule.runtime.internal.DSLRuleProvider) ChannelEventTriggerHandler(org.openhab.core.automation.internal.module.handler.ChannelEventTriggerHandler) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) GroupStateTriggerHandler(org.openhab.core.automation.internal.module.handler.GroupStateTriggerHandler) EventPublisher(org.openhab.core.events.EventPublisher) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Iterator(java.util.Iterator) Collection(java.util.Collection) RuleProvider(org.openhab.core.automation.RuleProvider) ReadyMarker(org.openhab.core.service.ReadyMarker) StandardCharsets(java.nio.charset.StandardCharsets) Rule(org.openhab.core.automation.Rule) Test(org.junit.jupiter.api.Test) IEvaluationContext(org.eclipse.xtext.xbase.interpreter.IEvaluationContext) AfterEach(org.junit.jupiter.api.AfterEach) ItemCommandTriggerHandler(org.openhab.core.automation.internal.module.handler.ItemCommandTriggerHandler) ScriptActionHandler(org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler) ReadyService(org.openhab.core.service.ReadyService) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest) DSLScriptEngine(org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine) ModelRepository(org.openhab.core.model.core.ModelRepository) GenericCronTriggerHandler(org.openhab.core.automation.internal.module.handler.GenericCronTriggerHandler) ModelRepository(org.openhab.core.model.core.ModelRepository) EventPublisher(org.openhab.core.events.EventPublisher) DSLRuleProvider(org.openhab.core.model.rule.runtime.internal.DSLRuleProvider) ReadyService(org.openhab.core.service.ReadyService) DSLRuleProvider(org.openhab.core.model.rule.runtime.internal.DSLRuleProvider) RuleProvider(org.openhab.core.automation.RuleProvider) ReadyMarker(org.openhab.core.service.ReadyMarker) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ReadyService

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);
        }
    });
}
Also used : ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ReadyService(org.openhab.core.service.ReadyService) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ThingManager(org.openhab.core.thing.ThingManager) ItemRegistry(org.openhab.core.items.ItemRegistry) ReadyMarker(org.openhab.core.service.ReadyMarker) URI(java.net.URI) ThingRegistry(org.openhab.core.thing.ThingRegistry) StorageService(org.openhab.core.storage.StorageService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ReadyService

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);
}
Also used : Locale(java.util.Locale) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) EventPublisher(org.openhab.core.events.EventPublisher) Bundle(org.osgi.framework.Bundle) ReadyService(org.openhab.core.service.ReadyService) ItemRegistry(org.openhab.core.items.ItemRegistry) BundleResolver(org.openhab.core.util.BundleResolver) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ThingTypeMigrationService(org.openhab.core.thing.ThingTypeMigrationService) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ReadyMarker(org.openhab.core.service.ReadyMarker) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ReadyService

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();
}
Also used : TestHueThingHandlerFactoryX(org.openhab.core.model.thing.testsupport.hue.TestHueThingHandlerFactoryX) ComponentContext(org.osgi.service.component.ComponentContext) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ReadyService(org.openhab.core.service.ReadyService) ThingHandler(org.openhab.core.thing.binding.ThingHandler) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ThingRegistry(org.openhab.core.thing.ThingRegistry) ModelRepository(org.openhab.core.model.core.ModelRepository) Command(org.openhab.core.types.Command) ChannelUID(org.openhab.core.thing.ChannelUID) Nullable(org.eclipse.jdt.annotation.Nullable) Thing(org.openhab.core.thing.Thing) Bridge(org.openhab.core.thing.Bridge) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ReadyService

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);
}
Also used : ReadyService(org.openhab.core.service.ReadyService) ReadyMarker(org.openhab.core.service.ReadyMarker)

Aggregations

ReadyService (org.openhab.core.service.ReadyService)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ReadyMarker (org.openhab.core.service.ReadyMarker)4 EventPublisher (org.openhab.core.events.EventPublisher)2 ItemRegistry (org.openhab.core.items.ItemRegistry)2 ModelRepository (org.openhab.core.model.core.ModelRepository)2 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)2 ItemChannelLinkRegistry (org.openhab.core.thing.link.ItemChannelLinkRegistry)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IEvaluationContext (org.eclipse.xtext.xbase.interpreter.IEvaluationContext)1