use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ClassGenerationActionTest method testExecuteArtifactPairsMapRelationships.
@Test
public void testExecuteArtifactPairsMapRelationships() throws Exception {
ObjEntity testEntity1 = new ObjEntity("TE1");
testEntity1.setClassName("org.example.TestClass1");
final ObjEntity testEntity2 = new ObjEntity("TE1");
testEntity2.setClassName("org.example.TestClass2");
ObjRelationship relationship = new ObjRelationship("xMap") {
private static final long serialVersionUID = 8042147877503405974L;
@Override
public boolean isToMany() {
return true;
}
@Override
public ObjEntity getTargetEntity() {
return testEntity2;
}
};
relationship.setCollectionType("java.util.Map");
testEntity1.addRelationship(relationship);
cgenConfiguration.setMakePairs(true);
List<String> generated = execute(new EntityArtifact(testEntity1));
assertNotNull(generated);
assertEquals(2, generated.size());
String superclass = generated.get(0);
assertTrue(superclass, superclass.contains("import java.util.Map;"));
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ClassGenerationActionTest method testFileForClass.
@Test
public void testFileForClass() throws Exception {
TemplateType templateType = TemplateType.DATAMAP_SINGLE_CLASS;
cgenConfiguration.setRootPath(tempFolder.getRoot().toPath());
cgenConfiguration.setRelPath(".");
action = new ClassGenerationAction(cgenConfiguration);
ObjEntity testEntity1 = new ObjEntity("TEST");
testEntity1.setClassName("TestClass1");
action.context.put(Artifact.SUB_PACKAGE_KEY, "");
action.context.put(Artifact.SUB_CLASS_KEY, "TestClass1");
File outFile = new File(tempFolder.getRoot() + "/TestClass1.java");
assertFalse(outFile.exists());
action.openWriter(templateType);
assertTrue(outFile.exists());
assertNull(action.openWriter(templateType));
cgenConfiguration.setMakePairs(false);
assertNull(action.openWriter(templateType));
cgenConfiguration.setOverwrite(true);
assertNull(action.openWriter(templateType));
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ClassGenerationActionTest method testExecuteArtifactPairsAttribute.
@Test
public void testExecuteArtifactPairsAttribute() throws Exception {
ObjEntity testEntity1 = new ObjEntity("TE1");
testEntity1.setClassName("org.example.TestClass1");
ObjAttribute attr = new ObjAttribute();
attr.setName("ID");
attr.setType("int");
ObjAttribute attr1 = new ObjAttribute();
attr1.setName("name");
attr1.setType("char");
testEntity1.addAttribute(attr);
testEntity1.addAttribute(attr1);
cgenConfiguration.setMakePairs(true);
List<String> generated = execute(new EntityArtifact(testEntity1));
assertNotNull(generated);
assertEquals(2, generated.size());
String superclass = generated.get(0);
assertTrue(superclass, superclass.contains("public void setID(int ID)"));
assertTrue(superclass, superclass.contains("this.ID = ID;"));
assertTrue(superclass, superclass.contains("public int getID()"));
assertTrue(superclass, superclass.contains("return this.ID;"));
assertTrue(superclass, superclass.contains("public void setName(char name)"));
assertTrue(superclass, superclass.contains("this.name = name;"));
assertTrue(superclass, superclass.contains("public char getName()"));
assertTrue(superclass, superclass.contains("return this.name;"));
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ClassGenerationActionTest method assertCallbacks.
private void assertCallbacks(boolean isClient) throws Exception {
ObjEntity testEntity1 = new ObjEntity("TE1");
testEntity1.setClassName("org.example.TestClass1");
int i = 0;
for (CallbackDescriptor cb : testEntity1.getCallbackMap().getCallbacks()) {
cb.addCallbackMethod("cb" + i++);
}
if (isClient) {
cgenConfiguration.setClient(true);
action = new TestClassGenerationAction(getUnitTestInjector().getInstance(ClassGenerationActionFactory.class).createAction(cgenConfiguration), writers);
}
cgenConfiguration.setMakePairs(true);
List<String> generated = execute(new EntityArtifact(testEntity1));
assertNotNull(generated);
assertEquals(2, generated.size());
String superclass = generated.get(0);
assertTrue(superclass, superclass.contains("public abstract class _TestClass1"));
for (int j = 0; j < i; j++) {
assertTrue(superclass, superclass.contains("protected abstract void cb" + j + "();"));
}
String subclass = generated.get(1);
for (int j = 0; j < i; j++) {
assertTrue(subclass, subclass.contains("protected void cb" + j + "() {"));
}
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ClassGenerationActionTest method testExecuteArtifactPairsImports.
@Test
public void testExecuteArtifactPairsImports() throws Exception {
ObjEntity testEntity1 = new ObjEntity("TE1");
testEntity1.setClassName("org.example.TestClass1");
cgenConfiguration.setMakePairs(true);
cgenConfiguration.setSuperPkg("org.example.auto");
List<String> generated = execute(new EntityArtifact(testEntity1));
assertNotNull(generated);
assertEquals(2, generated.size());
String superclass = generated.get(0);
assertTrue(superclass, superclass.contains("package org.example.auto;"));
assertTrue(superclass, superclass.contains("import org.apache.cayenne.BaseDataObject;"));
String subclass = generated.get(1);
assertTrue(subclass, subclass.contains("package org.example;"));
assertTrue(subclass, subclass.contains("import org.example.auto._TestClass1;"));
}
Aggregations