use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ThrowOnPartialSchemaStrategyIT method testThrowOnPartialStrategyWithOneTable.
@Test
public void testThrowOnPartialStrategyWithOneTable() throws Exception {
createOneTable("SUS1");
setStrategy(ThrowOnPartialSchemaStrategy.class);
String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
SQLTemplate query = new SQLTemplate(Object.class, template);
MockOperationObserver observer = new MockOperationObserver();
try {
node.performQueries(Collections.singletonList(query), observer);
assertEquals(1, existingTables().size());
fail("Must have thrown on partial schema");
} catch (CayenneRuntimeException e) {
// expected
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ThrowOnPartialSchemaStrategyIT method testThrowOnPartialStrategyTableNoExist.
@Test
public void testThrowOnPartialStrategyTableNoExist() throws Exception {
String template = "SELECT #result('ARTIST_ID' 'int') FROM ARTIST ORDER BY ARTIST_ID";
SQLTemplate query = new SQLTemplate(Object.class, template);
MockOperationObserver observer = new MockOperationObserver();
setStrategy(ThrowOnPartialSchemaStrategy.class);
try {
node.performQueries(Collections.singletonList((Query) query), observer);
} catch (CayenneRuntimeException e) {
assertNotNull(e);
}
try {
node.performQueries(Collections.singletonList((Query) query), observer);
} catch (CayenneRuntimeException e) {
assertNotNull(e);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class DataDomainIT method testLookupDataNode.
@Test
public void testLookupDataNode() {
DataDomain domain = new DataDomain("test");
DataMap m1 = new DataMap("m1");
DataNode n1 = new DataNode("n1");
n1.addDataMap(m1);
domain.addNode(n1);
DataMap m2 = new DataMap("m2");
DataNode n2 = new DataNode("n2");
n2.addDataMap(m2);
domain.addNode(n2);
assertSame(n1, domain.lookupDataNode(m1));
assertSame(n2, domain.lookupDataNode(m2));
try {
domain.lookupDataNode(new DataMap("m3"));
fail("must have thrown on missing Map to Node maping");
} catch (CayenneRuntimeException e) {
// expected
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class PropertyUtilsTest method testSetConvertedWithCustomConverter.
@Test
public void testSetConvertedWithCustomConverter() {
// save old converter for restore
Converter<Date> oldConverter = ConverterFactory.factory.getConverter(Date.class);
try {
ConverterFactory.addConverter(Date.class, new Converter<Date>() {
@Override
protected Date convert(Object value, Class<Date> type) {
if (value == null)
return null;
if (value instanceof Date) {
return (Date) value;
}
if (value instanceof String) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
return format.parse((String) value);
} catch (ParseException e) {
throw new CayenneRuntimeException("Unable to convert '" + value + "' to a Date", e);
}
}
throw new CayenneRuntimeException("Unable to convert '" + value + "' to a Date");
}
});
TstJavaBean o1 = new TstJavaBean();
// String to date
PropertyUtils.setProperty(o1, "dateField", "2013-08-01");
Calendar cal = new GregorianCalendar(2013, 7, 1, 0, 0, 0);
assertEquals(cal.getTime(), o1.getDateField());
} finally {
// restore global date converter
ConverterFactory.addConverter(Date.class, oldConverter);
}
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ASTExtractIT method testMonth.
@Test
public void testMonth() {
Expression exp = ExpressionFactory.exp("month(dateColumn) = 3");
try {
long res = ObjectSelect.query(DateTestEntity.class, exp).selectCount(context);
assertEquals(1, res);
} catch (CayenneRuntimeException e) {
if (unitDbAdapter.supportsExtractPart(ASTExtract.DateTimePart.MONTH)) {
throw e;
}
// else ok
}
}
Aggregations