Search in sources :

Example 1 with StorageService

use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.

the class ManagedItemProviderOSGiTest method assertItemsAreAddedAsGroupMembersOnDeferredCreation.

@SuppressWarnings("null")
@Test
public void assertItemsAreAddedAsGroupMembersOnDeferredCreation() throws ItemNotFoundException {
    StorageService storageService = getService(StorageService.class);
    assertThat(storageService, is(notNullValue()));
    Storage<PersistedItem> storage = storageService.getStorage(Item.class.getName());
    StrangeItem item = new StrangeItem("SomeStrangeItem");
    GroupItem groupItem = new GroupItem("SomeGroupItem");
    item.addGroupName(groupItem.getName());
    groupItem.addMember(item);
    String itemKey = item.getUID();
    // put items into the storage that cannot be handled (yet)
    storage.put(itemKey, itemProvider.toPersistableElement(item));
    itemProvider.add(groupItem);
    // start without the appropriate item factory - it only creates the group item
    assertThat(itemProvider.getAll().size(), is(1));
    assertThat(itemRegistry.getItems().size(), is(1));
    assertThat(itemProvider.get("SomeStrangeItem"), is(nullValue()));
    assertThat(itemProvider.get("SomeGroupItem"), is(notNullValue()));
    assertThat(itemRegistry.getItem("SomeGroupItem"), is(notNullValue()));
    try {
        assertThat(itemRegistry.getItem("SomeStrangeItem"), is(nullValue()));
        fail("the item is not (yet) expected to be there");
    } catch (ItemNotFoundException e) {
    // all good
    }
    // now register the item factory. Both items should be there...
    StrangeItemFactory factory = new StrangeItemFactory();
    registerService(factory);
    try {
        assertThat(itemProvider.getAll().size(), is(2));
        assertThat(itemRegistry.getItems().size(), is(2));
        Item item1 = itemRegistry.get("SomeStrangeItem");
        Item item2 = itemRegistry.get("SomeGroupItem");
        assertThat(itemRegistry.get("SomeStrangeItem"), is(notNullValue()));
        assertThat(item1, is(notNullValue()));
        assertThat(item1.getGroupNames().size(), is(1));
        assertThat(((GroupItem) item2).getMembers().size(), is(1));
    } finally {
        unregisterService(factory);
    }
}
Also used : PersistedItem(org.eclipse.smarthome.core.items.ManagedItemProvider.PersistedItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) StringItem(org.eclipse.smarthome.core.library.items.StringItem) PersistedItem(org.eclipse.smarthome.core.items.ManagedItemProvider.PersistedItem) StorageService(org.eclipse.smarthome.core.storage.StorageService) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 2 with StorageService

use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.

the class HostFragmentSupportTest method before.

@Before
public void before() {
    logger.info("@Before.begin");
    Locale.setDefault(Locale.ENGLISH);
    registerVolatileStorageService();
    StorageService storageService = getService(StorageService.class);
    moduleTypeRegistry = getService(ModuleTypeRegistry.class);
    pkgAdmin = getService(PackageAdmin.class);
    waitForAssert(() -> {
        assertThat(storageService, is(notNullValue()));
        assertThat(moduleTypeRegistry, is(notNullValue()));
        assertThat(pkgAdmin, is(notNullValue()));
    }, 9000, 1000);
    logger.info("@Before.finish");
}
Also used : ModuleTypeRegistry(org.eclipse.smarthome.automation.type.ModuleTypeRegistry) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) StorageService(org.eclipse.smarthome.core.storage.StorageService) Before(org.junit.Before)

Example 3 with StorageService

use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.

the class ChangeThingTypeOSGiTest method assertLoadingSpecializedThingTypeWorksDirectly.

@Test
public void assertLoadingSpecializedThingTypeWorksDirectly() {
    // println "[ChangeThingTypeOSGiTest] ======== assert loading specialized thing type works directly"
    StorageService storage = getService(StorageService.class);
    Map<String, Object> properties = new HashMap<>(1);
    properties.put("providedspecific", "there");
    Thing persistedThing = ThingFactory.createThing(thingTypeSpecific, new ThingUID("testBinding", "persistedThing"), new Configuration(properties), null, null);
    persistedThing.setProperty("universal", "survives");
    storage.getStorage(Thing.class.getName()).put("testBinding::persistedThing", persistedThing);
    selfChanging = true;
    unregisterService(storage);
    managedThingProvider = getService(ManagedThingProvider.class);
    assertThat(managedThingProvider, is(nullValue()));
    registerService(storage);
    managedThingProvider = getService(ManagedThingProvider.class);
    assertThat(managedThingProvider, is(notNullValue()));
    Collection<Thing> res = managedThingProvider.getAll();
    assertThat(res.size(), is(1));
    Thing thing = res.iterator().next();
    assertThat(thing.getUID().toString(), is("testBinding::persistedThing"));
    // Ensure that the ThingHandler has been registered as an OSGi service correctly
    waitForAssert(() -> {
        assertThat(thing.getHandler(), instanceOf(SpecificThingHandler.class));
    }, 4000, 100);
    ThingHandlerFactory handlerFactory = getService(ThingHandlerFactory.class, SampleThingHandlerFactory.class);
    assertThat(handlerFactory, not(nullValue()));
    // Ensure it's initialized
    waitForAssert(() -> {
        assertThat(specificInits, is(1));
        assertThat(genericInits, is(0));
    });
    // Ensure the Thing is ONLINE again
    assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) Thing(org.eclipse.smarthome.core.thing.Thing) StorageService(org.eclipse.smarthome.core.storage.StorageService) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 4 with StorageService

use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.

the class AutomationIntegrationTest method before.

