Search in sources :

Example 6 with MetadataKey

use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.

the class ItemResourceOSGiTest method testRemoveMetadata_unmanagedMetadata.

@Test
public void testRemoveMetadata_unmanagedMetadata() {
    MetadataProvider provider = mock(MetadataProvider.class);
    when(provider.getAll()).thenReturn(Collections.singleton(new Metadata(new MetadataKey("namespace", ITEM_NAME1), "some value", null)));
    registerService(provider);
    Response response = itemResource.removeMetadata(ITEM_NAME1, "namespace");
    assertEquals(409, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) MetadataProvider(org.eclipse.smarthome.core.items.MetadataProvider) Metadata(org.eclipse.smarthome.core.items.Metadata) MetadataKey(org.eclipse.smarthome.core.items.MetadataKey) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 7 with MetadataKey

use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.

the class MetadataRegistryImplTest method testGet.

@Test
public void testGet() throws Exception {
    MetadataKey key = new MetadataKey("namespace", "itemName");
    registry.added(managedProvider, new Metadata(key, "value", Collections.emptyMap()));
    registry.added(managedProvider, new Metadata(new MetadataKey("other", "itemName"), "other", Collections.emptyMap()));
    registry.added(managedProvider, new Metadata(new MetadataKey("namespace", "other"), "other", Collections.emptyMap()));
    Metadata res = registry.get(key);
    assertNotNull(res);
    assertEquals("value", res.getValue());
    assertEquals("namespace", res.getUID().getNamespace());
    assertEquals("itemName", res.getUID().getItemName());
}
Also used : Metadata(org.eclipse.smarthome.core.items.Metadata) MetadataKey(org.eclipse.smarthome.core.items.MetadataKey) Test(org.junit.Test)

Example 8 with MetadataKey

use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.

the class AbstractItemEventSubscriberOSGiTest method setup.

@Before
public void setup() {
    initMocks(this);
    eventPublisher = getService(EventPublisher.class);
    assertNotNull(eventPublisher);
    when(itemProvider.getAll()).thenReturn(Collections.singletonList(new SwitchItem(ITEM_NAME)));
    registerService(itemProvider);
    EventSubscriber itemEventSubscriber = new AbstractItemEventSubscriber() {

        @Override
        protected void receiveCommand(ItemCommandEvent event) {
            commandEvent = event;
        }

        @Override
        protected void receiveUpdate(ItemStateEvent event) {
            updateEvent = event;
        }
    };
    registerService(itemEventSubscriber, EventSubscriber.class.getName());
    when(mockMetadataProvider.getAll()).thenReturn(Collections.singletonList(new Metadata(new MetadataKey("autoupdate", ITEM_NAME), Boolean.toString(false), null)));
    registerService(mockMetadataProvider);
}
Also used : EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) Metadata(org.eclipse.smarthome.core.items.Metadata) MetadataKey(org.eclipse.smarthome.core.items.MetadataKey) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) Before(org.junit.Before)

Example 9 with MetadataKey

use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.

the class GenericMetadataProvider method addMetadata.

/**
 * Adds metadata to this provider
 *
 * @param bindingType
 * @param itemName
 * @param configuration
 */
public void addMetadata(String bindingType, String itemName, String value, @Nullable Map<String, Object> configuration) {
    MetadataKey key = new MetadataKey(bindingType, itemName);
    Metadata md = new Metadata(key, value, configuration);
    try {
        lock.writeLock().lock();
        metadata.add(md);
    } finally {
        lock.writeLock().unlock();
    }
    notifyListenersAboutAddedElement(md);
}
Also used : Metadata(org.eclipse.smarthome.core.items.Metadata) MetadataKey(org.eclipse.smarthome.core.items.MetadataKey)

Example 10 with MetadataKey

use of org.eclipse.smarthome.core.items.MetadataKey in project smarthome by eclipse.

the class MetadataRegistryImplTest method testGet_empty.

@Test
public void testGet_empty() throws Exception {
    MetadataKey key = new MetadataKey("namespace", "itemName");
    Metadata res = registry.get(key);
    assertNull(res);
}
Also used : Metadata(org.eclipse.smarthome.core.items.Metadata) MetadataKey(org.eclipse.smarthome.core.items.MetadataKey) Test(org.junit.Test)

Aggregations

MetadataKey (org.eclipse.smarthome.core.items.MetadataKey)15 Metadata (org.eclipse.smarthome.core.items.Metadata)13 Test (org.junit.Test)6 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)5 GenericItem (org.eclipse.smarthome.core.items.GenericItem)4 GroupItem (org.eclipse.smarthome.core.items.GroupItem)4 Item (org.eclipse.smarthome.core.items.Item)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Path (javax.ws.rs.Path)2 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)2 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)2 JsonObject (com.google.gson.JsonObject)1 BigDecimal (java.math.BigDecimal)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1