-
-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[discovery] Added validation for relation between ThingUID and BridgeUID #1481
Merged
kaikreuzer
merged 2 commits into
openhab:master
from
cweitkamp:feature-discovery-thinguid-validation
Sep 3, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
104 changes: 104 additions & 0 deletions
104
...discovery/src/test/java/org/openhab/core/config/discovery/DiscoveryResultBuilderTest.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,104 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* 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.openhab.core.config.discovery; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.collection.IsMapContaining.hasEntry; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.thing.ThingUID; | ||
|
||
/** | ||
* Tests the {@link DiscoveryResultBuilder}. | ||
* | ||
* @author Christoph Weitkamp - Initial contribution | ||
*/ | ||
public class DiscoveryResultBuilderTest { | ||
|
||
private static final String BINDING_ID = "bindingId"; | ||
private static final ThingUID BRIDGE_UID = new ThingUID(new ThingTypeUID(BINDING_ID, "bridgeTypeId"), "bridgeId"); | ||
private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID(BINDING_ID, "thingTypeId"); | ||
private static final ThingUID THING_UID = new ThingUID(THING_TYPE_UID, BRIDGE_UID, "thingId"); | ||
private static final String KEY1 = "key1"; | ||
private static final String KEY2 = "key2"; | ||
private static final String VALUE1 = "value1"; | ||
private static final String VALUE2 = "value2"; | ||
private final Map<String, Object> properties = new HashMap<String, Object>() { | ||
private static final long serialVersionUID = 1L; | ||
{ | ||
put(KEY1, VALUE1); | ||
put(KEY2, VALUE2); | ||
} | ||
}; | ||
private DiscoveryResultBuilder builder; | ||
private DiscoveryResult discoveryResult; | ||
|
||
@Before | ||
public void setup() { | ||
builder = DiscoveryResultBuilder.create(THING_UID).withThingType(THING_TYPE_UID).withProperties(properties) | ||
.withRepresentationProperty(KEY1).withLabel("Test"); | ||
discoveryResult = builder.build(); | ||
} | ||
|
||
@Test | ||
public void testDiscoveryResultBuilder() { | ||
assertThat(discoveryResult.getThingUID(), is(THING_UID)); | ||
assertThat(discoveryResult.getThingTypeUID(), is(THING_TYPE_UID)); | ||
assertThat(discoveryResult.getBindingId(), is(BINDING_ID)); | ||
assertThat(discoveryResult.getLabel(), is("Test")); | ||
assertThat(discoveryResult.getProperties().size(), is(2)); | ||
assertThat(discoveryResult.getProperties(), hasEntry(KEY1, VALUE1)); | ||
assertThat(discoveryResult.getProperties(), hasEntry(KEY2, VALUE2)); | ||
assertThat(discoveryResult.getRepresentationProperty(), is(KEY1)); | ||
assertThat(discoveryResult.getTimeToLive(), is(DiscoveryResult.TTL_UNLIMITED)); | ||
} | ||
|
||
@Test | ||
public void testDiscoveryResultBuilderWithTTL() { | ||
DiscoveryResult otherDiscoveryResult = builder.withTTL(100L).build(); | ||
|
||
assertThat(otherDiscoveryResult.getTimeToLive(), is(100L)); | ||
} | ||
|
||
@Test | ||
public void testDiscoveryResultBuilderWithMatchingBridge() { | ||
DiscoveryResult otherDiscoveryResult = builder.withBridge(BRIDGE_UID).build(); | ||
|
||
assertThat(otherDiscoveryResult.getBridgeUID(), is(BRIDGE_UID)); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testDiscoveryResultBuilderWithBridge() { | ||
@SuppressWarnings("unused") | ||
DiscoveryResult otherDiscoveryResult = DiscoveryResultBuilder | ||
.create(new ThingUID(THING_TYPE_UID, "otherThingId")).withBridge(BRIDGE_UID).build(); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void subsequentBuildsCreateIndependentDiscoveryResults() { | ||
DiscoveryResult otherDiscoveryResult = builder.withLabel("Second Test").withProperties(Collections.emptyMap()) | ||
.build(); | ||
|
||
assertThat(otherDiscoveryResult.getLabel(), is(not(discoveryResult.getLabel()))); | ||
assertThat(otherDiscoveryResult.getProperties().size(), is(not(discoveryResult.getProperties().size()))); | ||
} | ||
} |
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
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
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 is this test ignored?
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.
To streamline our builders (following eclipse-archived/smarthome#5929) I first changed the behavior of the
withProperties(Map<String, Object>)
method to replace existing properties map by the one set. This has been reverted after #1481 (comment) and thus the test is failing now. Will come up with a follow-up PR if the change should be applied at all to separate it from this feature.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.
Have a look here for the changes I am talking about.