use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.
the class ManagedItemProviderOSGiTest method assertItemsAreThereOnceTheFactoryGetsAdded.
@Test
public void assertItemsAreThereOnceTheFactoryGetsAdded() throws ItemNotFoundException {
StorageService storageService = getService(StorageService.class);
assertThat(storageService, is(notNullValue()));
Storage<PersistedItem> storage = storageService.getStorage(Item.class.getName());
StrangeItem item = new StrangeItem("SomeStrangeItem");
String key = item.getUID();
// put an item into the storage that cannot be handled (yet)
storage.put(key, itemProvider.toPersistableElement(item));
// start without the appropriate item factory - it's going to fail silently, leaving a debug log
assertThat(itemProvider.getAll().size(), is(0));
assertThat(itemRegistry.getItems().size(), is(0));
assertThat(itemProvider.get("SomeStrangeItem"), is(nullValue()));
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. The item should be there...
StrangeItemFactory factory = new StrangeItemFactory();
registerService(factory);
try {
assertThat(itemProvider.getAll().size(), is(1));
assertThat(itemRegistry.getItems().size(), is(1));
assertThat(itemProvider.get("SomeStrangeItem"), is(notNullValue()));
assertThat(itemRegistry.getItem("SomeStrangeItem"), is(notNullValue()));
} finally {
unregisterService(factory);
}
}
use of org.eclipse.smarthome.core.storage.StorageService in project smarthome by eclipse.
the class AutomationIntegrationJsonTest method before.
// rules imported from
// json files
@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() {
HashSet<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("myMotionItem11"));
items.add(new SwitchItem("myLampItem11"));
items.add(new SwitchItem("myMotionItem3"));
items.add(new SwitchItem("templ_MotionItem"));
items.add(new SwitchItem("templ_LampItem"));
return items;
}
@Override
public void removeProviderChangeListener(@NonNull ProviderChangeListener<@NonNull Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
EventSubscriber ruleEventHandler = new EventSubscriber() {
@Override
@NonNull
public Set<@NonNull String> getSubscribedEventTypes() {
return Collections.singleton(RuleStatusInfoEvent.TYPE);
}
@Override
@Nullable
public EventFilter getEventFilter() {
return null;
}
@Override
public void receive(@NonNull Event e) {
logger.info("RuleEvent: " + e.getTopic() + " --> " + e.getPayload());
System.out.println("RuleEvent: " + e.getTopic() + " --> " + e.getPayload());
if (e.getPayload().contains("RUNNING")) {
ruleEvent = e;
}
}
};
registerService(ruleEventHandler);
StorageService storageService = getService(StorageService.class);
managedRuleProvider = getService(ManagedRuleProvider.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
ruleRegistry = getService(RuleRegistry.class);
ruleManager = getService(RuleManager.class);
moduleTypeRegistry = getService(ModuleTypeRegistry.class);
waitForAssert(() -> {
assertThat(storageService, is(notNullValue()));
// sometimes assert fails because EventPublisher service is null
assertThat(eventPublisher, is(notNullValue()));
assertThat(itemRegistry, is(notNullValue()));
assertThat(ruleRegistry, is(notNullValue()));
assertThat(ruleManager, is(notNullValue()));
assertThat(managedRuleProvider, is(notNullValue()));
assertThat(moduleTypeRegistry, is(notNullValue()));
}, 9000, 1000);
logger.info("@Before.finish");
}
Aggregations