FINERACT-1269: (fix) add a try-catch block to ensure that the json is deserialized successfully.
- Wrap the fromJson() method with try-catch block and throw proper exception. - Add `publishHookEventHandlesInvalidJson()` method to test the invalid json is handled successfully.
This commit is contained in:
+17
-2
@@ -19,6 +19,7 @@
|
||||
package org.apache.fineract.commands.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -34,10 +35,10 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma
|
||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractRequestContextHolder;
|
||||
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -163,11 +164,25 @@ public class SynchronousCommandProcessingServiceTest {
|
||||
when(commandSourceService.processCommand(commandHandler, jsonCommand, commandSource, appUser, false, false))
|
||||
.thenThrow(runtimeException);
|
||||
|
||||
Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
underTest.executeCommand(commandWrapper, jsonCommand, false);
|
||||
});
|
||||
|
||||
verify(commandSourceService).getCommandSource(commandId);
|
||||
verify(commandSourceService).generateErrorInfo(runtimeException);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishHookEventHandlesInvalidJson() {
|
||||
String entityName = "entity";
|
||||
String actionName = "action";
|
||||
JsonCommand command = Mockito.mock(JsonCommand.class);
|
||||
String invalidJson = "{ invalidJson }";
|
||||
|
||||
when(command.json()).thenReturn(invalidJson);
|
||||
|
||||
assertThrows(PlatformApiDataValidationException.class, () -> {
|
||||
underTest.publishHookEvent(entityName, actionName, command, Object.class);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user