Пример #1
0
  @Test
  public void testEntityManager() throws Exception {
    logger.info("EntityManagerTest.testEntityManagerTest");

    UUID applicationId = createApplication("testEntityManagerTest");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "edanuff");
    properties.put("email", "*****@*****.**");

    Entity user = em.create("user", properties);
    assertNotNull(user);

    user = em.get(user);
    assertNotNull(user);
    assertEquals("user.username not expected value", "edanuff", user.getProperty("username"));
    assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email"));

    EntityRef userRef = em.getAlias(applicationId, "user", "edanuff");
    assertNotNull(userRef);
    assertEquals("userRef.id not expected value", user.getUuid(), userRef.getUuid());
    assertEquals("userRef.type not expected value", "user", userRef.getType());

    logger.info("user.username: "******"username"));
    logger.info("user.email: " + user.getProperty("email"));

    Results results =
        em.searchCollection(
            em.getApplicationRef(), "users", new Query().addEqualityFilter("username", "edanuff"));
    assertNotNull(results);
    assertEquals(1, results.size());
    user = results.getEntity();
    assertNotNull(user);
    assertEquals("user.username not expected value", "edanuff", user.getProperty("username"));
    assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email"));

    logger.info("user.username: "******"username"));
    logger.info("user.email: " + user.getProperty("email"));

    results =
        em.searchCollection(
            em.getApplicationRef(),
            "users",
            new Query().addEqualityFilter("email", "*****@*****.**"));
    assertNotNull(results);
    assertEquals(1, results.size());
    user = results.getEntity();
    assertNotNull(user);
    assertEquals("user.username not expected value", "edanuff", user.getProperty("username"));
    assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email"));

    logger.info("user.username: "******"username"));
    logger.info("user.email: " + user.getProperty("email"));
  }
Пример #2
0
  @Test
  public void testSelectEmailViaConnection() throws Exception {

    UUID applicationId = createApplication("testOrganization", "testSelectEmail");

    EntityManager em = emf.getEntityManager(applicationId);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put("username", "*****@*****.**");
    properties.put("email", "*****@*****.**");

    em.create("user", properties);

    String s = "select * where username = '******'";
    Query query = Query.fromQL(s);

    Results r = em.searchCollection(em.getApplicationRef(), "users", query);
    assertTrue(r.size() == 1);

    // selection results should be a list of lists
    Entity entity = r.getEntity();

    assertTrue("*****@*****.**".equals(entity.getProperty("username")));
    assertTrue("*****@*****.**".equals(entity.getProperty("email")));

    // now create a role and connect it
    properties = new LinkedHashMap<String, Object>();
    properties.put("name", "test");

    Entity foo = em.create("foo", properties);

    em.createConnection(foo, "testconnection", entity);

    // now query via the testConnection, this should work

    query = Query.fromQL(s);
    query.setConnectionType("testconnection");
    query.setEntityType("user");

    r = em.searchConnectedEntities(foo, query);

    assertTrue(r.size() == 1);

    // selection results should be a list of lists
    entity = r.getEntity();
    assertTrue("*****@*****.**".equals(entity.getProperty("username")));
    assertTrue("*****@*****.**".equals(entity.getProperty("email")));
  }
Пример #3
0
  @Test
  public void testCollectionFilters() throws Exception {
    logger.info("testCollectionFilters");

    UUID applicationId = createApplication("testOrganization", "testCollectionFilters");
    assertNotNull(applicationId);

    EntityManager em = emf.getEntityManager(applicationId);
    assertNotNull(em);

    for (int i = alphabet.length - 1; i >= 0; i--) {
      String name = alphabet[i];
      Map<String, Object> properties = new LinkedHashMap<String, Object>();
      properties.put("name", name);

      em.create("item", properties);
    }

    Query query = Query.fromQL("name < 'delta'");
    Results r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    int i = 0;
    for (Entity entity : r.getEntities()) {
      assertEquals(alphabet[i], entity.getProperty("name"));
      i++;
    }
    assertEquals(3, i);

    query = Query.fromQL("name <= 'delta'");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 0;
    for (Entity entity : r.getEntities()) {
      assertEquals(alphabet[i], entity.getProperty("name"));
      i++;
    }
    assertEquals(4, i);

    query = Query.fromQL("name <= 'foxtrot' and name > 'bravo'");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 2;
    for (Entity entity : r.getEntities()) {
      assertEquals(alphabet[i], entity.getProperty("name"));
      i++;
    }
    assertEquals(6, i);

    query = Query.fromQL("name < 'foxtrot' and name > 'bravo'");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 2;
    for (Entity entity : r.getEntities()) {
      assertEquals(alphabet[i], entity.getProperty("name"));
      i++;
    }
    assertEquals(5, i);

    query = Query.fromQL("name < 'foxtrot' and name >= 'bravo'");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 1;
    for (Entity entity : r.getEntities()) {
      assertEquals(alphabet[i], entity.getProperty("name"));
      i++;
    }
    assertEquals(5, i);

    query = Query.fromQL("name <= 'foxtrot' and name >= 'bravo'");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 1;
    for (Entity entity : r.getEntities()) {
      assertEquals(alphabet[i], entity.getProperty("name"));
      i++;
    }
    assertEquals(6, i);

    query = Query.fromQL("name <= 'foxtrot' and name >= 'bravo' order by name desc");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 6;
    for (Entity entity : r.getEntities()) {
      i--;
      assertEquals(alphabet[i], entity.getProperty("name"));
    }
    assertEquals(1, i);

    query = Query.fromQL("name < 'foxtrot' and name > 'bravo' order by name desc");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 5;
    for (Entity entity : r.getEntities()) {
      i--;
      assertEquals(alphabet[i], entity.getProperty("name"));
    }
    assertEquals(2, i);

    query = Query.fromQL("name < 'foxtrot' and name >= 'bravo' order by name desc");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    i = 5;
    for (Entity entity : r.getEntities()) {
      i--;
      assertEquals(alphabet[i], entity.getProperty("name"));
    }
    assertEquals(1, i);

    query = Query.fromQL("name = 'foxtrot'");
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    assertEquals(1, r.size());

    long created = r.getEntity().getCreated();
    UUID entityId = r.getEntity().getUuid();

    query = Query.fromQL("created = " + created);
    r = em.searchCollection(em.getApplicationRef(), "items", query);
    logger.info(JsonUtils.mapToFormattedJsonString(r.getEntities()));
    assertEquals(1, r.size());
    assertEquals(entityId, r.getEntity().getUuid());
  }