コード例 #1
0
  @Test
  public void testUpdateRetry() {
    TenantContext.setTenantId("SLIUnitTest");
    repository.deleteAll("student", null);

    DBObject indexKeys = new BasicDBObject("body.cityOfBirth", 1);
    mongoTemplate.getCollection("student").ensureIndex(indexKeys);

    repository.create("student", buildTestStudentEntity());

    Entity entity = repository.findOne("student", new NeutralQuery());
    Map<String, Object> studentBody = entity.getBody();
    studentBody.put("cityOfBirth", "ABC");

    Entity studentEntity =
        new MongoEntity("student", entity.getEntityId(), studentBody, entity.getMetaData());
    repository.updateWithRetries("student", studentEntity, 5);

    NeutralQuery neutralQuery = new NeutralQuery();
    neutralQuery.addCriteria(new NeutralCriteria("cityOfBirth=ABC"));
    assertEquals(1, repository.count("student", neutralQuery));

    repository.deleteAll("student", null);
    mongoTemplate.getCollection("student").dropIndex(indexKeys);
  }
コード例 #2
0
 @Test
 public void testCreateWithMetadata() {
   repository.deleteAll("student", null);
   Map<String, Object> studentBody = buildTestStudentEntity();
   Map<String, Object> studentMetaData = new HashMap<String, Object>();
   repository.create("student", studentBody, studentMetaData, "student");
   assertEquals(1, repository.count("student", new NeutralQuery()));
 }
コード例 #3
0
  @Test
  public void testCount() {
    repository.deleteAll("student", null);

    DBObject indexKeys = new BasicDBObject("body.cityOfBirth", 1);
    mongoTemplate.getCollection("student").ensureIndex(indexKeys);

    repository.create("student", buildTestStudentEntity());
    repository.create("student", buildTestStudentEntity());
    repository.create("student", buildTestStudentEntity());
    repository.create("student", buildTestStudentEntity());
    Map<String, Object> oddStudent = buildTestStudentEntity();
    oddStudent.put("cityOfBirth", "Nantucket");
    repository.create("student", oddStudent);
    assertEquals(5, repository.count("student", new NeutralQuery()));
    NeutralQuery neutralQuery = new NeutralQuery();
    neutralQuery.addCriteria(new NeutralCriteria("cityOfBirth=Nantucket"));
    assertEquals(1, repository.count("student", neutralQuery));

    repository.deleteAll("student", null);
    mongoTemplate.getCollection("student").dropIndex(indexKeys);
  }
コード例 #4
0
  @Test
  public void testDeleteAll() {
    repository.deleteAll("student", null);

    DBObject indexKeys = new BasicDBObject("body.firstName", 1);
    mongoTemplate.getCollection("student").ensureIndex(indexKeys);

    Map<String, Object> studentMap = buildTestStudentEntity();
    studentMap.put("firstName", "John");
    repository.create("student", buildTestStudentEntity());
    repository.create("student", buildTestStudentEntity());
    repository.create("student", buildTestStudentEntity());
    repository.create("student", buildTestStudentEntity());
    repository.create("student", studentMap);
    assertEquals(5, repository.count("student", new NeutralQuery()));
    NeutralQuery neutralQuery = new NeutralQuery();
    neutralQuery.addCriteria(new NeutralCriteria("firstName=John"));
    repository.deleteAll("student", neutralQuery);
    assertEquals(4, repository.count("student", new NeutralQuery()));

    repository.deleteAll("student", null);
    mongoTemplate.getCollection("student").dropIndex(indexKeys);
  }