Skip to content

Commit

Permalink
openhab#15 Write test for open/close gate and garage door
Browse files Browse the repository at this point in the history
  • Loading branch information
magx2 committed May 17, 2019
1 parent fe3f99c commit 6d54914
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ protected void handleHsbCommand(final ChannelUID channelUID, final HSBType comma
protected void handleOpenClosedCommand(final ChannelUID channelUID, final OpenClosedType command) throws ApiException {
final ChannelInfo channelInfo = ChannelInfoParser.PARSER.parse(channelUID);
final int channelId = channelInfo.getChannelId();
handleOneZeroCommand(channelId, command == OpenClosedType.OPEN, OPEN, CLOSE);
final pl.grzeslowski.jsupla.api.generated.model.Channel channel = queryForChannel(channelId);
switch (channel.getFunction().getName()) {
case CONTROLLINGTHEGATE:
case CONTROLLINGTHEGARAGEDOOR:
handleOneZeroCommand(channelId, command == OpenClosedType.OPEN, OPEN, CLOSE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.lang3.reflect.FieldUtils;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
Expand Down Expand Up @@ -189,7 +190,7 @@ void setUpInternalInitialize() throws ApiException, IllegalAccessException {
}

@Test
@DisplayName("should send request to Supla cloud to turn light ON")
@DisplayName("should send request to Supla Cloud to turn light ON")
void lightChannelOn() throws Exception {

// given
Expand All @@ -205,7 +206,7 @@ void lightChannelOn() throws Exception {
}

@Test
@DisplayName("should send request to Supla cloud to turn light OFF")
@DisplayName("should send request to Supla Cloud to turn light OFF")
void lightChannelOff() throws Exception {

// given
Expand All @@ -221,7 +222,7 @@ void lightChannelOff() throws Exception {
}

@DisplayName("OPEN gate, garage")
@ParameterizedTest(name = "[{index}] should send request to Supla cloud to open {0}")
@ParameterizedTest(name = "[{index}] should send request to Supla Cloud to open {0}")
@ValueSource(strings = {"gateChannelId", "garageDoorChannelId"})
void gateChannelOn(String idFieldName) throws Exception {

Expand All @@ -238,7 +239,7 @@ void gateChannelOn(String idFieldName) throws Exception {
assertThat(value.getAction()).isEqualTo(OPEN);
}

@ParameterizedTest(name = "[{index}] should send request to Supla cloud to close {0}")
@ParameterizedTest(name = "[{index}] should send request to Supla Cloud to close {0}")
@ValueSource(strings = {"gateChannelId", "garageDoorChannelId"})
@DisplayName("CLOSE gate, garage")
void gateChannelOff(String idFieldName) throws Exception {
Expand All @@ -256,8 +257,44 @@ void gateChannelOff(String idFieldName) throws Exception {
assertThat(value.getAction()).isEqualTo(CLOSE);
}

@DisplayName("OPEN gate, garage")
@ParameterizedTest(name = "[{index}] should send request to Supla Cloud to open {0}")
@ValueSource(strings = {"gateChannelId", "garageDoorChannelId"})
void gateChannelOpen(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id);

// when
handler.handleOpenClosedCommand(channelUID, OpenClosedType.OPEN);

// then
verify(channelsCloudApi).executeAction(channelExecuteActionRequestCaptor.capture(), eq(id));
ChannelExecuteActionRequest value = channelExecuteActionRequestCaptor.getValue();
assertThat(value.getAction()).isEqualTo(OPEN);
}

@ParameterizedTest(name = "[{index}] should send request to Supla Cloud to close {0}")
@ValueSource(strings = {"gateChannelId", "garageDoorChannelId"})
@DisplayName("CLOSE gate, garage")
void gateChannelClose(String idFieldName) throws Exception {

// given
final int id = (int) FieldUtils.readDeclaredField(this, idFieldName, true);
final ChannelUID channelUID = buildChannelUID(id);

// when
handler.handleOpenClosedCommand(channelUID, OpenClosedType.CLOSED);

// then
verify(channelsCloudApi).executeAction(channelExecuteActionRequestCaptor.capture(), eq(id));
ChannelExecuteActionRequest value = channelExecuteActionRequestCaptor.getValue();
assertThat(value.getAction()).isEqualTo(CLOSE);
}

@Test
@DisplayName("should send request to Supla cloud to reveal roller shutter")
@DisplayName("should send request to Supla Cloud to reveal roller shutter")
void rollerShutterUp() throws Exception {

// given
Expand All @@ -273,7 +310,7 @@ void rollerShutterUp() throws Exception {
}

@Test
@DisplayName("should send request to Supla cloud to shut roller shutter")
@DisplayName("should send request to Supla Cloud to shut roller shutter")
void rollerShutterDown() throws Exception {

// given
Expand Down

0 comments on commit 6d54914

Please sign in to comment.