Commit 19cd384b authored by Filip Reaboi's avatar Filip Reaboi
Browse files

Test wrapped in runAsCommand(){}

refs 2978
parent f06010b8
......@@ -35,6 +35,7 @@ import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.model.ILibraryPackage;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.service.ILibraryService;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.junit.Before;
......@@ -54,12 +55,15 @@ public class SmokeComponentLibraryTest extends LibraryTestBase {
/** The top component. */
private Component top;
/** */
FileProject project;
/** Setup a fake context for the verification. */
@Before
public void setUp() throws Exception {
// Bring up persistency service for this test
// Bring up persistence service for this test
IPersistencyService.getInstance().getClass();
FileProject project =
project =
loadProjectFromPlugin(AF3ComponentActivator.PLUGIN_ID,
"test-data/LibraryTests.af3_20", true);
......@@ -72,60 +76,67 @@ public class SmokeComponentLibraryTest extends LibraryTestBase {
/** Test saving a component into the library. */
@Test
public void testSaveToLibrary() {
Prototype prot = findPrototypeComposableWith(Component.class, "Div");
assertNull(prot);
Component div = top.findSubComponent("Div");
addElementToLibrary("default", "default", div);
prot = findPrototypeComposableWith(Component.class, "Div");
assertNotNull(prot);
assertTrue(prot.getPrototype() instanceof ComponentRef);
ComponentRef prototypeCopy = (ComponentRef)prot.getPrototypeCopy();
assertEquals("default.Div", prototypeCopy.getURI());
prototypeCopy.setName("DivCopy");
top.getContainedElements().add(prototypeCopy);
assertEquals("DivCopy", prototypeCopy.getName());
Component divCopy = top.findSubComponent("DivCopy");
assertTrue(divCopy instanceof ComponentRef);
CodeSpecification cs = divCopy.getCodeSpecification();
assertEquals(1, cs.getBody().getStatements().size());
ILibraryPackage pack = findLibraryPackage("default", "default");
LibraryComponent libCom = (LibraryComponent)pack.getLibraryElements().get(0);
final Component compFromLib = libCom.getComponent();
final CodeSpecification csLib = compFromLib.getCodeSpecification();
assertEquals(1, csLib.getBody().getStatements().size());
// changes in the library are propagated
final ITopLevelElement libTopLevel =
IPersistencyService.getInstance().getTopLevelElementFor(csLib);
libTopLevel.runAsCommand(new Runnable() {
@Override
public void run() {
csLib.getBody().getStatements().clear();
}
});
assertEquals(0, csLib.getBody().getStatements().size());
assertTrue(ILibraryService.getInstance().isDirty(prototypeCopy));
CodeSpecification csNew = divCopy.getCodeSpecification();
assertEquals(0, csNew.getBody().getStatements().size());
// the name of the library component should not be synchronized
libTopLevel.runAsCommand(new Runnable() {
@Override
public void run() {
compFromLib.setName("NewName");
}
});
sleep();
assertEquals("DivCopy", divCopy.getName());
ICommandStackService.getInstance().runAsCommand(
project,
() -> {
Prototype prot = findPrototypeComposableWith(Component.class, "Div");
assertNull(prot);
Component div = top.findSubComponent("Div");
addElementToLibrary("default", "default", div);
prot = findPrototypeComposableWith(Component.class, "Div");
assertNotNull(prot);
assertTrue(prot.getPrototype() instanceof ComponentRef);
ComponentRef prototypeCopy = (ComponentRef)prot.getPrototypeCopy();
assertEquals("default.Div", prototypeCopy.getURI());
prototypeCopy.setName("DivCopy");
top.getContainedElements().add(prototypeCopy);
assertEquals("DivCopy", prototypeCopy.getName());
Component divCopy = top.findSubComponent("DivCopy");
assertTrue(divCopy instanceof ComponentRef);
CodeSpecification cs = divCopy.getCodeSpecification();
assertEquals(1, cs.getBody().getStatements().size());
ILibraryPackage pack = findLibraryPackage("default", "default");
LibraryComponent libCom = (LibraryComponent)pack.getLibraryElements().get(0);
final Component compFromLib = libCom.getComponent();
final CodeSpecification csLib = compFromLib.getCodeSpecification();
assertEquals(1, csLib.getBody().getStatements().size());
// changes in the library are propagated
final ITopLevelElement libTopLevel =
IPersistencyService.getInstance().getTopLevelElementFor(csLib);
libTopLevel.runAsCommand(new Runnable() {
@Override
public void run() {
csLib.getBody().getStatements().clear();
}
});
assertEquals(0, csLib.getBody().getStatements().size());
assertTrue(ILibraryService.getInstance().isDirty(prototypeCopy));
CodeSpecification csNew = divCopy.getCodeSpecification();
assertEquals(0, csNew.getBody().getStatements().size());
// the name of the library component should not be synchronized
libTopLevel.runAsCommand(new Runnable() {
@Override
public void run() {
compFromLib.setName("NewName");
}
});
sleep();
assertEquals("DivCopy", divCopy.getName());
});
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment