use of org.openhab.core.storage.StorageService in project openhab-core by openhab.
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 = Map.of("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.openhab.core.storage.StorageService in project openhab-core by openhab.
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.openhab.core.storage.StorageService in project openhab-core by openhab.
the class AutomationIntegrationJsonTest method before.
@BeforeEach
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<Item> getAll() {
return Set.of(new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2"), new SwitchItem("myMotionItem11"), new SwitchItem("myLampItem11"), new SwitchItem("myMotionItem3"), new SwitchItem("templ_MotionItem"), new SwitchItem("templ_LampItem"));
}
@Override
public void removeProviderChangeListener(ProviderChangeListener<Item> listener) {
}
};
registerService(itemProvider);
registerVolatileStorageService();
EventSubscriber ruleEventHandler = new EventSubscriber() {
@Override
public Set<String> getSubscribedEventTypes() {
return Set.of(RuleStatusInfoEvent.TYPE);
}
@Override
@Nullable
public EventFilter getEventFilter() {
return null;
}
@Override
public void receive(Event e) {
logger.info("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);
// start rule engine
RuleEngineImpl ruleEngine = (RuleEngineImpl) ruleManager;
ruleEngine.onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> assertTrue(ruleEngine.isStarted()));
logger.info("@Before.finish");
}
use of org.openhab.core.storage.StorageService in project openhab-core by openhab.
the class AutomationIntegrationTest method before.
@BeforeEach
public void before() {
logger.info("@Before.begin");
getService(ItemRegistry.class);
ItemProvider itemProvider = new ItemProvider() {
@Override
public void addProviderChangeListener(ProviderChangeListener<Item> listener) {
}
@Override
public Collection<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(ProviderChangeListener<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);
// start rule engine
((RuleEngineImpl) ruleEngine).onReadyMarkerAdded(new ReadyMarker("", ""));
waitForAssert(() -> {
assertThat(((RuleEngineImpl) ruleEngine).isStarted(), is(true));
}, 5000, 1000);
logger.info("@Before.finish");
}
use of org.openhab.core.storage.StorageService 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);
}
});
}
Aggregations