Search in sources :

Example 1 with TestClassGenerationAction

use of org.apache.cayenne.gen.mock.TestClassGenerationAction 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 + "() {"));
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) TestClassGenerationAction(org.apache.cayenne.gen.mock.TestClassGenerationAction) CallbackDescriptor(org.apache.cayenne.map.CallbackDescriptor)

Example 2 with TestClassGenerationAction

use of org.apache.cayenne.gen.mock.TestClassGenerationAction in project cayenne by apache.

the class ClassGenerationActionTest method setUp.

@Before
public void setUp() throws Exception {
    writers = new ArrayList<>(3);
    cgenConfiguration = new CgenConfiguration(false);
    action = new TestClassGenerationAction(getUnitTestInjector().getInstance(ClassGenerationActionFactory.class).createAction(cgenConfiguration), writers);
}
Also used : TestClassGenerationAction(org.apache.cayenne.gen.mock.TestClassGenerationAction) Before(org.junit.Before)

Aggregations

TestClassGenerationAction (org.apache.cayenne.gen.mock.TestClassGenerationAction)2 CallbackDescriptor (org.apache.cayenne.map.CallbackDescriptor)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 Before (org.junit.Before)1