|
14 | 14 |
|
15 | 15 | import static org.mockito.ArgumentMatchers.any;
|
16 | 16 | import static org.mockito.ArgumentMatchers.argThat;
|
| 17 | +import static org.mockito.Mockito.times; |
17 | 18 | import static org.mockito.Mockito.verify;
|
18 | 19 | import static org.mockito.Mockito.when;
|
19 | 20 |
|
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Set; |
20 | 24 | import java.util.concurrent.ExecutionException;
|
21 | 25 | import java.util.concurrent.TimeoutException;
|
22 | 26 |
|
23 | 27 | import org.eclipse.jdt.annotation.NonNullByDefault;
|
| 28 | +import org.junit.jupiter.api.Tag; |
24 | 29 | import org.junit.jupiter.api.Test;
|
| 30 | +import org.junit.jupiter.api.TestInfo; |
25 | 31 | import org.junit.jupiter.params.ParameterizedTest;
|
26 | 32 | import org.junit.jupiter.params.provider.MethodSource;
|
27 | 33 | import org.openhab.binding.boschshc.internal.devices.bridge.dto.Device;
|
|
42 | 48 | public abstract class AbstractBoschSHCDeviceHandlerTest<T extends BoschSHCDeviceHandler>
|
43 | 49 | extends AbstractBoschSHCHandlerTest<T> {
|
44 | 50 |
|
| 51 | + protected static final String TAG_LEGACY_LOCATION_PROPERTY = "LegacyLocationProperty"; |
| 52 | + protected static final String TAG_LOCATION_PROPERTY = "LocationProperty"; |
| 53 | + protected static final String DEFAULT_ROOM_ID = "hz_1"; |
| 54 | + |
45 | 55 | @Override
|
46 | 56 | protected void configureDevice(Device device) {
|
47 | 57 | super.configureDevice(device);
|
48 | 58 |
|
49 | 59 | device.id = getDeviceID();
|
| 60 | + device.roomId = DEFAULT_ROOM_ID; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + protected void beforeHandlerInitialization(TestInfo testInfo) { |
| 65 | + super.beforeHandlerInitialization(testInfo); |
| 66 | + Set<String> tags = testInfo.getTags(); |
| 67 | + if (tags.contains(TAG_LEGACY_LOCATION_PROPERTY) || tags.contains(TAG_LOCATION_PROPERTY)) { |
| 68 | + Map<String, String> properties = new HashMap<>(); |
| 69 | + when(getThing().getProperties()).thenReturn(properties); |
| 70 | + |
| 71 | + if (tags.contains(TAG_LEGACY_LOCATION_PROPERTY)) { |
| 72 | + properties.put(BoschSHCBindingConstants.PROPERTY_LOCATION_LEGACY, "Living Room"); |
| 73 | + } |
| 74 | + |
| 75 | + if (tags.contains(TAG_LOCATION_PROPERTY)) { |
| 76 | + when(getBridgeHandler().resolveRoomId(DEFAULT_ROOM_ID)).thenReturn("Kitchen"); |
| 77 | + } |
| 78 | + } |
50 | 79 | }
|
51 | 80 |
|
52 | 81 | @Override
|
@@ -80,4 +109,44 @@ void initializeHandleExceptionDuringDeviceInfoRestCall(Exception exception)
|
80 | 109 | argThat(status -> status.getStatus().equals(ThingStatus.OFFLINE)
|
81 | 110 | && status.getStatusDetail().equals(ThingStatusDetail.CONFIGURATION_ERROR)));
|
82 | 111 | }
|
| 112 | + |
| 113 | + @Tag(TAG_LEGACY_LOCATION_PROPERTY) |
| 114 | + @Test |
| 115 | + protected void deleteLegacyLocationProperty() { |
| 116 | + verify(getThing()).setProperty(BoschSHCBindingConstants.PROPERTY_LOCATION_LEGACY, null); |
| 117 | + verify(getCallback()).thingUpdated(getThing()); |
| 118 | + } |
| 119 | + |
| 120 | + @Tag(TAG_LOCATION_PROPERTY) |
| 121 | + @Test |
| 122 | + protected void locationPropertyDidNotChange() { |
| 123 | + verify(getThing()).setProperty(BoschSHCBindingConstants.PROPERTY_LOCATION, "Kitchen"); |
| 124 | + verify(getCallback()).thingUpdated(getThing()); |
| 125 | + |
| 126 | + getThing().getProperties().put(BoschSHCBindingConstants.PROPERTY_LOCATION, "Kitchen"); |
| 127 | + |
| 128 | + // re-initialize |
| 129 | + getFixture().initialize(); |
| 130 | + |
| 131 | + verify(getThing()).setProperty(BoschSHCBindingConstants.PROPERTY_LOCATION, "Kitchen"); |
| 132 | + verify(getCallback()).thingUpdated(getThing()); |
| 133 | + } |
| 134 | + |
| 135 | + @Tag(TAG_LOCATION_PROPERTY) |
| 136 | + @Test |
| 137 | + protected void locationPropertyDidChange() { |
| 138 | + verify(getThing()).setProperty(BoschSHCBindingConstants.PROPERTY_LOCATION, "Kitchen"); |
| 139 | + verify(getCallback()).thingUpdated(getThing()); |
| 140 | + |
| 141 | + getThing().getProperties().put(BoschSHCBindingConstants.PROPERTY_LOCATION, "Kitchen"); |
| 142 | + |
| 143 | + getDevice().roomId = "hz_2"; |
| 144 | + when(getBridgeHandler().resolveRoomId("hz_2")).thenReturn("Dining Room"); |
| 145 | + |
| 146 | + // re-initialize |
| 147 | + getFixture().initialize(); |
| 148 | + |
| 149 | + verify(getThing()).setProperty(BoschSHCBindingConstants.PROPERTY_LOCATION, "Dining Room"); |
| 150 | + verify(getCallback(), times(2)).thingUpdated(getThing()); |
| 151 | + } |
83 | 152 | }
|
0 commit comments