[wemo] add annotations and remove usage of apache.commons.* (#9829)

* [wemo] add annotations and remove usage of apache.commons.*

Also-by: Wouter Born <github@maindrain.net>
Signed-off-by: Hans-Jörg Merk <github@hmerk.de>
This commit is contained in:
Hans-Jörg Merk
2021-04-08 22:46:46 +02:00
committed by GitHub
parent 8521756abb
commit fdada9a155
24 changed files with 905 additions and 883 deletions

View File

@@ -48,8 +48,8 @@ import org.openhab.core.thing.ThingUID;
public class WemoDiscoveryParticipantTest {
UpnpDiscoveryParticipant participant = new WemoDiscoveryParticipant();
private final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
private final String DEVICE_FRIENDLY_NAME = "Wemo Test";
private static final String DEVICE_UDN = GenericWemoOSGiTest.DEVICE_MANUFACTURER + "_3434xxx";
private static final String DEVICE_FRIENDLY_NAME = "Wemo Test";
RemoteDevice createUpnpDevice(String modelName)
throws MalformedURLException, ValidationException, URISyntaxException {

View File

@@ -28,10 +28,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
@@ -50,14 +48,14 @@ import org.openhab.core.types.RefreshType;
public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
// Thing information
private final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_STATE;
private final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_SOCKET;
private static final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_STATE;
private static final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private static final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_SOCKET;
// UPnP information
private final String MODEL_NAME = WemoBindingConstants.THING_TYPE_SOCKET.getId();
private final String SERVICE_ID = "basicevent";
private final String SERVICE_NUMBER = "1";
private static final String MODEL_NAME = WemoBindingConstants.THING_TYPE_SOCKET.getId();
private static final String SERVICE_ID = "basicevent";
private static final String SERVICE_NUMBER = "1";
@BeforeEach
public void setUp() throws IOException {
@@ -74,8 +72,7 @@ public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
throws MalformedURLException, URISyntaxException, ValidationException {
Command command = OnOffType.OFF;
WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller);
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
@@ -111,8 +108,7 @@ public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
throws MalformedURLException, URISyntaxException, ValidationException {
Command command = RefreshType.REFRESH;
WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller);
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.ONLINE));

View File

@@ -40,23 +40,23 @@ import org.openhab.core.types.State;
*/
public class WemoHandlerTest {
private final ThingTypeUID THING_TYPE = WemoBindingConstants.THING_TYPE_INSIGHT;
private final String THING_ID = "test";
private static final ThingTypeUID THING_TYPE = WemoBindingConstants.THING_TYPE_INSIGHT;
private static final String THING_ID = "test";
private MockWemoHandler handler;
private final String SERVICE_ID = "insight";
private final String PARAMS_NAME = "InsightParams";
private static final String SERVICE_ID = "insight";
private static final String PARAMS_NAME = "InsightParams";
private WemoInsightParams insightParams;
/** Used for all tests, where expected value is time in seconds **/
private final int TIME_PARAM = 4702;
private static final int TIME_PARAM = 4702;
/** Represents a state parameter, where 1 stays for ON and 0 stays for OFF **/
private final int STATE_PARAM = 1;
private static final int STATE_PARAM = 1;
/** Represents power in Wats **/
private final int POWER_PARAM = 54;
private static final int POWER_PARAM = 54;
private final Thing thing = mock(Thing.class);

View File

@@ -28,10 +28,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoLightHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoLightOSGiTestParent;
import org.openhab.core.library.types.IncreaseDecreaseType;
import org.openhab.core.library.types.OnOffType;
@@ -154,8 +152,7 @@ public class WemoLightHandlerOSGiTest extends GenericWemoLightOSGiTestParent {
String capitability) throws MalformedURLException, URISyntaxException, ValidationException {
Thing bridge = createBridge(BRIDGE_TYPE_UID);
WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller);
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(bridge.getStatus(), is(ThingStatus.ONLINE));

View File

@@ -28,10 +28,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jupnp.model.ValidationException;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.WemoMakerHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.binding.wemo.internal.test.GenericWemoOSGiTest;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.ChannelUID;
@@ -51,14 +49,14 @@ import org.openhab.core.types.RefreshType;
public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
// Specific Thing information
private final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_RELAY;
private final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_MAKER;
private static final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_RELAY;
private static final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private static final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_MAKER;
// Specific UpnP service information
private final String MODEL = THING_TYPE_UID.getId();
private final String BASIC_EVENT_SERVICE_ID = "basicevent";
private final String SERVICE_NUMBER = "1";
private static final String MODEL = THING_TYPE_UID.getId();
private static final String BASIC_EVENT_SERVICE_ID = "basicevent";
private static final String SERVICE_NUMBER = "1";
@BeforeEach
public void setUp() throws IOException {
@@ -75,8 +73,7 @@ public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
throws MalformedURLException, URISyntaxException, ValidationException {
Command command = OnOffType.OFF;
WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller);
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
@@ -111,8 +108,7 @@ public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
throws MalformedURLException, URISyntaxException, ValidationException {
Command command = RefreshType.REFRESH;
WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller);
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
waitForAssert(() -> {
assertThat(thing.getStatus(), is(ThingStatus.ONLINE));

View File

@@ -17,7 +17,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.AbstractWemoHandler;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
@@ -42,19 +41,19 @@ import org.openhab.core.thing.type.ChannelKind;
public class GenericWemoLightOSGiTestParent extends GenericWemoOSGiTest {
// Thing information
protected ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_MZ100;
protected ThingTypeUID BRIDGE_TYPE_UID = WemoBindingConstants.THING_TYPE_BRIDGE;
protected String WEMO_BRIDGE_ID = BRIDGE_TYPE_UID.getId();
protected String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_STATE;
protected String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
protected static final ThingTypeUID THING_TYPE_UID = WemoBindingConstants.THING_TYPE_MZ100;
protected static final ThingTypeUID BRIDGE_TYPE_UID = WemoBindingConstants.THING_TYPE_BRIDGE;
protected static final String WEMO_BRIDGE_ID = BRIDGE_TYPE_UID.getId();
protected static final String DEFAULT_TEST_CHANNEL = WemoBindingConstants.CHANNEL_STATE;
protected static final String DEFAULT_TEST_CHANNEL_TYPE = "Switch";
private final String WEMO_LIGHT_ID = THING_TYPE_UID.getId();
private static final String WEMO_LIGHT_ID = THING_TYPE_UID.getId();
// UPnP service information
protected String DEVICE_MODEL_NAME = WEMO_LIGHT_ID;
protected String SERVICE_ID = "bridge";
protected String SERVICE_NUMBER = "1";
protected String SERVLET_URL = DEVICE_CONTROL_PATH + SERVICE_ID + SERVICE_NUMBER;
protected static final String DEVICE_MODEL_NAME = WEMO_LIGHT_ID;
protected static final String SERVICE_ID = "bridge";
protected static final String SERVICE_NUMBER = "1";
protected static final String SERVLET_URL = DEVICE_CONTROL_PATH + SERVICE_ID + SERVICE_NUMBER;
private Bridge bridge;
@@ -71,8 +70,7 @@ public class GenericWemoLightOSGiTestParent extends GenericWemoOSGiTest {
}
@Override
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType,
WemoHttpCall wemoHttpCaller) {
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType) {
Configuration configuration = new Configuration();
configuration.put(WemoBindingConstants.DEVICE_ID, WEMO_LIGHT_ID);
@@ -91,7 +89,6 @@ public class GenericWemoLightOSGiTestParent extends GenericWemoOSGiTest {
ThingHandler handler = thing.getHandler();
if (handler != null) {
AbstractWemoHandler h = (AbstractWemoHandler) handler;
h.setWemoHttpCaller(wemoHttpCaller);
}
return thing;

View File

@@ -37,8 +37,10 @@ import org.jupnp.model.types.DeviceType;
import org.jupnp.model.types.ServiceId;
import org.jupnp.model.types.ServiceType;
import org.jupnp.model.types.UDN;
import org.mockito.Mockito;
import org.openhab.binding.wemo.internal.WemoBindingConstants;
import org.openhab.binding.wemo.internal.handler.AbstractWemoHandler;
import org.openhab.binding.wemo.internal.WemoHttpCallFactory;
import org.openhab.binding.wemo.internal.WemoUtil;
import org.openhab.binding.wemo.internal.http.WemoHttpCall;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.io.transport.upnp.UpnpIOService;
@@ -52,7 +54,6 @@ import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingRegistry;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.type.ChannelKind;
@@ -69,35 +70,39 @@ import org.openhab.core.thing.type.ChannelTypeUID;
*/
public abstract class GenericWemoOSGiTest extends JavaOSGiTest {
public static MockUpnpService mockUpnpService;
public static final String DEVICE_MANUFACTURER = "Belkin";
// This port is included in the run configuration
private final int ORG_OSGI_SERVICE_HTTP_PORT = 9090;
private static final int ORG_OSGI_SERVICE_HTTP_PORT = 9090;
// Thing information
protected String TEST_THING_ID = "TestThing";
protected static final String TEST_THING_ID = "TestThing";
// UPnP Device information
public static String DEVICE_UDN = "Test-1_0-22124";
public static final String DEVICE_UDN = "Test-1_0-22124";
private final String DEVICE_TYPE = "Test";
private final int DEVICE_VERSION = 1;
private final String DEVICE_URL = "http://127.0.0.1:" + ORG_OSGI_SERVICE_HTTP_PORT;
private final String DEVICE_DESCRIPTION_PATH = "/setup.xml";
private static final String DEVICE_TYPE = "Test";
private static final int DEVICE_VERSION = 1;
private static final String DEVICE_URL = "http://127.0.0.1:" + ORG_OSGI_SERVICE_HTTP_PORT;
private static final String DEVICE_DESCRIPTION_PATH = "/setup.xml";
protected final String DEVICE_FRIENDLY_NAME = "WeMo Test";
protected final String DEVICE_CONTROL_PATH = "/upnp/control/";
protected final ChannelTypeUID DEFAULT_CHANNEL_TYPE_UID = new ChannelTypeUID(
protected static final String DEVICE_FRIENDLY_NAME = "WeMo Test";
protected static final String DEVICE_CONTROL_PATH = "/upnp/control/";
protected static final ChannelTypeUID DEFAULT_CHANNEL_TYPE_UID = new ChannelTypeUID(
WemoBindingConstants.BINDING_ID + ":channelType");
protected ManagedThingProvider managedThingProvider;
protected UpnpIOService upnpIOService;
protected ThingRegistry thingRegistry;
protected WemoHttpCall mockCaller;
protected MockUpnpService mockUpnpService;
protected Thing thing;
protected void setUpServices() throws IOException {
WemoUtil.serviceAvailableFunction = (host, port) -> true;
// StorageService is required from the ManagedThingProvider
VolatileStorageService volatileStorageService = new VolatileStorageService();
registerService(volatileStorageService);
@@ -117,14 +122,17 @@ public abstract class GenericWemoOSGiTest extends JavaOSGiTest {
upnpIOService = getService(UpnpIOService.class);
assertThat(upnpIOService, is(notNullValue()));
mockCaller = Mockito.spy(new WemoHttpCall());
WemoHttpCallFactory wemoHttpCallFactory = () -> mockCaller;
registerService(wemoHttpCallFactory, WemoHttpCallFactory.class.getName());
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(
ChannelTypeBuilder.state(DEFAULT_CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
}
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType,
WemoHttpCall wemoHttpCaller) {
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType) {
Configuration configuration = new Configuration();
configuration.put(WemoBindingConstants.UDN, DEVICE_UDN);
@@ -138,13 +146,6 @@ public abstract class GenericWemoOSGiTest extends JavaOSGiTest {
.build();
managedThingProvider.add(thing);
ThingHandler handler = thing.getHandler();
if (handler != null) {
AbstractWemoHandler h = (AbstractWemoHandler) handler;
h.setWemoHttpCaller(wemoHttpCaller);
}
return thing;
}
@@ -153,8 +154,8 @@ public abstract class GenericWemoOSGiTest extends JavaOSGiTest {
UDN udn = new UDN(DEVICE_UDN);
URL deviceURL = new URL(DEVICE_URL + DEVICE_DESCRIPTION_PATH);
RemoteDeviceIdentity identity = new RemoteDeviceIdentity(udn, WemoBindingConstants.SUBSCRIPTION_DURATION,
deviceURL, new byte[1], null);
RemoteDeviceIdentity identity = new RemoteDeviceIdentity(udn,
WemoBindingConstants.SUBSCRIPTION_DURATION_SECONDS, deviceURL, new byte[1], null);
DeviceType type = new DeviceType(DEVICE_MANUFACTURER, DEVICE_TYPE, DEVICE_VERSION);
ManufacturerDetails manufacturerDetails = new ManufacturerDetails(DEVICE_MANUFACTURER);