Skip to content

Commit

Permalink
Reset ip-address after retrieval of invocation counter from device
Browse files Browse the repository at this point in the history
Signed-off-by: Gerben Kroes <[email protected]>
  • Loading branch information
kroesctrl committed Oct 19, 2023
1 parent 3a86eaa commit 2ce5194
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ public InvocationCounterManager(
*/
public void initializeInvocationCounter(
final MessageMetadata messageMetadata, final DlmsDevice device) throws OsgpException {
this.initializeWithInvocationCounterStoredOnDevice(messageMetadata, device, null);

/*
* When the invocation counter is out of sync, the device closes the session.
* When the invocation counter has been initialized, the device closes the session.
* By setting the ip-address to null, the application will be forced to get a new ip-address.
* The meter will start a new session.
* This is done by the DlmsConnectionFactory in the method:
* this.domainHelperService.setIpAddressFromMessageMetadataOrSessionProvider
*/
device.setIpAddress(null);

this.initializeWithInvocationCounterStoredOnDevice(messageMetadata, device, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.mockito.ArgumentMatchers.isNotNull;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.refEq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -24,6 +25,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openmuc.jdlms.AttributeAddress;
Expand Down Expand Up @@ -75,15 +77,17 @@ void setUp() {
}

@Test
void initializeInvocationCounterForDeviceTaskExecuted() throws OsgpException {
this.device.setIpAddress(IP_ADDRESS);
void resetIpAddressAfterInitialize() throws OsgpException {
this.device = mock(DlmsDevice.class);

this.manager.initializeInvocationCounter(this.messageMetadata, this.device);

assertThat(this.device.getIpAddress()).isNull();
verify(this.connectionFactory, times(1))
final InOrder inOrder = inOrder(this.connectionFactory, this.device);
inOrder
.verify(this.connectionFactory, times(1))
.createAndHandlePublicClientConnection(
any(MessageMetadata.class), eq(this.device), isNull(), isNull(), any());
inOrder.verify(this.device).setIpAddress(null);
}

@Test
Expand Down

0 comments on commit 2ce5194

Please sign in to comment.