public void testColors() {
    Set<Class<?>> classes = Sets.newHashSet();
    classes.add(ColorsBean.class);
    IMappingContextFactory<?> factory =
        new IMappingContextFactory<IMappingContext>() {
          @Override
          public IMappingContext newContext() {
            return new ColorMappingContext();
          }
        };
    Transformations transformations = new Transformations(factory, classes);
    IDatastore datastore = new Datastore(getMongo(), getDatabaseName(), transformations);
    datastore.ensureCaps();
    datastore.ensureIndexes();

    ColorsBean colors = new ColorsBean();
    colors.setColors(Lists.newArrayList(new Color(103, 53, 23, 43), new Color(206, 106, 56, 86)));
    datastore.save(colors);
    colors.setColors(Lists.newArrayList(new Color(100, 50, 25, 44), new Color(200, 100, 50, 88)));
    datastore.update(colors);
    colors = new ColorsBean();
    colors.setColors(Lists.newArrayList(new Color(100, 50, 25, 44)));
    datastore.save(colors);

    List<ColorsBean> list = datastore.find(ColorsBean.class);
    assertEquals("Size", 2, list.size());
    //		System.out.println("Books: "+books);

    list =
        datastore
            .with(ColorsBean.class)
            .field(ColorsBean.Colors)
            .field(Colors.Red)
            .eq(100)
            .result()
            .asList();
    assertEquals("Size", 2, list.size());

    list =
        datastore
            .with(ColorsBean.class)
            .field(ColorsBean.Colors)
            .field(Colors.Red)
            .eq(200)
            .result()
            .asList();
    assertEquals("Size", 1, list.size());

    list =
        datastore
            .with(ColorsBean.class)
            .field(Property.ref("colors", List.class))
            .field(Property.ref("r", Integer.class))
            .eq(200)
            .result()
            .asList();
    assertEquals("Size", 1, list.size());
  }
  public void testBooks() {
    Set<Class<?>> classes = Sets.newHashSet();
    classes.add(Book.class);
    IMappingContextFactory<?> factory =
        new IMappingContextFactory<IMappingContext>() {
          @Override
          public IMappingContext newContext() {
            return new ColorMappingContext();
          }
        };
    Transformations transformations = new Transformations(factory, classes);
    IDatastore datastore = new Datastore(getMongo(), getDatabaseName(), transformations);
    datastore.ensureCaps();
    datastore.ensureIndexes();

    Book book = new Book();
    book.setName("Bla");
    datastore.save(book);
    book.setName("Blu");
    datastore.update(book);
    book = new Book();
    book.setName("2. Buch");
    datastore.save(book);

    List<Book> books = datastore.find(Book.class);
    assertEquals("Size", 2, books.size());
    //		System.out.println("Books: "+books);

    books = datastore.with(Book.class).field(Book.Name).eq("Blu").result().asList();
    assertEquals("Size", 1, books.size());

    for (int i = 0; i < 10; i++) {
      book = new Book();
      book.setName(i + ". Buch");
      datastore.save(book);
    }

    books = datastore.with(Book.class).result().order("name", false).asList();
    System.out.println("Books: " + books);
    assertEquals("Size", 9, books.size());
    assertEquals("9. Buch", "9. Buch", books.get(0).getName());
  }
  public void testArticles() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2011);
    cal.set(Calendar.MONTH, Calendar.FEBRUARY);
    cal.set(Calendar.DAY_OF_MONTH, 4);
    cal.set(Calendar.HOUR, 15);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 45);
    cal.set(Calendar.MILLISECOND, 0);
    Date date = cal.getTime();

    Set<Class<?>> classes = Sets.newLinkedHashSet();
    classes.add(Book.class);
    classes.add(Article.class);
    IMappingContextFactory<?> factory =
        new IMappingContextFactory<IMappingContext>() {
          @Override
          public IMappingContext newContext() {
            return new DateMappingContext();
          }
        };
    Transformations transformations = new Transformations(factory, classes);
    IDatastore datastore = new Datastore(getMongo(), getDatabaseName(), transformations);
    datastore.ensureCaps();
    datastore.ensureIndexes();

    Article article = new Article();
    article.setName("Bla");
    datastore.save(article);
    article.setName("Blu");
    datastore.update(article);
    article = new Article();
    article.setName("2. Buch");
    article.setCreated(date);
    datastore.save(article);

    List<Article> articles = datastore.find(Article.class);
    assertEquals("Size", 2, articles.size());
    //		System.out.println("Books: "+books);

    articles =
        datastore
            .with(Article.class)
            .field(Article.Created)
            .field(Dates.Year)
            .eq(2011)
            .result()
            .asList();
    assertEquals("Size", 1, articles.size());
    articles =
        datastore
            .with(Article.class)
            .field(Article.Created)
            .field(Dates.Year)
            .eq(2010)
            .result()
            .asList();
    assertEquals("Size", 0, articles.size());
    articles =
        datastore
            .with(Article.class)
            .field(Article.Created)
            .field(Dates.Year)
            .gt(2010)
            .result()
            .asList();
    assertEquals("Size", 1, articles.size());
  }