Skip to content

Commit

Permalink
[modbus] verify defaults are used for undefined configuration parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
  • Loading branch information
ssalonen committed Feb 14, 2021
1 parent 8bd71b5 commit fbdeb73
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public void receive(Event event) {
private final Logger logger = LoggerFactory.getLogger(AbstractModbusOSGiTest.class);

protected @Mock @NonNullByDefault({}) ModbusManager mockedModbusManager;
protected @NonNullByDefault({}) ModbusManager realModbusManager;
protected @NonNullByDefault({}) ManagedThingProvider thingProvider;
protected @NonNullByDefault({}) ManagedItemProvider itemProvider;
protected @NonNullByDefault({}) ManagedItemChannelLinkProvider itemChannelLinkProvider;
protected @NonNullByDefault({}) ItemRegistry itemRegistry;
protected @NonNullByDefault({}) CoreItemFactory coreItemFactory;

private @NonNullByDefault({}) ModbusManager realModbusManager;
private Set<Item> addedItems = new HashSet<>();
private Set<Thing> addedThings = new HashSet<>();
private Set<ItemChannelLink> addedLinks = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

import java.util.Objects;

Expand Down Expand Up @@ -98,6 +98,18 @@ public void testTwoDifferentEndpointWithDifferentParameters() {

ModbusTcpThingHandler thingHandler = (ModbusTcpThingHandler) thing.getHandler();
assertNotNull(thingHandler);

EndpointPoolConfiguration expectedPoolConfiguration = new EndpointPoolConfiguration();
expectedPoolConfiguration.setConnectMaxTries(1);
expectedPoolConfiguration.setInterTransactionDelayMillis(1);

// defaults
expectedPoolConfiguration.setConnectTimeoutMillis(10_000);
expectedPoolConfiguration.setInterConnectDelayMillis(0);
expectedPoolConfiguration.setReconnectAfterMillis(0);

assertEquals(expectedPoolConfiguration, realModbusManager
.getEndpointPoolConfiguration(new ModbusTCPSlaveEndpoint("thisishost", 44, false)));
}
{
Configuration thingConfig = new Configuration();
Expand Down Expand Up @@ -148,6 +160,22 @@ public void testTwoIdenticalEndpointWithDifferentParameters() {
assertThat(thing.getStatus(), is(equalTo(ThingStatus.OFFLINE)));
assertThat(thing.getStatusInfo().getStatusDetail(), is(equalTo(ThingStatusDetail.CONFIGURATION_ERROR)));
}
{
//
// Ensure the right EndpointPoolConfiguration is still in place
//
EndpointPoolConfiguration expectedPoolConfiguration = new EndpointPoolConfiguration();
expectedPoolConfiguration.setConnectMaxTries(1);
expectedPoolConfiguration.setInterTransactionDelayMillis(1); // Note: not 100

// defaults
expectedPoolConfiguration.setConnectTimeoutMillis(10_000);
expectedPoolConfiguration.setInterConnectDelayMillis(0);
expectedPoolConfiguration.setReconnectAfterMillis(0);

assertEquals(expectedPoolConfiguration, realModbusManager
.getEndpointPoolConfiguration(new ModbusTCPSlaveEndpoint("thisishost", 44, false)));
}
}

@Test
Expand Down

0 comments on commit fbdeb73

Please sign in to comment.