complete Studio core and JavaFX boundary migration
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 64.01% (20482/31999)
* Branch Coverage: 54.22% (8240/15196)
* Lines of Code: 31999
* Cyclomatic Complexity: 13164
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 715
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 64.01% (20482/31999)
* Branch Coverage: 54.22% (8240/15196)
* Lines of Code: 31999
* Cyclomatic Complexity: 13164
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 715
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package p.studio.app;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import p.packer.PackerWorkspaceService;
|
||||
import p.studio.api.operation.OperationExecutor;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class StudioApplicationConfigurationTest {
|
||||
@Test
|
||||
void bootsAndClosesWithoutAWebApplicationContext() {
|
||||
final ConfigurableApplicationContext context = new SpringApplicationBuilder(StudioApplicationConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.headless(true)
|
||||
.run();
|
||||
final ExecutorService executor = context.getBean(ExecutorService.class);
|
||||
try (context) {
|
||||
assertNotNull(context.getBean(StudioUiFactory.class));
|
||||
assertNotNull(context.getBean(PackerWorkspaceService.class));
|
||||
assertNotNull(context.getBean(OperationExecutor.class));
|
||||
assertFalse(context.getClass().getName().contains("WebServer"));
|
||||
assertFalse(executor.isShutdown());
|
||||
}
|
||||
assertTrue(executor.isShutdown());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package p.studio.app;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.packer.events.PackerEvent;
|
||||
import p.packer.events.PackerEventKind;
|
||||
import p.packer.events.PackerProgress;
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
import p.studio.ui.javafx.events.StudioPackerOperationEvent;
|
||||
import p.studio.ui.javafx.events.StudioPackerOperationKind;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
final class StudioPackerEventAdapterTest {
|
||||
@Test
|
||||
void translatesProviderEventsIntoStudioEvents() {
|
||||
final StudioEventBus globalBus = new StudioEventBus();
|
||||
final List<StudioPackerOperationEvent> events = new ArrayList<>();
|
||||
globalBus.subscribe(StudioPackerOperationEvent.class, events::add);
|
||||
|
||||
new StudioPackerEventAdapter(globalBus).publish(new PackerEvent(
|
||||
"main", "op-1", 0L, PackerEventKind.ASSET_DISCOVERED, Instant.now(),
|
||||
"Discovered asset.", new PackerProgress(0.25d, false), List.of("ui_atlas")));
|
||||
|
||||
assertEquals(1, events.size());
|
||||
assertEquals(StudioPackerOperationKind.ASSET_DISCOVERED, events.getFirst().kind());
|
||||
assertEquals(0.25d, events.getFirst().progress());
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package p.studio.app.compiler;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.FrontendRegistryService;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class CompilerProjectLanguageCatalogTest {
|
||||
@Test
|
||||
void listsLanguagesFromRegisteredProviders() {
|
||||
FrontendRegistryService.bootstrapDefaults();
|
||||
|
||||
final var templates = new CompilerProjectLanguageCatalog().listLanguageTemplates();
|
||||
|
||||
assertEquals(1, templates.size());
|
||||
assertEquals("pbs", templates.getFirst().languageId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package p.studio.app.operation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.api.operation.OperationState;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
final class ExecutorOperationExecutorTest {
|
||||
@Test
|
||||
void completesWithTypedResultAndTerminalSnapshot() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
final var handle = new ExecutorOperationExecutor(executor).submit("test operation", () -> 42);
|
||||
|
||||
assertEquals(42, handle.completion().toCompletableFuture().get(2, TimeUnit.SECONDS));
|
||||
assertEquals(OperationState.SUCCEEDED, handle.snapshot().state());
|
||||
assertEquals("test operation", handle.snapshot().summary());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void cancellationInterruptsWorkAndCancelsCompletion() throws Exception {
|
||||
final var executor = Executors.newSingleThreadExecutor();
|
||||
final var started = new CountDownLatch(1);
|
||||
try {
|
||||
final var handle = new ExecutorOperationExecutor(executor).submit("cancel operation", () -> {
|
||||
started.countDown();
|
||||
new CountDownLatch(1).await();
|
||||
return 42;
|
||||
});
|
||||
assertTrue(started.await(2, TimeUnit.SECONDS));
|
||||
|
||||
assertTrue(handle.cancel());
|
||||
assertEquals(OperationState.CANCELLED, handle.snapshot().state());
|
||||
assertThrows(java.util.concurrent.CancellationException.class,
|
||||
() -> handle.completion().toCompletableFuture().join());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user