Package com.rapleaf.jack.test_project.database_1

Examples of com.rapleaf.jack.test_project.database_1.BaseDatabase1Fixtures


  public void testQueryWithOrder(IDatabases dbs) throws IOException, SQLException {

    IUserPersistence users = dbs.getDatabase1().users();
    users.deleteAll();

    User userA = users.createDefaultInstance().setHandle("A").setBio("CEO").setNumPosts(1).setSomeDecimal(0.9);
    User userB = users.createDefaultInstance().setHandle("B").setBio("Engineer").setNumPosts(2).setSomeDecimal(12.1);
    User userC = users.createDefaultInstance().setHandle("C").setBio("Analyst").setNumPosts(3).setSomeDecimal(-0.8);
    User userD = users.createDefaultInstance().setHandle("D").setBio("Dean").setNumPosts(3).setSomeDecimal(0.9);
    User userE = users.createDefaultInstance().setHandle("E").setBio("Associate").setNumPosts(3).setSomeDecimal(1.1);
    User userF = users.createDefaultInstance().setHandle("F").setBio("Associate").setNumPosts(6).setSomeDecimal(1.0);
    User userG = users.createDefaultInstance().setHandle("G").setBio("Associate").setNumPosts(5).setSomeDecimal(2.0);
    User userH = users.createDefaultInstance().setHandle("H").setBio("Associate").setNumPosts(7).setSomeDecimal(0.0);
    userA.save();
    userB.save();
    userC.save();
    userD.save();
    userE.save();
    userF.save();
    userG.save();
    userH.save();

    List<User> orderedResult1;
    List<User> orderedResult2;

    // An empty query should return an empty list.
View Full Code Here


  public void testQueryWithSelect(IDatabases dbs) throws IOException, SQLException {

    IUserPersistence users = dbs.getDatabase1().users();
    users.deleteAll();

    User userA = users.createDefaultInstance().setHandle("AAAA").setBio("Batman").setCreatedAtMillis(1L).setNumPosts(1);
    User userB = users.createDefaultInstance().setHandle("BBBB").setBio("Superman").setCreatedAtMillis(1L);
    User userC = users.createDefaultInstance().setHandle("CCCC").setBio("Spiderman").setCreatedAtMillis(1L);
    userA.save();
    userB.save();
    userC.save();

    Collection<User> result;

    result = users.query().select(User._Fields.handle)
        .whereBio(endsWith("man"))
View Full Code Here

  public void testGroupBy(IDatabases dbs) throws IOException, SQLException {
    IUserPersistence users = dbs.getDatabase1().users();
    users.deleteAll();

    for (int i = 0; i < 100; i++) {
      User user = users.createDefaultInstance().setHandle(String.valueOf(i % 2)).setNumPosts(i);
      user.save();
    }

    List<User> result;

    // Test Max
View Full Code Here

  }

  // this test is duplicated because of some weirdness with single quote escaping that appears contstrained to the mock mysql.
  public void testFindAllWithEscapedQuotesInStrings() throws Exception {
    IUserPersistence users = dbs.getDatabase1().users();
    User u1 = users.create("brya'nd", System.currentTimeMillis(), 5, System.currentTimeMillis() + 10, System.currentTimeMillis() + 20, "this is a relatively long string", new byte[]{5, 4, 3, 2, 1}, 1.2d, 3.4d, true);
    User u2 = users.create("thoma\"sk", null, 5, System.currentTimeMillis() + 10, System.currentTimeMillis() + 20, "this is a relatively long string", new byte[]{5, 4, 3, 2, 1}, 1.2d, 3.4d, true);

    assertEquals(Collections.singleton(u1), users.findAll("handle = 'brya\\'nd'"));
    assertEquals(Collections.singleton(u2), users.findAll("handle = 'thoma\"sk'"));
    assertEquals(Collections.singleton(u1), users.findAll("handle = 'brya\\'nd'"));
    assertEquals(Collections.singleton(u2), users.findAll("handle = 'thoma\"sk'"));
View Full Code Here

  @Override
  public void setUp() {
    dbs = new DatabasesImpl(DATABASE_CONNECTION1);
    postModel = new Post(0, "Test Post", 100l, 1, 0l);
    imageModel = new Image(0, null, dbs);
    userModel = new User(0l, "handle", 0l, 0, 0l, 0l, "bio", null, 0.0, 0.0, true);
    try {
      dbs.getDatabase1().deleteAll();
      dbs.getDatabase1().users().save(userModel);
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

    IUserPersistence users = dbs.getDatabase1().users();
    long t0 = System.currentTimeMillis();
    long t1 = t0 + 10;
    long t2 = t0 + 20;
    byte[] someBinary = new byte[]{5, 4, 3, 2, 1};
    User bryand = users.create("bryand", t0, 5, t1, t2, "this is a relatively long string", someBinary, 1.2d, 3.4d, true);
    verifyCreatedUser(users, t0, t1, t2, someBinary, bryand);
  }
View Full Code Here

    fieldsMap.put(User._Fields.some_binary, someBinary);
    fieldsMap.put(User._Fields.some_float, 1.2d);
    fieldsMap.put(User._Fields.some_decimal, 3.4d);
    fieldsMap.put(User._Fields.some_boolean, true);

    User bryand = (User)users.create(fieldsMap);
    verifyCreatedUser(users, t0, t1, t2, someBinary, bryand);
  }
View Full Code Here

    verifyCreatedUser(users, t0, t1, t2, someBinary, bryand);
  }

  public void testCreateWithDefaultValues() throws IOException {
    IUserPersistence users = dbs.getDatabase1().users();
    User user = users.createDefaultInstance();
  }
View Full Code Here

    IUserPersistence users = dbs.getDatabase1().users();
    long t0 = System.currentTimeMillis();
    long t1 = t0 + 10;
    long t2 = t0 + 20;
    byte[] someBinary = new byte[]{5, 4, 3, 2, 1};
    User bryand = users.create("bryand", t0, 5, t1, t2, "this is a relatively long string", someBinary, 1.2d, 3.4d, true);

    User bryand_again = users.find(bryand.getId());
    assertEquals(bryand.getId(), bryand_again.getId());
    assertEquals("bryand", bryand_again.getHandle());
    assertEquals(Long.valueOf(t0), bryand_again.getCreatedAtMillis());
    assertEquals(5, bryand_again.getNumPosts());
    // need to figure out what the appropriate rounding is...
    // assertEquals(Long.valueOf(t1), bryand_again.getSomeDate());
    // need to figure out what the appropriate rounding is...
    // assertEquals(Long.valueOf(t2), bryand_again.getSomeDatetime());
    assertEquals("this is a relatively long string", bryand_again.getBio());
    assertEquals(ByteBuffer.wrap(someBinary), ByteBuffer.wrap(bryand_again.getSomeBinary()));
    assertEquals(1.2, bryand_again.getSomeFloat());
    assertEquals(3.4, bryand_again.getSomeDecimal());
    assertTrue(bryand_again.isSomeBoolean());
  }
View Full Code Here

    IUserPersistence users = dbs.getDatabase1().users();
    long t0 = System.currentTimeMillis();
    long t1 = t0 + 10;
    long t2 = t0 + 20;
    byte[] someBinary = new byte[]{5, 4, 3, 2, 1};
    User bryand = users.create("bryand", t0, 5, t1, t2, "this is a relatively long string", someBinary, 1.2d, 3.4d, true);
    User notBryand = users.create("notBryand", t0, 3, t1, t2, "another relatively long string", someBinary, 1.2d, 3.4d, true);
    users.create("unwanted", t0, 0, t1, t2, "yet another relatively long string", someBinary, 1.2d, 3.4d, true);

    users.clearCacheById(bryand.getId());
    users.clearCacheById(notBryand.getId());
    Set<Long> keysToSearch = new HashSet<Long>();
    keysToSearch.add(bryand.getId());
    keysToSearch.add(notBryand.getId());
    Set<User> foundValues = users.find(keysToSearch);

    assertEquals(2, foundValues.size());
    Iterator<User> iter = foundValues.iterator();
    User bryand_again = null;
    User notBryand_again = null;
    while (iter.hasNext()) {
      User curUser = iter.next();
      if (curUser.getId() == bryand.getId()) {
        bryand_again = curUser;
      } else if (curUser.getId() == notBryand.getId()) {
        notBryand_again = curUser;
      } else {
        fail("Unexpected user id: " + curUser.getId());
      }
    }
    assertNotNull(bryand_again);
    assertNotNull(notBryand_again);
View Full Code Here

TOP

Related Classes of com.rapleaf.jack.test_project.database_1.BaseDatabase1Fixtures

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.