Skip to content

Commit 866a696

Browse files
authored
Merge pull request #1709 from OSGP/feature/SMHE-2453_Bij_een_retry_de_actuele_ip_gegevens_gebruiken
Feature/smhe 2453 bij een retry de actuele ip gegevens gebruiken
2 parents ec5632d + 4312d6a commit 866a696

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

osgp/platform/osgp-core/src/test/java/org/opensmartgridplatform/core/application/services/DeviceResponseMessageServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/** test class for DeviceResponseMessageService */
3232
@ExtendWith(MockitoExtension.class)
33-
public class DeviceResponseMessageServiceTest {
33+
class DeviceResponseMessageServiceTest {
3434

3535
private static final String DOMAIN = "Domain";
3636
private static final String DOMAIN_VERSION = "1.0";
@@ -60,7 +60,7 @@ public class DeviceResponseMessageServiceTest {
6060

6161
/** test processMessage with a scheduled task that failed */
6262
@Test
63-
public void testProcessScheduledMessageFailed() {
63+
void testProcessScheduledMessageFailed() {
6464
final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
6565
final Calendar calendar = Calendar.getInstance();
6666
calendar.add(Calendar.DATE, 1);
@@ -89,7 +89,7 @@ public void testProcessScheduledMessageFailed() {
8989

9090
/** test processMessage with a scheduled task that must be retried */
9191
@Test
92-
public void testProcessScheduledMessageRetry() {
92+
void testProcessScheduledMessageRetry() {
9393
final String exceptionMessage = "message";
9494
this.testProcessScheduledMessageRetry(exceptionMessage, exceptionMessage);
9595
}
@@ -141,7 +141,7 @@ private void testProcessScheduledMessageRetry(
141141
* than 255 characters
142142
*/
143143
@Test
144-
public void testProcessScheduledMessageRetryWithTruncatedError() {
144+
void testProcessScheduledMessageRetryWithTruncatedError() {
145145
final String exceptionMessageWith255Characters = StringUtils.repeat('x', 255);
146146
final String tooLongExceptionMessage = exceptionMessageWith255Characters + "extra";
147147
this.testProcessScheduledMessageRetry(
@@ -150,7 +150,7 @@ public void testProcessScheduledMessageRetryWithTruncatedError() {
150150

151151
/** test processMessage with a scheduled task that has been successful */
152152
@Test
153-
public void testProcessScheduledMessageSuccess() {
153+
void testProcessScheduledMessageSuccess() {
154154
final ProtocolResponseMessage message =
155155
new ProtocolResponseMessage.Builder()
156156
.messageMetadata(MESSAGE_METADATA.builder().withScheduled(true).build())

osgp/platform/osgp-core/src/test/java/org/opensmartgridplatform/core/application/tasks/ScheduledTaskExecutorServiceTest.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void testMetadataOfScheduledTaskToRetryRequest() throws FunctionalException {
207207
final String deviceIdentification = "device-1";
208208
final String deviceModelCode = "E,M1,M2,M3,M4";
209209
final MessageMetadata messageMetadata =
210-
this.createMessageMetadata(deviceIdentification, deviceModelCode);
210+
this.createMessageMetadata(deviceIdentification, deviceModelCode, null);
211211
final ScheduledTask scheduledTask =
212212
new ScheduledTask(messageMetadata, DOMAIN, DOMAIN, DATA_OBJECT, INITIAL_SCHEDULED_TIME);
213213
final Device device = new Device();
@@ -241,6 +241,50 @@ void testMetadataOfScheduledTaskToRetryRequest() throws FunctionalException {
241241
assertThat(protocolRequestMessage.getDeviceModelCode()).isEqualTo(deviceModelCode);
242242
}
243243

244+
@Test
245+
void testRequestFromScheduledTaskIsCreatedWithLatestDeviceNetworkAddress()
246+
throws FunctionalException {
247+
final String deviceIdentification = "device-1";
248+
final String deviceModelCode = "E,M1,M2,M3,M4";
249+
final String oldNetworkAddress = "oldNetworkAddress";
250+
final String newNetworkAddress = "newNetworkAddress";
251+
final MessageMetadata messageMetadata =
252+
this.createMessageMetadata(deviceIdentification, deviceModelCode, oldNetworkAddress);
253+
254+
final ScheduledTask scheduledTask =
255+
new ScheduledTask(messageMetadata, DOMAIN, DOMAIN, DATA_OBJECT, INITIAL_SCHEDULED_TIME);
256+
final Device device = new Device();
257+
device.setNetworkAddress(newNetworkAddress);
258+
259+
when(this.scheduledTaskExecutorJobConfig.scheduledTaskPendingDurationMaxSeconds())
260+
.thenReturn(-1L);
261+
when(this.scheduledTaskExecutorJobConfig.scheduledTaskPageSize()).thenReturn(30);
262+
when(this.scheduledTaskRepository.updateStatus(
263+
scheduledTask.getId(), ScheduledTaskStatusType.PENDING))
264+
.thenReturn(1);
265+
when(this.deviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(device);
266+
when(this.scheduledTaskRepository.findByStatusAndScheduledTimeLessThan(
267+
eq(ScheduledTaskStatusType.PENDING), any(Timestamp.class), any(Pageable.class)))
268+
.thenReturn(new ArrayList<>());
269+
when(this.scheduledTaskRepository.findByStatusAndScheduledTimeLessThan(
270+
eq(ScheduledTaskStatusType.NEW), any(Timestamp.class), any(Pageable.class)))
271+
.thenReturn(List.of(scheduledTask), Collections.emptyList());
272+
when(this.scheduledTaskRepository.findByStatusAndScheduledTimeLessThan(
273+
eq(ScheduledTaskStatusType.RETRY), any(Timestamp.class), any(Pageable.class)))
274+
.thenReturn(new ArrayList<>());
275+
when(this.scheduledTaskExecutorJobConfig.getScheduledTaskThreadPoolSize()).thenReturn(1);
276+
277+
this.scheduledTaskExecutorService.processScheduledTasks();
278+
279+
verify(this.deviceRequestMessageService)
280+
.processMessage(this.protocolRequestMessageCaptor.capture());
281+
final ProtocolRequestMessage protocolRequestMessage =
282+
this.protocolRequestMessageCaptor.getValue();
283+
assertThat(protocolRequestMessage).isNotNull();
284+
285+
assertThat(protocolRequestMessage.getIpAddress()).isEqualTo(newNetworkAddress);
286+
}
287+
244288
private void whenFindByStatusAndScheduledTime(
245289
final List<ScheduledTask> pendingTasks,
246290
final List<ScheduledTask> newTasks,
@@ -295,14 +339,17 @@ private MessageMetadata createExpiredMessageMetadata() {
295339
}
296340

297341
private MessageMetadata createMessageMetadata() {
298-
return this.createMessageMetadata("retryable", null);
342+
return this.createMessageMetadata("retryable", null, null);
299343
}
300344

301345
private MessageMetadata createMessageMetadata(
302-
final String deviceIdentification, final String deviceModelCode) {
346+
final String deviceIdentification,
347+
final String deviceModelCode,
348+
final String networkAddress) {
303349
return this.createMessageMetadataBuilder()
304350
.withDeviceIdentification(deviceIdentification)
305351
.withDeviceModelCode(deviceModelCode)
352+
.withNetworkAddress(networkAddress)
306353
.build();
307354
}
308355

0 commit comments

Comments
 (0)