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);
}
Aggregations