Example #1
0
 /** @throws Exception */
 @Test
 public void modelToEntity() throws Exception {
   Hoge hoge = new Hoge();
   Entity entity = DatastoreUtil.modelToEntity(ds, hoge);
   assertThat((Long) entity.getProperty("version"), is(1L));
   assertThat(hoge.getKey(), is(notNullValue()));
   assertThat(hoge.getKey(), is(entity.getKey()));
 }
Example #2
0
 /** @throws Exception */
 @Test
 public void modelsToEntities() throws Exception {
   Hoge hoge = new Hoge();
   Entity entity = new Entity("Hoge");
   List<Entity> entities = DatastoreUtil.modelsToEntities(ds, Arrays.asList(hoge, entity));
   assertThat(entities.size(), is(2));
   assertThat((Long) entities.get(0).getProperty("version"), is(1L));
   assertThat(hoge.getKey(), is(notNullValue()));
   assertThat(hoge.getKey(), is(entities.get(0).getKey()));
 }
Example #3
0
  /** @throws Exception */
  @Test
  public void sortInMemoryForEnumWhenDescending() throws Exception {
    List<Hoge> list = new ArrayList<Hoge>();
    Hoge hoge = new Hoge();
    hoge.setMyEnum(SortDirection.ASCENDING);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyEnum(SortDirection.DESCENDING);
    list.add(hoge);

    List<Hoge> sorted =
        DatastoreUtil.sortInMemory(list, Arrays.asList((InMemorySortCriterion) meta.myEnum.desc));
    assertThat(sorted.size(), is(2));
    assertThat(sorted.get(0).getMyEnum(), is(SortDirection.DESCENDING));
    assertThat(sorted.get(1).getMyEnum(), is(SortDirection.ASCENDING));
  }
Example #4
0
  /** @throws Exception */
  @Test
  public void filterInMemoryForEnum() throws Exception {
    List<Hoge> list = new ArrayList<Hoge>();
    Hoge hoge = new Hoge();
    hoge.setMyEnum(SortDirection.ASCENDING);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyEnum(SortDirection.DESCENDING);
    list.add(hoge);

    List<Hoge> filtered =
        DatastoreUtil.filterInMemory(
            list, Arrays.asList(meta.myEnum.equal(SortDirection.ASCENDING)));
    assertThat(filtered.size(), is(1));
    assertThat(filtered.get(0).getMyEnum(), is(SortDirection.ASCENDING));
  }
Example #5
0
  /** @throws Exception */
  @Test
  public void sortInMemory() throws Exception {
    List<Hoge> list = new ArrayList<Hoge>();
    Hoge hoge = new Hoge();
    hoge.setMyInteger(1);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(3);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(2);
    list.add(hoge);

    List<Hoge> sorted =
        DatastoreUtil.sortInMemory(
            list, Arrays.asList((InMemorySortCriterion) meta.myInteger.desc));
    assertThat(sorted.size(), is(3));
    assertThat(sorted.get(0).getMyInteger(), is(3));
    assertThat(sorted.get(1).getMyInteger(), is(2));
    assertThat(sorted.get(2).getMyInteger(), is(1));
  }
Example #6
0
  /** @throws Exception */
  @Test
  public void filterInMemory() throws Exception {
    List<Hoge> list = new ArrayList<Hoge>();
    Hoge hoge = new Hoge();
    hoge.setMyInteger(1);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(3);
    list.add(hoge);
    hoge = new Hoge();
    hoge.setMyInteger(2);
    list.add(hoge);

    List<Hoge> filtered =
        DatastoreUtil.filterInMemory(
            list,
            Arrays.asList(
                (InMemoryFilterCriterion) meta.myInteger.greaterThanOrEqual(2),
                (InMemoryFilterCriterion) meta.myInteger.lessThan(3)));
    assertThat(filtered.size(), is(1));
    assertThat(filtered.get(0).getMyInteger(), is(2));
  }