Search in sources :

Example 21 with SwitchItem

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);
}
Also used : ManagedItemProvider(org.eclipse.smarthome.core.items.ManagedItemProvider) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) UriInfo(javax.ws.rs.core.UriInfo) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) Before(org.junit.Before)

Example 22 with SwitchItem

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);
}
Also used : Response(javax.ws.rs.core.Response) JsonElement(com.google.gson.JsonElement) InputStream(java.io.InputStream) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) JsonParser(com.google.gson.JsonParser) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 23 with SwitchItem

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));
}
Also used : Response(javax.ws.rs.core.Response) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 24 with SwitchItem

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()));
}
Also used : Response(javax.ws.rs.core.Response) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)24 Test (org.junit.Test)17 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)16 ArithmeticGroupFunction (org.eclipse.smarthome.core.library.types.ArithmeticGroupFunction)11 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)9 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)9 Before (org.junit.Before)9 GroupItem (org.eclipse.smarthome.core.items.GroupItem)7 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)7 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)7 State (org.eclipse.smarthome.core.types.State)7 Item (org.eclipse.smarthome.core.items.Item)6 StringType (org.eclipse.smarthome.core.library.types.StringType)6 Temperature (javax.measure.quantity.Temperature)5 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)5 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4