Establish buildable modules and shared host-service boundaries
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
package de.neitzel.fxdesigner.intellij;
|
||||
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
|
||||
import de.neitzel.fxdesigner.contracts.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
public final class IntellijDocumentsTest extends BasePlatformTestCase {
|
||||
public void testNativeDocumentTransactionUndoAndIndependentHandles() throws Exception {
|
||||
Path file = Files.createTempFile("designer-document-", ".fxml");
|
||||
Files.writeString(file, "abcdef");
|
||||
com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess.allowRootAccess(getTestRootDisposable(), file.toRealPath().toString());
|
||||
try (var docs = new IntellijDocuments(getProject())) {
|
||||
var a = docs.open(file.toUri()).toCompletableFuture().get();
|
||||
var b = docs.open(file.toUri()).toCompletableFuture().get();
|
||||
var initial = a.snapshot().toCompletableFuture().get();
|
||||
var changed =
|
||||
a.apply(
|
||||
new EditBatch(
|
||||
initial.revision(),
|
||||
"Component properties",
|
||||
List.of(
|
||||
new EditBatch.Replacement(0, 1, "A"),
|
||||
new EditBatch.Replacement(5, 6, "F"))))
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
assertEquals("AbcdeF", b.snapshot().toCompletableFuture().get().text());
|
||||
a.close();
|
||||
var undone = b.undo().toCompletableFuture().get();
|
||||
assertEquals("abcdef", undone.text());
|
||||
assertTrue(undone.revision() > changed.revision());
|
||||
try {
|
||||
b.apply(new EditBatch(initial.revision(), "stale", List.of())).toCompletableFuture().get();
|
||||
fail("Stale edit accepted");
|
||||
} catch (java.util.concurrent.ExecutionException expected) {
|
||||
assertInstanceOf(expected.getCause(), ConcurrentModificationException.class);
|
||||
}
|
||||
var redone = b.redo().toCompletableFuture().get();
|
||||
assertEquals("AbcdeF", redone.text());
|
||||
b.save(redone.revision()).toCompletableFuture().get();
|
||||
assertEquals("AbcdeF", Files.readString(file));
|
||||
b.close();
|
||||
} finally {
|
||||
Files.deleteIfExists(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void testExternalChangesDoNotLoseDraft() throws Exception {
|
||||
Path file = Files.createTempFile("designer-conflict-", ".fxml");
|
||||
Files.writeString(file, "old");
|
||||
com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess.allowRootAccess(getTestRootDisposable(), file.toRealPath().toString());
|
||||
try (var docs = new IntellijDocuments(getProject())) {
|
||||
var d = docs.open(file.toUri()).toCompletableFuture().get();
|
||||
var changed =
|
||||
d.apply(new EditBatch(0, "edit", List.of(new EditBatch.Replacement(0, 3, "draft"))))
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
Files.writeString(file, "external");
|
||||
try {
|
||||
d.save(changed.revision()).toCompletableFuture().get();
|
||||
fail("Conflict accepted");
|
||||
} catch (java.util.concurrent.ExecutionException expected) {
|
||||
assertInstanceOf(expected.getCause(), ConcurrentModificationException.class);
|
||||
}
|
||||
assertEquals("draft", d.snapshot().toCompletableFuture().get().text());
|
||||
assertEquals("external", Files.readString(file));
|
||||
d.close();
|
||||
} finally {
|
||||
Files.deleteIfExists(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user