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