Search in sources :

Example 1 with RemotePersistenceManager

use of siena.remote.RemotePersistenceManager in project siena by mandubian.

the class SienaRemoteTest method testSecurity.

public void testSecurity() {
    MockPersistenceManager mock = new MockPersistenceManager();
    PersistenceManagerFactory.install(mock, Person.class);
    RemotePersistenceManager remote = new RemotePersistenceManager();
    Properties properties = new Properties();
    properties.setProperty("connector", MockConnector.class.getName());
    properties.setProperty("serializer", MockConnector.class.getName());
    properties.setProperty("key", "siena");
    remote.init(properties);
    remote.createQuery(Person.class).fetch();
}
Also used : RemotePersistenceManager(siena.remote.RemotePersistenceManager) Properties(java.util.Properties)

Example 2 with RemotePersistenceManager

use of siena.remote.RemotePersistenceManager in project siena by mandubian.

the class SienaRemoteTest method testFailSecurity.

public void testFailSecurity() {
    MockPersistenceManager mock = new MockPersistenceManager();
    PersistenceManagerFactory.install(mock, Person.class);
    RemotePersistenceManager remote = new RemotePersistenceManager();
    Properties properties = new Properties();
    properties.setProperty("connector", MockConnector.class.getName());
    properties.setProperty("serializer", MockConnector.class.getName());
    properties.setProperty("key", "siena");
    remote.init(properties);
    MockConnector.key = "1234";
    try {
        remote.createQuery(Person.class).fetch();
    } catch (SienaException e) {
        return;
    }
    fail("It should have failed due to invalid hash");
}
Also used : RemotePersistenceManager(siena.remote.RemotePersistenceManager) SienaException(siena.SienaException) Properties(java.util.Properties)

Example 3 with RemotePersistenceManager

use of siena.remote.RemotePersistenceManager in project siena by mandubian.

the class SienaRemoteTest method testRemote.

public void testRemote() {
    MockPersistenceManager mock = new MockPersistenceManager();
    PersistenceManagerFactory.install(mock, Person.class);
    RemotePersistenceManager remote = new RemotePersistenceManager();
    Properties properties = new Properties();
    properties.setProperty("connector", MockConnector.class.getName());
    properties.setProperty("serializer", MockConnector.class.getName());
    remote.init(properties);
    remote.insert(TESLA);
    assertEquals("insert", mock.action);
    assertEquals(TESLA, mock.object);
    remote.update(TESLA);
    assertEquals("update", mock.action);
    assertEquals(TESLA, mock.object);
    Person expected = new Person();
    expected.id = TESLA.id;
    remote.delete(TESLA);
    assertEquals("delete", mock.action);
    assertEquals(expected, mock.object);
    remote.get(TESLA);
    assertEquals("get", mock.action);
    assertEquals(expected, mock.object);
    remote.createQuery(Person.class).fetch();
    assertEquals(0, mock.lastQuery.filters.size());
    assertEquals(0, mock.lastQuery.orders.size());
    remote.createQuery(Person.class).order("firstName").order("lastName").fetch();
    assertEquals(0, mock.lastQuery.filters.size());
    assertEquals(Arrays.asList("firstName", "lastName"), mock.lastQuery.orders);
    remote.createQuery(Person.class).filter("city", "Ulm").filter("firstName", "Albert").filter("lastName", null).order("firstName").order("lastName").fetch();
    assertEquals(3, mock.lastQuery.filters.size());
    assertEquals("city", ((Object[]) mock.lastQuery.filters.get(0))[0]);
    assertEquals("Ulm", ((Object[]) mock.lastQuery.filters.get(0))[1]);
    assertEquals("firstName", ((Object[]) mock.lastQuery.filters.get(1))[0]);
    assertEquals("Albert", ((Object[]) mock.lastQuery.filters.get(1))[1]);
    assertEquals("lastName", ((Object[]) mock.lastQuery.filters.get(2))[0]);
    assertEquals(null, ((Object[]) mock.lastQuery.filters.get(2))[1]);
    assertEquals(Arrays.asList("firstName", "lastName"), mock.lastQuery.orders);
}
Also used : RemotePersistenceManager(siena.remote.RemotePersistenceManager) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)3 RemotePersistenceManager (siena.remote.RemotePersistenceManager)3 SienaException (siena.SienaException)1