Skip to content

Commit

Permalink
RemoteTaskMonitor coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Rol <[email protected]>
  • Loading branch information
rolnico committed Jan 30, 2024
1 parent 585975d commit 25b0b73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.powsybl.afs.ws.storage.RemoteTaskMonitor;
import com.powsybl.commons.exceptions.UncheckedUriSyntaxException;
import com.powsybl.computation.ComputationManager;
import jakarta.servlet.ServletContext;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -31,15 +32,16 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import jakarta.servlet.ServletContext;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -106,6 +108,11 @@ protected void nextDependentTests() throws InterruptedException {
TaskMonitor.Snapshot snapshot = taskMonitor.takeSnapshot(project.getId());
assertThat(snapshot.getTasks().stream().anyMatch(t -> t.getId().equals(task.getId()))).isTrue();

ProjectFile projectFile = Mockito.mock(ProjectFile.class);
AfsStorageException error = assertThrows(AfsStorageException.class, () -> taskMonitor.startTask(projectFile));
assertTrue(Pattern.compile("\\{\"timestamp\":\"(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}[+-]\\d{2}:\\d{2})\",\"status\":\\d+,\"error\":\"[^\"]*\",\"path\":\"[^\"]*\"}")
.matcher(error.getMessage()).find());

taskMonitor.updateTaskMessage(task.getId(), "new Message");
TaskMonitor.Snapshot snapshotAfterUpdate = taskMonitor.takeSnapshot(project.getId());
TaskMonitor.Task taskAfterUpdate = snapshotAfterUpdate.getTasks().stream().filter(t -> t.getId().equals(task.getId())).findFirst().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ private static RuntimeException createServerErrorException(Response response) {
ExceptionDetail exceptionDetail = new ObjectMapper().readValue(body, ExceptionDetail.class);
String javaException = exceptionDetail.getJavaException();
if (javaException != null) {
Class exceptionClass = Class.forName(javaException);
Class<?> exceptionClass = Class.forName(javaException);
if (RuntimeException.class.isAssignableFrom(exceptionClass)) {
if (exceptionDetail.getMessage() != null) {
return (RuntimeException) exceptionClass.getConstructor(String.class).newInstance(exceptionDetail.getMessage());
}
return (RuntimeException) exceptionClass.newInstance();
return (RuntimeException) exceptionClass.getDeclaredConstructor().newInstance();
}
}
} catch (Exception e) {
Expand Down

0 comments on commit 25b0b73

Please sign in to comment.