mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
Ignore illegal thing status updates from REMOVING (#2313)
* Ignore illegal thing status updates from REMOVING Ignore illegal thing status transitions from REMOVING instead of throwing IllegalArgumentException Signed-off-by: Björn Lange <blange@itemis.com>
This commit is contained in:
parent
0fe6b31f19
commit
6258268031
@ -122,6 +122,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
* @author Henning Sudbrock - Consider thing type properties when migrating to new thing type
|
* @author Henning Sudbrock - Consider thing type properties when migrating to new thing type
|
||||||
* @author Christoph Weitkamp - Added preconfigured ChannelGroupBuilder
|
* @author Christoph Weitkamp - Added preconfigured ChannelGroupBuilder
|
||||||
* @author Yordan Zhelev - Added thing disabling mechanism
|
* @author Yordan Zhelev - Added thing disabling mechanism
|
||||||
|
* @author Björn Lange - Ignore illegal thing status transitions instead of throwing IllegalArgumentException
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
@Component(immediate = true, service = { ThingTypeMigrationService.class, ThingManager.class })
|
@Component(immediate = true, service = { ThingTypeMigrationService.class, ThingManager.class })
|
||||||
@ -193,10 +194,11 @@ public class ThingManagerImpl
|
|||||||
|
|
||||||
if (ThingStatus.REMOVING.equals(oldStatusInfo.getStatus())
|
if (ThingStatus.REMOVING.equals(oldStatusInfo.getStatus())
|
||||||
&& !ThingStatus.REMOVED.equals(statusInfo.getStatus())) {
|
&& !ThingStatus.REMOVED.equals(statusInfo.getStatus())) {
|
||||||
// only allow REMOVING -> REMOVED transition, all others are illegal
|
// only allow REMOVING -> REMOVED transition, all others are ignored because they are illegal
|
||||||
throw new IllegalArgumentException(MessageFormat.format(
|
logger.debug(
|
||||||
"Illegal status transition from REMOVING to {0}, only REMOVED would have been allowed.",
|
"Ignoring illegal status transition for thing {} from REMOVING to {}, only REMOVED would have been allowed.",
|
||||||
statusInfo.getStatus()));
|
thing.getUID(), statusInfo.getStatus());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update thing status and send event about new status
|
// update thing status and send event about new status
|
||||||
|
@ -111,6 +111,7 @@ import org.osgi.service.component.ComponentContext;
|
|||||||
*
|
*
|
||||||
* @author Dennis Nobel - Initial contribution
|
* @author Dennis Nobel - Initial contribution
|
||||||
* @author Wouter Born - Migrate tests from Groovy to Java
|
* @author Wouter Born - Migrate tests from Groovy to Java
|
||||||
|
* @author Björn Lange - Ignore illegal thing status transitions instead of throwing IllegalArgumentException
|
||||||
*/
|
*/
|
||||||
public class ThingManagerOSGiTest extends JavaOSGiTest {
|
public class ThingManagerOSGiTest extends JavaOSGiTest {
|
||||||
|
|
||||||
@ -968,6 +969,45 @@ public class ThingManagerOSGiTest extends JavaOSGiTest {
|
|||||||
expectException(() -> state.callback.statusUpdated(thing, removedNone), IllegalArgumentException.class);
|
expectException(() -> state.callback.statusUpdated(thing, removedNone), IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void thingManagerIgnoresRestoringOfThingStatusFromRemoving() {
|
||||||
|
class ThingHandlerState {
|
||||||
|
ThingHandlerCallback callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ThingHandlerState state = new ThingHandlerState();
|
||||||
|
|
||||||
|
ThingHandler thingHandler = mock(ThingHandler.class);
|
||||||
|
|
||||||
|
managedThingProvider.add(thing);
|
||||||
|
|
||||||
|
doAnswer(new Answer<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
state.callback = (ThingHandlerCallback) invocation.getArgument(0);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(thingHandler).setCallback(any(ThingHandlerCallback.class));
|
||||||
|
when(thingHandler.getThing()).thenReturn(thing);
|
||||||
|
|
||||||
|
ThingHandlerFactory thingHandlerFactory = mock(ThingHandlerFactory.class);
|
||||||
|
when(thingHandlerFactory.supportsThingType(any(ThingTypeUID.class))).thenReturn(true);
|
||||||
|
when(thingHandlerFactory.registerHandler(any(Thing.class))).thenReturn(thingHandler);
|
||||||
|
|
||||||
|
registerService(thingHandlerFactory);
|
||||||
|
|
||||||
|
final ThingStatusInfo removingNone = ThingStatusInfoBuilder.create(ThingStatus.REMOVING, ThingStatusDetail.NONE)
|
||||||
|
.build();
|
||||||
|
final ThingStatusInfo onlineNone = ThingStatusInfoBuilder.create(ThingStatus.ONLINE, ThingStatusDetail.NONE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
thing.setStatusInfo(removingNone);
|
||||||
|
|
||||||
|
state.callback.statusUpdated(thing, onlineNone);
|
||||||
|
|
||||||
|
assertThat(thing.getStatusInfo(), is(removingNone));
|
||||||
|
}
|
||||||
|
|
||||||
private void expectException(Runnable runnable, Class<? extends Exception> exceptionType) {
|
private void expectException(Runnable runnable, Class<? extends Exception> exceptionType) {
|
||||||
try {
|
try {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
|
Loading…
Reference in New Issue
Block a user