Package org.springframework.data.mongodb.core.query

Examples of org.springframework.data.mongodb.core.query.Update


   * @see DATAMONGO-812
   */
  @Test
  public void updateMapperShouldConvertPushWhithoutAddingClassInformationWhenUsedWithEvery() {

    Update update = new Update().push("values").each("spring", "data", "mongodb");

    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Model.class));
    DBObject push = getAsDBObject(mappedObject, "$push");
    DBObject values = getAsDBObject(push, "values");

    assertThat(push.get("_class"), nullValue());
    assertThat(values.get("_class"), nullValue());
View Full Code Here


   */
  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void updateMapperShouldConvertPushCorrectlyWhenCalledWithEachUsingCustomTypes() {

    Update update = new Update().push("models").each(new ListModel("spring", "data", "mongodb"));
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ModelWrapper.class));

    DBObject push = getAsDBObject(mappedObject, "$push");
    DBObject model = getAsDBObject(push, "models");
    BasicDBList each = getAsDBList(model, "$each");
View Full Code Here

   * @see DATAMONGO-812
   */
  @Test
  public void updateMapperShouldRetainClassInformationForPushCorrectlyWhenCalledWithEachUsingCustomTypes() {

    Update update = new Update().push("models").each(new ListModel("spring", "data", "mongodb"));
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(ModelWrapper.class));

    DBObject push = getAsDBObject(mappedObject, "$push");
    DBObject model = getAsDBObject(push, "models");
    BasicDBList each = getAsDBList(model, "$each");
View Full Code Here

   * @see DATAMONGO-812
   */
  @Test
  public void testUpdateShouldAllowMultiplePushEachForDifferentFields() {

    Update update = new Update().push("category").each("spring", "data").push("type").each("mongodb");
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Object.class));

    DBObject push = getAsDBObject(mappedObject, "$push");
    assertThat(getAsDBObject(push, "category").containsField("$each"), is(true));
    assertThat(getAsDBObject(push, "type").containsField("$each"), is(true));
  }
View Full Code Here

    List<NestedEntity> someValues = Arrays.asList(new NestedEntity("spring"), new NestedEntity("data"),
        new NestedEntity("mongodb"));
    NestedEntity[] array = new NestedEntity[someValues.size()];

    Update update = new Update().pushAll("collectionOfNestedEntities", someValues.toArray(array));
    mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(DomainEntity.class));

    verify(writingConverterSpy, times(3)).convert(Mockito.any(NestedEntity.class));
  }
View Full Code Here

   * @see DATAMONGO-404
   */
  @Test
  public void createsDbRefForEntityIdOnPulls() {

    Update update = new Update().pull("dbRefAnnotatedList.id", "2");

    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject pullClause = getAsDBObject(mappedObject, "$pull");
    assertThat(pullClause.get("dbRefAnnotatedList"), is((Object) new DBRef(null, "entity", "2")));
  }
View Full Code Here

  public void createsDbRefForEntityOnPulls() {

    Entity entity = new Entity();
    entity.id = "5";

    Update update = new Update().pull("dbRefAnnotatedList", entity);
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject pullClause = getAsDBObject(mappedObject, "$pull");
    assertThat(pullClause.get("dbRefAnnotatedList"), is((Object) new DBRef(null, "entity", entity.id)));
  }
View Full Code Here

   * @see DATAMONGO-404
   */
  @Test(expected = MappingException.class)
  public void rejectsInvalidFieldReferenceForDbRef() {

    Update update = new Update().pull("dbRefAnnotatedList.name", "NAME");
    mapper.getMappedObject(update.getUpdateObject(), context.getPersistentEntity(DocumentWithDBRefCollection.class));
  }
View Full Code Here

   * @see DATAMONGO-404
   */
  @Test
  public void rendersNestedDbRefCorrectly() {

    Update update = new Update().pull("nested.dbRefAnnotatedList.id", "2");
    DBObject mappedObject = mapper
        .getMappedObject(update.getUpdateObject(), context.getPersistentEntity(Wrapper.class));

    DBObject pullClause = getAsDBObject(mappedObject, "$pull");
    assertThat(pullClause.containsField("mapped.dbRefAnnotatedList"), is(true));
  }
View Full Code Here

  public void rendersUpdateOfDbRefPropertyWithDomainObjectCorrectly() {

    Entity entity = new Entity();
    entity.id = "5";

    Update update = new Update().set("dbRefProperty", entity);
    DBObject mappedObject = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject setClause = getAsDBObject(mappedObject, "$set");
    assertThat(setClause.get("dbRefProperty"), is((Object) new DBRef(null, "entity", entity.id)));
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.query.Update

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.