@Before
public void before() {
    logger.info("@Before.begin");
    getService(ItemRegistry.class);
    ItemProvider itemProvider = new ItemProvider() {

        @Override
        public void addProviderChangeListener(@NonNull ProviderChangeListener<@NonNull Item> listener) {
        }

        @Override
        @NonNull
        public Collection<@NonNull Item> getAll() {
            Set<Item> items = new HashSet<>();
            items.add(new SwitchItem("myMotionItem"));
            items.add(new SwitchItem("myPresenceItem"));
            items.add(new SwitchItem("myLampItem"));
            items.add(new SwitchItem("myMotionItem2"));
            items.add(new SwitchItem("myPresenceItem2"));
            items.add(new SwitchItem("myLampItem2"));
            items.add(new SwitchItem("myMotionItem3"));
            items.add(new SwitchItem("templ_MotionItem"));
            items.add(new SwitchItem("templ_LampItem"));
            items.add(new SwitchItem("myMotionItem3"));
            items.add(new SwitchItem("myPresenceItem3"));
            items.add(new SwitchItem("myLampItem3"));
            items.add(new SwitchItem("myMotionItem4"));
            items.add(new SwitchItem("myPresenceItem4"));
            items.add(new SwitchItem("myLampItem4"));
            items.add(new SwitchItem("myMotionItem5"));
            items.add(new SwitchItem("myPresenceItem5"));
            items.add(new SwitchItem("myLampItem5"));
            items.add(new SwitchItem("xtempl_MotionItem"));
            items.add(new SwitchItem("xtempl_LampItem"));
            return items;
        }

        @Override
        public void removeProviderChangeListener(@NonNull ProviderChangeListener<@NonNull Item> listener) {
        }
    };
    registerService(itemProvider);
    registerVolatileStorageService();
    StorageService storageService = getService(StorageService.class);
    eventPublisher = getService(EventPublisher.class);
    itemRegistry = getService(ItemRegistry.class);
    ruleRegistry = getService(RuleRegistry.class);
    ruleEngine = getService(RuleManager.class);
    managedRuleProvider = getService(ManagedRuleProvider.class);
    moduleTypeRegistry = getService(ModuleTypeRegistry.class);
    templateRegistry = getService(TemplateRegistry.class);
    waitForAssert(() -> {
        assertThat(eventPublisher, is(notNullValue()));
        assertThat(storageService, is(notNullValue()));
        assertThat(itemRegistry, is(notNullValue()));
        assertThat(ruleRegistry, is(notNullValue()));
        assertThat(ruleEngine, is(notNullValue()));
        assertThat(moduleTypeRegistry, is(notNullValue()));
        assertThat(templateRegistry, is(notNullValue()));
        assertThat(managedRuleProvider, is(notNullValue()));
    }, 9000, 1000);
    logger.info("@Before.finish");
}
Also used : ItemProvider(org.eclipse.smarthome.core.items.ItemProvider) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) ModuleTypeRegistry(org.eclipse.smarthome.automation.type.ModuleTypeRegistry) RuleRegistry(org.eclipse.smarthome.automation.RuleRegistry) ManagedRuleProvider(org.eclipse.smarthome.automation.core.ManagedRuleProvider) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) StorageService(org.eclipse.smarthome.core.storage.StorageService) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) Item(org.eclipse.smarthome.core.items.Item) TemplateRegistry(org.eclipse.smarthome.automation.template.TemplateRegistry) NonNull(org.eclipse.jdt.annotation.NonNull) ProviderChangeListener(org.eclipse.smarthome.core.common.registry.ProviderChangeListener) RuleManager(org.eclipse.smarthome.automation.RuleManager) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 5 with StorageService

use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method setUp.

@Before
public void setUp() throws Exception {
    CONFIG_DESCRIPTION_THING = new URI("test:test");
    CONFIG_DESCRIPTION_CHANNEL = new URI("test:channel");
    THING = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(// 
    Collections.singletonList(ChannelBuilder.create(CHANNEL_UID, "Switch").withLabel("Test Label").withDescription("Test Description").withType(CHANNEL_TYPE_UID).withDefaultTags(Collections.singleton("Test Tag")).build())).build();
    registerVolatileStorageService();
    configureAutoLinking(false);
    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, "(esh.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
        } catch (InvalidSyntaxException e) {
            throw new RuntimeException(e);
        }
    });
    waitForAssert(() -> {
        try {
            assertThat(bundleContext.getServiceReferences(ChannelItemProvider.class, null), is(notNullValue()));
        } catch (InvalidSyntaxException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ReadyService(org.eclipse.smarthome.core.service.ReadyService) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ThingManager(org.eclipse.smarthome.core.thing.ThingManager) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ReadyMarker(org.eclipse.smarthome.core.service.ReadyMarker) URI(java.net.URI) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) StorageService(org.eclipse.smarthome.core.storage.StorageService) Before(org.junit.Before)

Aggregations

StorageService (org.eclipse.smarthome.core.storage.StorageService)7 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)4 Before (org.junit.Before)4 ModuleTypeRegistry (org.eclipse.smarthome.automation.type.ModuleTypeRegistry)3 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 RuleManager (org.eclipse.smarthome.automation.RuleManager)2 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)2 ManagedRuleProvider (org.eclipse.smarthome.automation.core.ManagedRuleProvider)2 ProviderChangeListener (org.eclipse.smarthome.core.common.registry.ProviderChangeListener)2 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)2 Item (org.eclipse.smarthome.core.items.Item)2 ItemProvider (org.eclipse.smarthome.core.items.ItemProvider)2 PersistedItem (org.eclipse.smarthome.core.items.ManagedItemProvider.PersistedItem)2 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)2 StringItem (org.eclipse.smarthome.core.library.items.StringItem)2 ManagedThingProvider (org.eclipse.smarthome.core.thing.ManagedThingProvider)2