This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 780
[Core] Added item metadata infrastructure #4390
Merged
Merged
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ce584a8
added metadata infrastructure
kaikreuzer 59864a6
Introduced AbstractUID
9f19a43
[metadata] turned MetadataKey into a AbstractUID
0d60100
[metadata] minor cleanups
f49460a
[metadata] Cleanup in MetadataRegistry based on ManagedItemProvider only
173e575
[metadata] implement equals/hashCode in Metadata
6d6b8e5
[metadata] fix metadata removal in GenericItemProvider
ba34419
[metadata] made GenericMetadataProvider thread-safe, fixed removal
a4bd749
added UoM to model.item.test launch config
107254d
[metadata] optional metadata configuration, immutable
ec38404
[metadata] handle update and exceptional cases in ItemResource
fc6a80e
[metadata] added tests for metadata
07e4b69
[metadata] added a section to the item concept documentation
2b7738f
[metadata] added missing log statements
eb742c3
protect AbstractUID segments from external tampering
4d23ff0
hide managed metadata provider implementation in internal package
cf8fcf0
allow filtering config descriptions for a specific scheme
4b365a2
[metadata] added missing @Nullable annotation for the namespace selector
f59c385
incorporated review feedback
5924264
[metadata] support config descriptions for meta-data
5a97015
[metadata] updated license headers
dbc48fc
[metadata] export config.items package
51dd700
[metadata] review feedback on config description API
d478139
fixed illegal list modification in GenericThingProvider
a37b32b
review feedback: renamed method in ChannelUID
4d13116
[metadata] pour some magic on items
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
...est/src/test/java/org/eclipse/smarthome/core/internal/items/MetadataRegistryImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.smarthome.core.internal.items; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
import java.util.Collections; | ||
|
||
import org.eclipse.smarthome.core.common.registry.ProviderChangeListener; | ||
import org.eclipse.smarthome.core.items.Item; | ||
import org.eclipse.smarthome.core.items.ManagedItemProvider; | ||
import org.eclipse.smarthome.core.items.ManagedMetadataProvider; | ||
import org.eclipse.smarthome.core.items.Metadata; | ||
import org.eclipse.smarthome.core.items.MetadataKey; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.ServiceEvent; | ||
import org.osgi.framework.ServiceListener; | ||
import org.osgi.framework.ServiceReference; | ||
|
||
/** | ||
* @author Simon Kaufmann - initial contribution and API | ||
*/ | ||
public class MetadataRegistryImplTest { | ||
|
||
private static final String ITEM_NAME = "itemName"; | ||
|
||
@SuppressWarnings("rawtypes") | ||
private @Mock ServiceReference managedProviderRef; | ||
private @Mock BundleContext bundleContext; | ||
private @Mock ManagedItemProvider itemProvider; | ||
private @Mock ManagedMetadataProvider managedProvider; | ||
private @Mock Item item; | ||
|
||
private ServiceListener providerTracker; | ||
|
||
private MetadataRegistryImpl registry; | ||
|
||
private ProviderChangeListener<Item> providerChangeListener; | ||
|
||
@Before | ||
@SuppressWarnings("unchecked") | ||
public void setup() throws Exception { | ||
initMocks(this); | ||
|
||
when(bundleContext.getService(same(managedProviderRef))).thenReturn(managedProvider); | ||
|
||
when(item.getName()).thenReturn(ITEM_NAME); | ||
|
||
registry = new MetadataRegistryImpl(); | ||
|
||
registry.setManagedItemProvider(itemProvider); | ||
registry.setManagedProvider(managedProvider); | ||
registry.activate(bundleContext); | ||
|
||
ArgumentCaptor<ServiceListener> captor = ArgumentCaptor.forClass(ServiceListener.class); | ||
verify(bundleContext).addServiceListener(captor.capture(), any()); | ||
providerTracker = captor.getValue(); | ||
providerTracker.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, managedProviderRef)); | ||
|
||
ArgumentCaptor<ProviderChangeListener<Item>> captorChangeListener = ArgumentCaptor | ||
.forClass(ProviderChangeListener.class); | ||
verify(itemProvider).addProviderChangeListener(captorChangeListener.capture()); | ||
providerChangeListener = captorChangeListener.getValue(); | ||
} | ||
|
||
@Test | ||
public void testManagedItemProviderChangeListenerRegistration() { | ||
verify(itemProvider).addProviderChangeListener(any()); | ||
verifyNoMoreInteractions(itemProvider); | ||
|
||
registry.unsetManagedItemProvider(itemProvider); | ||
verify(itemProvider).removeProviderChangeListener(any()); | ||
verifyNoMoreInteractions(itemProvider); | ||
} | ||
|
||
@Test | ||
public void testRemoved() { | ||
providerChangeListener.removed(itemProvider, item); | ||
verify(managedProvider).removeItemMetadata(eq(ITEM_NAME)); | ||
} | ||
|
||
@Test | ||
public void testGet_empty() throws Exception { | ||
MetadataKey key = new MetadataKey("namespace", "itemName"); | ||
|
||
Metadata res = registry.get(key); | ||
assertNull(res); | ||
} | ||
|
||
@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()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...e.smarthome.core.test/src/test/java/org/eclipse/smarthome/core/items/MetadataKeyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.smarthome.core.items; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* @author Simon Kaufmann - initial contribution and API | ||
*/ | ||
public class MetadataKeyTest { | ||
|
||
@Test | ||
public void testGetNamespace() { | ||
assertEquals("namespace", new MetadataKey("namespace", "itemName").getNamespace()); | ||
} | ||
|
||
@Test | ||
public void testGetItemName() { | ||
assertEquals("itemName", new MetadataKey("namespace", "itemName").getItemName()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does getArray now return a List?
You might want to rename the method.