use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class Runtime_AES128_IT method testInsert_MultipleObjects.
@Test
public void testInsert_MultipleObjects() throws SQLException {
ObjectContext context = runtime.newContext();
Table2 t1 = context.newObject(Table2.class);
t1.setPlainBytes("a".getBytes());
t1.setCryptoBytes("crypto_1".getBytes());
Table2 t2 = context.newObject(Table2.class);
t2.setPlainBytes("b".getBytes());
t2.setCryptoBytes("crypto_2".getBytes());
Table2 t3 = context.newObject(Table2.class);
t3.setPlainBytes("c".getBytes());
t3.setCryptoBytes(null);
context.commitChanges();
List<Object[]> data = table2.selectAll();
assertEquals(3, data.size());
Map<String, byte[]> cipherByPlain = new HashMap<>();
for (Object[] r : data) {
cipherByPlain.put(new String((byte[]) r[1]), (byte[]) r[2]);
}
assertArrayEquals("crypto_1".getBytes(), CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("a"), runtime));
assertArrayEquals("crypto_2".getBytes(), CryptoUnitUtils.decrypt_AES_CBC(cipherByPlain.get("b"), runtime));
assertNull(cipherByPlain.get("c"));
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class Runtime_AES128_IT method testInsert_Numeric.
@Test
public void testInsert_Numeric() throws SQLException {
ObjectContext context = runtime.newContext();
Table1 t1 = context.newObject(Table1.class);
t1.setPlainInt(59);
t1.setCryptoInt(61);
context.commitChanges();
Object[] data = table1.select();
assertEquals(59, data[3]);
assertEquals(new Integer(61), IntegerConverter.INSTANCE.fromBytes(CryptoUnitUtils.decrypt_AES_CBC((byte[]) data[4], runtime)));
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class ClientServerChannelIT method testOnQuery.
@Test
public void testOnQuery() {
final boolean[] genericDone = new boolean[1];
MockDataChannel parent = new MockDataChannel(new EntityResolver()) {
@Override
public QueryResponse onQuery(ObjectContext context, Query query) {
genericDone[0] = true;
return super.onQuery(context, query);
}
};
DataContext context = (DataContext) runtime.newContext(parent);
QueryMessage message = new QueryMessage(new MockQuery());
new ClientServerChannel(context).onQuery(null, message.getQuery());
assertTrue(genericDone[0]);
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class ClientChannelServerDiffsIT method testReturnDiffInPrePersist.
@Test
public void testReturnDiffInPrePersist() {
final List<GenericDiff> diffs = new ArrayList<GenericDiff>();
final NoopGraphChangeHandler diffReader = new NoopGraphChangeHandler() {
@Override
public void nodePropertyChanged(Object nodeId, String property, Object oldValue, Object newValue) {
super.nodePropertyChanged(nodeId, property, oldValue, newValue);
diffs.add(new GenericDiff((ObjectId) nodeId, property, oldValue, newValue));
}
};
LifecycleCallbackRegistry callbackRegistry = clientServerChannel.getEntityResolver().getCallbackRegistry();
try {
callbackRegistry.addListener(LifecycleEvent.POST_ADD, MtTable1.class, new ClientChannelServerDiffsListener1(), "prePersist");
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false) {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
GraphDiff serverDiff = super.onSync(originatingContext, changes, syncType);
assertNotNull(serverDiff);
serverDiff.apply(diffReader);
return serverDiff;
}
};
CayenneContext context = new CayenneContext(channel);
ClientMtTable1 o = context.newObject(ClientMtTable1.class);
ObjectId tempId = o.getObjectId();
o.setServerAttribute1("YY");
context.commitChanges();
assertEquals(2, diffReader.size);
assertEquals(1, diffs.size());
assertEquals(tempId, diffs.get(0).sourceId);
assertEquals(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, diffs.get(0).property);
assertNull(diffs.get(0).oldValue);
assertEquals("XXX", diffs.get(0).newValue);
} finally {
callbackRegistry.clear();
}
}
use of org.apache.cayenne.ObjectContext in project cayenne by apache.
the class NestedObjectContextPeerEventsIT method testPeerObjectUpdatedToManyRelationship.
@Test
public void testPeerObjectUpdatedToManyRelationship() throws Exception {
ClientMtTable1 a = clientContext.newObject(ClientMtTable1.class);
a.setGlobalAttribute1("X");
ClientMtTable2 px = clientContext.newObject(ClientMtTable2.class);
px.setTable1(a);
px.setGlobalAttribute("PX");
ClientMtTable2 py = clientContext.newObject(ClientMtTable2.class);
py.setGlobalAttribute("PY");
clientContext.commitChanges();
ObjectContext peer1 = runtime.newContext(clientContext);
ClientMtTable2 py1 = peer1.localObject(py);
ClientMtTable1 a1 = peer1.localObject(a);
ObjectContext peer2 = runtime.newContext(clientContext);
ClientMtTable2 py2 = peer2.localObject(py);
ClientMtTable1 a2 = peer2.localObject(a);
a1.addToTable2Array(py1);
assertEquals(1, a2.getTable2Array().size());
assertFalse(a2.getTable2Array().contains(py2));
peer1.commitChangesToParent();
assertEquals(2, a2.getTable2Array().size());
assertTrue(a2.getTable2Array().contains(py2));
assertFalse("Peer data context became dirty on event processing", peer2.hasChanges());
}
Aggregations