Search in sources :

Example 1 with OperationExtender

use of com.developmentontheedge.be5.metadata.model.OperationExtender in project be5 by DevelopmentOnTheEdge.

the class ReadModelFromXmlTest method testWriteReadOperationExtender.

@Test
public void testWriteReadOperationExtender() throws Exception {
    final Project project = new Project("TestProject");
    final Module module = project.getApplication();
    DataElementUtils.saveQuiet(module);
    final Entity table = new Entity("table", module, EntityType.TABLE);
    DataElementUtils.saveQuiet(table);
    final Operation op = Operation.createOperation("op", Operation.OPERATION_TYPE_JAVA, table);
    DataElementUtils.saveQuiet(op);
    final OperationExtender ex1 = new OperationExtender(op, module.getName());
    DataElementUtils.saveQuiet(ex1);
    ex1.setClassName("test.class.name");
    ex1.setInvokeOrder(1);
    final JavaScriptOperationExtender ex2 = new JavaScriptOperationExtender(op, module.getName());
    DataElementUtils.saveQuiet(ex2);
    ex2.setFileName("MyExtender.js");
    ex2.setCode("Hello world!");
    final Path tempFolder = Files.createTempDirectory("be4-temp");
    Serialization.save(project, tempFolder);
    final Project readProject = Serialization.load(tempFolder);
    final Entity readEntity = readProject.getApplication().getEntity("table");
    final BeModelCollection<OperationExtender> extenders = readEntity.getOperations().get("op").getExtenders();
    assertEquals(2, extenders.getSize());
    final OperationExtender readEx1 = extenders.get("application - 0001");
    assertEquals("test.class.name", readEx1.getClassName());
    assertEquals(1, readEx1.getInvokeOrder());
    final JavaScriptOperationExtender readEx2 = (JavaScriptOperationExtender) extenders.get("application - 0002");
    assertEquals(0, readEx2.getInvokeOrder());
    assertEquals("MyExtender.js", readEx2.getFileName());
    assertEquals("Hello world!", readEx2.getCode());
    FileUtils.deleteRecursively(tempFolder);
}
Also used : Path(java.nio.file.Path) Project(com.developmentontheedge.be5.metadata.model.Project) Entity(com.developmentontheedge.be5.metadata.model.Entity) JavaScriptOperationExtender(com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender) OperationExtender(com.developmentontheedge.be5.metadata.model.OperationExtender) JavaScriptOperationExtender(com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender) Operation(com.developmentontheedge.be5.metadata.model.Operation) Module(com.developmentontheedge.be5.metadata.model.Module) Test(org.junit.Test)

Aggregations

Entity (com.developmentontheedge.be5.metadata.model.Entity)1 JavaScriptOperationExtender (com.developmentontheedge.be5.metadata.model.JavaScriptOperationExtender)1 Module (com.developmentontheedge.be5.metadata.model.Module)1 Operation (com.developmentontheedge.be5.metadata.model.Operation)1 OperationExtender (com.developmentontheedge.be5.metadata.model.OperationExtender)1 Project (com.developmentontheedge.be5.metadata.model.Project)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1