Search in sources :

Example 31 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class Project2Case method setupTestDirectory.

protected File setupTestDirectory(String subfolder) {
    String classPath = getClass().getName().replace('.', '/');
    String location = "target/testrun/" + classPath + "/" + subfolder;
    File testDirectory = new File(location);
    // delete old tests
    if (testDirectory.exists()) {
        if (!FileUtil.delete(location, true)) {
            throw new CayenneRuntimeException("Error deleting test directory '%s'", location);
        }
    }
    if (!testDirectory.mkdirs()) {
        throw new CayenneRuntimeException("Error creating test directory '%s'", location);
    }
    return testDirectory;
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) File(java.io.File)

Example 32 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class BaseRemoteService method processMessage.

@Override
public Object processMessage(ClientMessage message) {
    if (message == null) {
        throw new IllegalArgumentException("Null client message.");
    }
    ServerSession handler = getServerSession();
    if (handler == null) {
        throw new MissingSessionException("No session associated with request.");
    }
    logger.debug("processMessage, sessionId: " + handler.getSession().getSessionId());
    // intercept and log exceptions
    try {
        return DispatchHelper.dispatch(handler.getChannel(), message);
    } catch (Throwable th) {
        String wrapperMessageString = "Exception processing message " + message.getClass().getName() + " of type " + message;
        logger.info(wrapperMessageString, th);
        // This exception will probably be propagated to the client.
        // Recast the exception to a serializable form.
        Exception cause = new Exception(Util.unwindException(th).getLocalizedMessage());
        throw new CayenneRuntimeException(wrapperMessageString, cause);
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) RemoteException(java.rmi.RemoteException) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 33 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class DispatchHelperTest method testUnknownMessage.

@Test
public void testUnknownMessage() {
    try {
        DispatchHelper.dispatch(new MockDataChannel(), mock(ClientMessage.class));
        fail("Unknown message must have failed");
    } catch (CayenneRuntimeException e) {
    // expected
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ClientMessage(org.apache.cayenne.remote.ClientMessage) MockDataChannel(org.apache.cayenne.MockDataChannel) Test(org.junit.Test)

Example 34 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class DefaultDbImportActionTest method testImportWithFieldChanged.

@Test
public void testImportWithFieldChanged() throws Exception {
    DbImportConfiguration config = mock(DbImportConfiguration.class);
    when(config.getTargetDataMap()).thenReturn(FILE_STUB);
    when(config.createMergeDelegate()).thenReturn(new DefaultModelMergeDelegate());
    when(config.getDbLoaderConfig()).thenReturn(new DbLoaderConfiguration());
    when(config.createNameGenerator()).thenReturn(new DefaultObjectNameGenerator(NoStemStemmer.getInstance()));
    when(config.createMeaningfulPKFilter()).thenReturn(NamePatternMatcher.EXCLUDE_ALL);
    DbLoader dbLoader = new DbLoader(mockAdapter, mockConnection, config.getDbLoaderConfig(), mockDelegate, mockNameGenerator) {

        @Override
        public DataMap load() throws SQLException {
            DataMap dataMap = new DataMap();
            new DataMapBuilder(dataMap).with(dbEntity("ARTGROUP").attributes(dbAttr("GROUP_ID").typeInt().primaryKey(), dbAttr("NAME").typeVarchar(100).mandatory(), dbAttr("NAME_01").typeVarchar(100).mandatory(), dbAttr("PARENT_GROUP_ID").typeInt())).with(objEntity("org.apache.cayenne.testdo.testmap", "ArtGroup", "ARTGROUP").attributes(objAttr("name").type(String.class).dbPath("NAME")));
            return dataMap;
        }
    };
    final boolean[] haveWeTriedToSave = { false };
    DefaultDbImportAction action = buildDbImportAction(new FileProjectSaver(Collections.<ProjectExtension>emptyList()) {

        @Override
        public void save(Project project) {
            haveWeTriedToSave[0] = true;
            // Validation phase
            DataMap rootNode = (DataMap) project.getRootNode();
            assertEquals(1, rootNode.getObjEntities().size());
            assertEquals(1, rootNode.getDbEntityMap().size());
            DbEntity entity = rootNode.getDbEntity("ARTGROUP");
            assertNotNull(entity);
            assertEquals(4, entity.getAttributes().size());
            assertNotNull(entity.getAttribute("NAME_01"));
        }
    }, new DataMapLoader() {

        @Override
        public DataMap load(Resource configurationResource) throws CayenneRuntimeException {
            return new DataMapBuilder().with(dbEntity("ARTGROUP").attributes(dbAttr("GROUP_ID").typeInt().primaryKey(), dbAttr("NAME").typeVarchar(100).mandatory(), dbAttr("PARENT_GROUP_ID").typeInt())).with(objEntity("org.apache.cayenne.testdo.testmap", "ArtGroup", "ARTGROUP").attributes(objAttr("name").type(String.class).dbPath("NAME"))).build();
        }
    }, dbLoader);
    action.execute(config);
    assertTrue("We should try to save.", haveWeTriedToSave[0]);
}
Also used : FileProjectSaver(org.apache.cayenne.project.FileProjectSaver) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) Resource(org.apache.cayenne.resource.Resource) URLResource(org.apache.cayenne.resource.URLResource) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DefaultModelMergeDelegate(org.apache.cayenne.dbsync.reverse.dbload.DefaultModelMergeDelegate) DbLoaderConfiguration(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration) DataMap(org.apache.cayenne.map.DataMap) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) Project(org.apache.cayenne.project.Project) DataMapBuilder(org.apache.cayenne.dbsync.merge.builders.DataMapBuilder) DbEntity(org.apache.cayenne.map.DbEntity) ProjectExtension(org.apache.cayenne.project.extension.ProjectExtension) DbLoader(org.apache.cayenne.dbsync.reverse.dbload.DbLoader) Test(org.junit.Test)

Example 35 with CayenneRuntimeException

use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.

the class Runtime_LazyInit_IT method testCryptoLocked_Unlocked.

@Test
public void testCryptoLocked_Unlocked() {
    assertFalse(UNLOCKED);
    try {
        Table1 t1 = runtime.newContext().newObject(Table1.class);
        t1.setPlainInt(56);
        t1.setCryptoInt(77);
        t1.setPlainString("XX");
        t1.setCryptoString("YY");
        t1.getObjectContext().commitChanges();
        fail("Must have thrown on crypto access");
    } catch (CayenneRuntimeException e) {
    // expected
    }
    UNLOCKED = true;
    Table1 t1 = runtime.newContext().newObject(Table1.class);
    t1.setPlainInt(56);
    t1.setCryptoInt(77);
    t1.setPlainString("XX");
    t1.setCryptoString("YY");
    t1.getObjectContext().commitChanges();
    assertEquals(t1.getObjectId(), ObjectSelect.query(Table1.class).selectOne(runtime.newContext()).getObjectId());
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Table1(org.apache.cayenne.crypto.db.Table1) Test(org.junit.Test)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)168 Test (org.junit.Test)25 DbAttribute (org.apache.cayenne.map.DbAttribute)21 DataMap (org.apache.cayenne.map.DataMap)19 ObjectId (org.apache.cayenne.ObjectId)18 ObjEntity (org.apache.cayenne.map.ObjEntity)18 Persistent (org.apache.cayenne.Persistent)17 Expression (org.apache.cayenne.exp.Expression)17 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)17 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 DbEntity (org.apache.cayenne.map.DbEntity)14 IOException (java.io.IOException)13 List (java.util.List)12 ObjRelationship (org.apache.cayenne.map.ObjRelationship)12 DbRelationship (org.apache.cayenne.map.DbRelationship)10 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)10 File (java.io.File)9 Connection (java.sql.Connection)9 SQLException (java.sql.SQLException)9