Skip to content

Commit

Permalink
Parameterized tests for most cases
Browse files Browse the repository at this point in the history
  • Loading branch information
codepitbull committed Aug 8, 2024
1 parent ea9a0c4 commit 5bab5a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.hivemq.edge.adapters.etherip.model.EtherIpDataType;
import com.hivemq.edge.adapters.etherip.model.EtherIpDataTypeFactory;
import etherip.EtherNetIP;
import etherip.data.CipException;
import etherip.types.CIPData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -128,6 +129,14 @@ public void poll(
.forEach(it -> pollingOutput.addDataPoint(tagAddress, it.getValue()));

pollingOutput.finish();
} catch (CipException e) {
if (e.getStatusCode() == 0x04) {
LOG.warn("Tag '{}' doesn't exist on device.", tagAddress, e);
pollingOutput.fail(e, "Tag '" + tagAddress + "' doesn't exist on device");
} else {
LOG.warn("Problem accessing tag '{}' on device.", tagAddress, e);
pollingOutput.fail(e, "Problem accessing tag '" + tagAddress + "' on device.");
}
} catch (Exception e) {
LOG.warn("An exception occurred while reading tag '{}'.", tagAddress, e);
pollingOutput.fail(e, "An exception occurred while reading tag '" + tagAddress + "'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import com.hivemq.edge.adapters.etherip.model.EtherIpAdapterConfig;
import com.hivemq.edge.adapters.etherip.model.EtherIpDataTypes;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.InstanceOfAssertFactory;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -27,26 +25,28 @@
@Tag(TAG_REQUIRES_VPN)
public class EtherIpPollingProtocolAdapterIT {

private static String TAG_PRORGAM = "program:MainProgram.test_tag";
private static String TAG_INT = "dev_int_tag";
private static String TAG_BOOL = "dev_bool_tag";
private static String TAG_REAL = "dev_real_tag";
private static String TAG_STRING = "dev_string_tag";
private static String TAG_INT = "at_int_tag";
private static String TAG_BOOL = "at_bool_tag";
private static String TAG_PROGRAM_BOOL_TRUE = "program:MainProgram.dev_bool_tag_t";
private static String TAG_PROGRAM_BOOL_FALSE = "program:MainProgram.dev_bool_tag_f";
private static String TAG_REAL = "at_real_tag";
private static String TAG_STRING = "at_string_tag";

private static final String HOST = "172.16.10.60";

public static Stream<Arguments> provideStringsForIsBlank() {
public static Stream<Arguments> tagsToExpectedValues() {
return Stream.of(
Arguments.of(TAG_INT, EtherIpDataTypes.DATA_TYPE.INT, TAG_INT + ":INT", 3),
Arguments.of(TAG_BOOL, EtherIpDataTypes.DATA_TYPE.BOOL, TAG_BOOL + ":BOOL", true),
Arguments.of(TAG_PROGRAM_BOOL_TRUE, EtherIpDataTypes.DATA_TYPE.BOOL, TAG_PROGRAM_BOOL_TRUE + ":BOOL", true),
Arguments.of(TAG_PROGRAM_BOOL_FALSE, EtherIpDataTypes.DATA_TYPE.BOOL, TAG_PROGRAM_BOOL_FALSE + ":BOOL", false),
Arguments.of(TAG_STRING, EtherIpDataTypes.DATA_TYPE.STRING, TAG_STRING + ":STRING", "test"),
Arguments.of(TAG_PRORGAM, EtherIpDataTypes.DATA_TYPE.DINT, TAG_PRORGAM + ":DINT", 17L),
Arguments.of(TAG_REAL, EtherIpDataTypes.DATA_TYPE.REAL, TAG_REAL + ":REAL", 5.59)
);
}

@ParameterizedTest
@MethodSource("provideStringsForIsBlank")
@MethodSource("tagsToExpectedValues")
public void test_parameterized(String tagAddress, EtherIpDataTypes.DATA_TYPE tagType, String expectedName, Object expectedValue) {
EtherIpAdapterConfig config = mock(EtherIpAdapterConfig.class);
when(config.getHost()).thenReturn(HOST);
Expand Down

0 comments on commit 5bab5a3

Please sign in to comment.