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