use of org.eclipse.smarthome.test.AsyncResultWrapper in project smarthome by eclipse.
the class ThingRegistryOSGiTest method assertThatCreateThingDelegatesToRegisteredThingHandlerFactory.
@Test
public void assertThatCreateThingDelegatesToRegisteredThingHandlerFactory() {
ThingTypeUID expectedThingTypeUID = THING_TYPE_UID;
ThingUID expectedThingUID = new ThingUID(THING_TYPE_UID, THING1_ID);
Configuration expectedConfiguration = new Configuration();
ThingUID expectedBridgeUID = new ThingUID(THING_TYPE_UID, THING2_ID);
String expectedLabel = "Test Thing";
AsyncResultWrapper<Thing> thingResultWrapper = new AsyncResultWrapper<Thing>();
ThingRegistry thingRegistry = getService(ThingRegistry.class);
ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {
@Override
public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
return true;
}
@Override
@Nullable
protected ThingHandler createHandler(@NonNull Thing thing) {
return null;
}
@Override
@Nullable
public Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
assertThat(thingTypeUID, is(expectedThingTypeUID));
assertThat(configuration, is(expectedConfiguration));
assertThat(thingUID, is(expectedThingUID));
assertThat(bridgeUID, is(expectedBridgeUID));
Thing thing = ThingBuilder.create(thingTypeUID, thingUID.getId()).withBridge(bridgeUID).build();
thingResultWrapper.set(thing);
return thing;
}
};
registerThingHandlerFactory(thingHandlerFactory);
Thing thing = thingRegistry.createThingOfType(expectedThingTypeUID, expectedThingUID, expectedBridgeUID, expectedLabel, expectedConfiguration);
waitForAssert(() -> {
assertTrue(thingResultWrapper.isSet());
});
assertThat(thing, is(thingResultWrapper.getWrappedObject()));
}
use of org.eclipse.smarthome.test.AsyncResultWrapper in project smarthome by eclipse.
the class HueLightDiscoveryServiceOSGiTest method hueLightRegistration.
@Test
public void hueLightRegistration() {
FullLight light = new FullLight();
light.setId("1");
light.setModelID("LCT001");
light.setType("Extended color light");
AsyncResultWrapper<DiscoveryResult> resultWrapper = new AsyncResultWrapper<DiscoveryResult>();
registerDiscoveryListener(new DiscoveryListener() {
@Override
public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
resultWrapper.set(result);
}
@Override
public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
}
@Override
public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
return null;
}
});
discoveryService.onLightAdded(null, light);
waitForAssert(() -> {
assertTrue(resultWrapper.isSet());
});
final DiscoveryResult result = resultWrapper.getWrappedObject();
assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
assertThat(result.getThingUID().toString(), is("hue:0210:testBridge:" + light.getId()));
assertThat(result.getThingTypeUID(), is(THING_TYPE_EXTENDED_COLOR_LIGHT));
assertThat(result.getBridgeUID(), is(hueBridge.getUID()));
assertThat(result.getProperties().get(LIGHT_ID), is(light.getId()));
}
use of org.eclipse.smarthome.test.AsyncResultWrapper in project smarthome by eclipse.
the class HueLightDiscoveryServiceOSGiTest method startSearchIsCalled.
@Test
public void startSearchIsCalled() {
final AtomicBoolean searchHasBeenTriggered = new AtomicBoolean(false);
AsyncResultWrapper<String> addressWrapper = new AsyncResultWrapper<String>();
AsyncResultWrapper<String> bodyWrapper = new AsyncResultWrapper<String>();
MockedHttpClient mockedHttpClient = new MockedHttpClient() {
@Override
public Result put(String address, String body) throws IOException {
addressWrapper.set(address);
bodyWrapper.set(body);
return new Result("", 200);
}
@Override
public Result get(String address) throws IOException {
if (address.endsWith("testUserName")) {
String body = "{\"lights\":{}}";
return new Result(body, 200);
} else {
return new Result("", 404);
}
}
@Override
public Result post(String address, String body) throws IOException {
if (address.endsWith("lights")) {
String bodyReturn = "{\"success\": {\"/lights\": \"Searching for new devices\"}}";
searchHasBeenTriggered.set(true);
return new Result(bodyReturn, 200);
} else {
return new Result("", 404);
}
}
};
installHttpClientMock(hueBridgeHandler, mockedHttpClient);
ThingStatusInfo online = ThingStatusInfoBuilder.create(ThingStatus.ONLINE, ThingStatusDetail.NONE).build();
waitForAssert(() -> {
assertThat(hueBridge.getStatusInfo(), is(online));
});
discoveryService.startScan();
waitForAssert(() -> {
assertTrue(searchHasBeenTriggered.get());
});
}
Aggregations