use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.
the class ItemResourceOSGiTest method setup.
@Before
public void setup() {
initMocks(this);
itemResource = getService(ItemResource.class);
itemResource.uriInfo = mock(UriInfo.class);
registerVolatileStorageService();
managedItemProvider = getService(ManagedItemProvider.class);
item1 = new SwitchItem(ITEM_NAME1);
item2 = new SwitchItem(ITEM_NAME2);
item3 = new DimmerItem(ITEM_NAME3);
when(itemProvider.getAll()).thenReturn(Arrays.asList(item1, item2, item3));
registerService(itemProvider);
}
use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.
the class ItemResourceOSGiTest method shouldIncludeRequestedFieldsOnly.
@Test
public void shouldIncludeRequestedFieldsOnly() throws Exception {
JsonParser parser = new JsonParser();
managedItemProvider.add(new SwitchItem("Switch"));
itemResource.addTag("Switch", "MyTag");
Response response = itemResource.getItems(null, null, "MyTag", false, "type,name");
JsonElement result = parser.parse(IOUtils.toString((InputStream) response.getEntity()));
JsonElement expected = parser.parse("[{type: \"Switch\", name: \"Switch\"}]");
assertEquals(expected, result);
}
use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.
the class ItemResourceOSGiTest method shouldAddAndRemoveTags.
@Test
public void shouldAddAndRemoveTags() throws Exception {
managedItemProvider.add(new SwitchItem("Switch"));
Response response = itemResource.getItems(null, null, "MyTag", false, null);
assertThat(readItemNamesFromResponse(response), hasSize(0));
itemResource.addTag("Switch", "MyTag");
response = itemResource.getItems(null, null, "MyTag", false, null);
assertThat(readItemNamesFromResponse(response), hasSize(1));
itemResource.removeTag("Switch", "MyTag");
response = itemResource.getItems(null, null, "MyTag", false, null);
assertThat(readItemNamesFromResponse(response), hasSize(0));
}
use of org.eclipse.smarthome.core.library.items.SwitchItem in project smarthome by eclipse.
the class ItemResourceOSGiTest method shouldProvideReturnCodesForTagHandling.
@Test
public void shouldProvideReturnCodesForTagHandling() {
Response response = itemResource.addTag("Switch", "MyTag");
assertThat(response.getStatus(), is(Status.NOT_FOUND.getStatusCode()));
response = itemResource.removeTag("Switch", "MyTag");
assertThat(response.getStatus(), is(Status.NOT_FOUND.getStatusCode()));
unregisterService(itemProvider);
when(itemProvider.getAll()).thenReturn(Collections.singletonList(new SwitchItem("UnmanagedItem")));
registerService(itemProvider);
response = itemResource.addTag("UnmanagedItem", "MyTag");
assertThat(response.getStatus(), is(Status.METHOD_NOT_ALLOWED.getStatusCode()));
}
Aggregations