Java 类org.hamcrest.collection.IsCollectionWithSize 实例源码

项目:vind    文件:TestServerPojoTest.java   
@Test
public void testMultipleBeanIndex() {
    final SearchServer server = searchServer.getSearchServer();

    final Pojo doc1 = Pojo.create("doc1", "Eins", "Erstes Dokument", "simple");
    final Pojo doc2 = Pojo.create("doc2", "Zwei", "Zweites Dokument", "simple");
    final Pojo doc3 = Pojo.create("doc3", "Drei", "Dieses ist das dritte Dokument", "complex");
    final Pojo doc4 = Pojo.create("doc4", "Vier", "Das vierte Dokument", "complex");

    server.indexBean(doc1,doc2);

    List<Object> beanList = new ArrayList<>();
    beanList.add(doc3);
    beanList.add(doc4);

    server.indexBean(beanList);
    server.commit();

    final BeanSearchResult<Pojo> all = server.execute(Search.fulltext(), Pojo.class);
    assertThat("#numOfResults", all.getNumOfResults(), CoreMatchers.equalTo(4l));
    assertThat("results.size()", all.getResults(), IsCollectionWithSize.hasSize(4));
    checkPojo(doc3, all.getResults().get(2));
    checkPojo(doc2, all.getResults().get(1));
    checkPojo(doc1, all.getResults().get(0));
    checkPojo(doc4, all.getResults().get(3));
}
项目:javaOIDCMsg    文件:PayloadDeserializerTest.java   
@Test
public void shouldGetStringArrayWhenParsingArrayNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    List<JsonNode> subNodes = new ArrayList<>();
    TextNode textNode1 = new TextNode("one");
    TextNode textNode2 = new TextNode("two");
    subNodes.add(textNode1);
    subNodes.add(textNode2);
    ArrayNode arrNode = new ArrayNode(JsonNodeFactory.instance, subNodes);
    tree.put("key", arrNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsCollectionWithSize.hasSize(2)));
    assertThat(values, is(IsCollectionContaining.hasItems("one", "two")));
}
项目:auth0-spring-security-api    文件:AuthenticationJsonWebTokenTest.java   
@Test
public void shouldGetScopeAsAuthorities() throws Exception {
    String token = JWT.create()
            .withClaim("scope", "auth0 auth10")
            .sign(hmacAlgorithm);

    AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsCollectionWithSize.hasSize(2)));

    ArrayList<GrantedAuthority> authorities = new ArrayList<>(auth.getAuthorities());
    assertThat(authorities.get(0), is(notNullValue()));
    assertThat(authorities.get(0).getAuthority(), is("auth0"));
    assertThat(authorities.get(1), is(notNullValue()));
    assertThat(authorities.get(1).getAuthority(), is("auth10"));
}
项目:microservices    文件:JujacoreProgressServiceTest.java   
@Test
public void shouldFetchAllProgressCodes() throws Exception {
    //Given
    final ProgressDao dao = Mockito.mock(ProgressDao.class);
    final ProgressService service = new JujacoreProgressService(
        "", dao, Mockito.mock(SlackSession.class)
    );
    Mockito.when(dao.fetchProgressCodes()).thenReturn(Arrays.asList(
        "+code1", "+code2", "+code1"
    ));
    //When
    final Set<String> codes = service.codes();
    //Then
    MatcherAssert.assertThat(
        codes, IsCollectionWithSize.hasSize(2)
    );
    MatcherAssert.assertThat(
        codes, IsCollectionContaining.hasItems(
            "+code1", "+code2"
        )
    );
}
项目:microservices    文件:JujacoreProgressServiceTest.java   
@Test
public void shouldExcludeBlackListedCodes() throws Exception {
    //Given
    final ProgressDao dao = Mockito.mock(ProgressDao.class);
    final ProgressService service = new JujacoreProgressService(
        "+blackListCode1;+blackListCode2", dao,
        Mockito.mock(SlackSession.class)
    );
    Mockito.when(dao.fetchProgressCodes()).thenReturn(Arrays.asList(
        "+code1", "+blackListCode1", "+blackListCode2", "+code2"
    ));
    //When
    final Set<String> actualProgressCodes = service.codes();
    //Then
    MatcherAssert.assertThat(
        actualProgressCodes, IsCollectionWithSize.hasSize(2)
    );
    MatcherAssert.assertThat(
        actualProgressCodes, IsCollectionContaining.hasItems(
            "+code1", "+code2"
        )
    );
}
项目:statistics    文件:FilterTest.java   
@Test
public void testHalfPassMatcher() {
  Set<TreeNode> input = new HashSet<>();
  input.add(createTreeNode(A.class));
  input.add(createTreeNode(B.class));

  assertThat(buildQuery(new Matcher<TreeNode>() {

    private boolean match;

    @Override
    protected boolean matchesSafely(TreeNode object) {
      return match ^= true;
    }
  }).execute(input), IsCollectionWithSize.hasSize(input.size() / 2));
}
项目:java-jwt    文件:PayloadDeserializerTest.java   
@Test
public void shouldGetStringArrayWhenParsingArrayNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    List<JsonNode> subNodes = new ArrayList<>();
    TextNode textNode1 = new TextNode("one");
    TextNode textNode2 = new TextNode("two");
    subNodes.add(textNode1);
    subNodes.add(textNode2);
    ArrayNode arrNode = new ArrayNode(JsonNodeFactory.instance, subNodes);
    tree.put("key", arrNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsCollectionWithSize.hasSize(2)));
    assertThat(values, is(IsCollectionContaining.hasItems("one", "two")));
}
项目:vind    文件:TestServerPojoTest.java   
@Test
public void testPojoRoundtrip() {
    final SearchServer server = searchServer.getSearchServer();

    final Pojo doc1 = Pojo.create("doc1", "Eins", "Erstes Dokument", "simple");
    final Pojo doc2 = Pojo.create("doc2", "Zwei", "Zweites Dokument", "simple");
    final Pojo doc3 = Pojo.create("doc3", "Drei", "Dieses ist das dritte Dokument", "complex");
    final Pojo doc4 = Pojo.create("doc3", "Drei", "Dieses ist das dritte Dokument", "complex");

    server.indexBean(doc1);
    server.indexBean(doc2);
    server.indexBean(doc3);
    server.commit();

    final BeanSearchResult<Pojo> dritte = server.execute(Search.fulltext("dritte"), Pojo.class);
    assertThat("#numOfResults", dritte.getNumOfResults(), CoreMatchers.equalTo(1l));
    assertThat("results.size()", dritte.getResults(), IsCollectionWithSize.hasSize(1));
    checkPojo(doc3, dritte.getResults().get(0));

    final BeanSearchResult<Pojo> all = server.execute(Search.fulltext()
            .facet("category")
            .filter(or(eq("title", "Eins"), or(eq("title", "Zwei"),eq("title","Drei"))))
            .sort("_id_", Sort.Direction.Desc), Pojo.class); //TODO create special sort for reserved fields (like score, type, id)
    assertThat("#numOfResults", all.getNumOfResults(), CoreMatchers.equalTo(3l));
    assertThat("results.size()", all.getResults(), IsCollectionWithSize.hasSize(3));
    checkPojo(doc3, all.getResults().get(0));
    checkPojo(doc2, all.getResults().get(1));
    checkPojo(doc1, all.getResults().get(2));

    TermFacetResult<String> facets = all.getFacetResults().getTermFacet("category", String.class);
    assertEquals(2,facets.getValues().size());
    assertEquals("simple", facets.getValues().get(0).getValue());
    assertEquals("complex",facets.getValues().get(1).getValue());
    assertEquals(2,facets.getValues().get(0).getCount());
    assertEquals(1,facets.getValues().get(1).getCount());
}
项目:vind    文件:TestServerPojoTest.java   
@Test
public void testTaxonomyPojo() {
    final SearchServer server = searchServer.getSearchServer();

    final Pojo1 doc1 = new Pojo1();
    doc1.id = "pojo-Id-1";
    doc1.title = "title 1";
    doc1.tax = new Taxonomy("term 1",1,"", ZonedDateTime.now(),Arrays.asList("term 1","term one"));

    final Pojo1 doc2 = new Pojo1();
    doc2.id = "pojo-Id-2";
    doc2.title = "title 2";
    doc2.tax = new Taxonomy("term 2",2,"", ZonedDateTime.now(),Arrays.asList("term 2","term two"));

    server.indexBean(doc1);
    server.indexBean(doc2);
    server.commit();

    final BeanSearchResult<Pojo1> second = server.execute(Search.fulltext("two"), Pojo1.class);
    assertThat("#numOfResults", second.getNumOfResults(), CoreMatchers.equalTo(1l));
    assertThat("results.size()", second.getResults(), IsCollectionWithSize.hasSize(1));
   // checkPojo(doc3, dritte.getResults().get(0));

   /* final BeanSearchResult<Pojo> all = server.execute(Search.fulltext()
            .facet("category")
            .filter(or(eq("title", "Eins"), or(eq("title", "Zwei"),eq("title","Drei"))))
            .sort("_id_", Sort.Direction.Desc), Pojo.class); //TODO create special sort for reserved fields (like score, type, id)
    assertThat("#numOfResults", all.getNumOfResults(), CoreMatchers.equalTo(3l));
    assertThat("results.size()", all.getResults(), IsCollectionWithSize.hasSize(3));
    checkPojo(doc3, all.getResults().get(0));
    checkPojo(doc2, all.getResults().get(1));
    checkPojo(doc1, all.getResults().get(2));

    TermFacetResult<String> facets = all.getFacetResults().getTermFacet("category", String.class);
    assertEquals(2,facets.getValues().size());
    assertEquals("simple", facets.getValues().get(0).getValue());
    assertEquals("complex",facets.getValues().get(1).getValue());
    assertEquals(2,facets.getValues().get(0).getCount());
    assertEquals(1,facets.getValues().get(1).getCount());*/
}
项目:javaOIDCMsg    文件:PayloadDeserializerTest.java   
@Test
public void shouldGetStringArrayWhenParsingTextNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    TextNode textNode = new TextNode("something");
    tree.put("key", textNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsCollectionWithSize.hasSize(1)));
    assertThat(values, is(IsCollectionContaining.hasItems("something")));
}
项目:javaOIDCMsg    文件:PayloadImplTest.java   
@Test
public void shouldGetAudience() throws Exception {
    assertThat(payload, is(notNullValue()));

    assertThat(payload.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(payload.getAudience(), is(IsCollectionContaining.hasItems("audience")));
}
项目:javaOIDCMsg    文件:JWTDecoderTest.java   
@Test
public void shouldGetArrayAudience() throws Exception {
    String token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsiSG9wZSIsIlRyYXZpcyIsIlNvbG9tb24iXX0.Tm4W8WnfPjlmHSmKFakdij0on2rWPETpoM7Sh0u6-S4";
    JWT jwt = JWT.require(Algorithm.HMAC256("secret")).build();
    DecodedJWT decodedJWT = jwt.decode(token);
    assertThat(decodedJWT, is(notNullValue()));
    assertThat(decodedJWT.getAudience(), is(IsCollectionWithSize.hasSize(3)));
    assertThat(decodedJWT.getAudience(), is(IsCollectionContaining.hasItems("Hope", "Travis", "Solomon")));
}
项目:javaOIDCMsg    文件:JWTDecoderTest.java   
@Test
public void shouldGetStringAudience() throws Exception {
    String token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJKYWNrIFJleWVzIn0.a4I9BBhPt1OB1GW67g2P1bEHgi6zgOjGUL4LvhE9Dgc";
    JWT jwt = JWT.require(Algorithm.HMAC256("secret")).build();
    DecodedJWT decodedJWT = jwt.decode(token);
    assertThat(decodedJWT, is(notNullValue()));
    assertThat(decodedJWT.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(decodedJWT.getAudience(), is(IsCollectionContaining.hasItems("Jack Reyes")));
}
项目:Parseux    文件:CsvAsDTOTest.java   
@Test
public void parsedSize() {
    MatcherAssert.assertThat(
        "DTOs has correct size",
        new CsvAsDTO<>(
            new InputStreamReader(
                new ResourceAsStream("csv/test.csv").stream()
            ),
            CsvTestDTO.class
        ).asDTOs(),
        IsCollectionWithSize.hasSize(4)
    );
}
项目:dashboard    文件:BundleControllerDeleteTest.java   
@Test
public void successDeleteBundle() throws Exception {

    BundleMetadata bundleMetadata = new BundleMetadata.Builder().name("ToDelete").build();
    bundleService.save(bundleMetadata);

    final long previousSize = bundleService.getAll().size();
    final long previousRevision = revisionService.getLatest();

    assertThat(bundleService.getAll().size(), Matchers.equalTo(1));
    assertThat(bundleMetadata.getUuid(), not(Matchers.isEmptyOrNullString()));
    assertThat(bundleMetadata.getTag(), not(Matchers.isEmptyOrNullString()));
    assertTrue(Files.exists(fileSystem.getPath(props.getBasePath(), BundleDaoImpl.ENTITY_NAME, bundleMetadata.getUuid() + ".yaml")));

    assertNotNull(bundleService.getByTag(bundleMetadata.getTag()));

    mockMvc.perform(deleteAuthenticated("/bundle/" + bundleMetadata.getTag()))
            .andExpect(status().isOk());

    mockMvc.perform(deleteAuthenticated("/bundle/" + bundleMetadata.getTag()))
            .andExpect(status().isNotFound());

    assertFalse(Files.exists(fileSystem.getPath(props.getBasePath(), BundleDaoImpl.ENTITY_NAME, bundleMetadata.getUuid() + ".yaml")));
    assertNull(bundleService.getByTag(bundleMetadata.getTag()));

    assertEquals(previousSize - 1, bundleService.getAll().size());
    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.DELETE);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.BUNDLE);
    assertEquals(revision.getTarget(), bundleMetadata.getUuid());
    assertEquals(revision.getResult(), null);
}
项目:dashboard    文件:BundleControllerCreateTest.java   
@Test
public void successWithBasic() throws Exception {
    long n = bundleService.getAll().size();
    final long previousRevision = revisionService.getLatest();
    final String name = "UnNom";

    MvcResult result = mockMvc.perform(postAuthenticated(("/bundle"))
            .content(toJson(new BundleMetadataDto.Builder().name(name).build()))
            .contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(status().isOk())
            .andReturn();

    BundleMetadataDto bundleMetadataDto = fromJson(result.getResponse().getContentAsString(), BundleMetadataDto.class);

    assertEquals(name, bundleMetadataDto.getName());
    assertNull(bundleMetadataDto.getValidity());
    assertNotNull(bundleMetadataDto.getUuid());
    assertEquals(StringUtils.normalize(name), bundleMetadataDto.getTag());

    // Vérification de la persistence
    assertNotNull(bundleService.getByTag(bundleMetadataDto.getTag()));
    Path path = fileSystem.getPath(props.getBasePath(), BundleDao.ENTITY_NAME, bundleMetadataDto.getUuid() + ".yaml");
    assertTrue(Files.isRegularFile(path));
    assertEquals(n + 1, bundleService.getAll().size());

    // Vérification de la récision
    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.ADD);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.BUNDLE);
    assertEquals(revision.getTarget(), bundleMetadataDto.getUuid());
    assertEquals(revision.getResult(), null);
}
项目:microservices    文件:JujacoreProgressServiceIntegrationTest.java   
@Ignore
@Test
public void fetchCodesFromRealSpreadsheet() throws Exception {
    final ProgressService service = JujacoreProgressServiceIntegrationTest
        .injector.getInstance(ProgressService.class);
    final Set<String> codes = service.codes();
    MatcherAssert.assertThat(
        codes, IsCollectionWithSize.hasSize(251)
    );
    MatcherAssert.assertThat(codes, IsNot.not(
        IsCollectionContaining.hasItem(""))
    );
}
项目:edison-microservice    文件:InMemJobRepositoryTest.java   
@Test
public void shouldFindRunningJobsWithoutUpdatedSinceSpecificDate() throws Exception {
    // given
    repository.createOrUpdate(newJobInfo("deadJob", "FOO", fixed(Instant.now().minusSeconds(10), systemDefault()), "localhost"));
    repository.createOrUpdate(newJobInfo("running", "FOO", fixed(Instant.now(), systemDefault()), "localhost"));

    // when
    final List<JobInfo> jobInfos = repository.findRunningWithoutUpdateSince(now().minus(5, ChronoUnit.SECONDS));

    // then
    assertThat(jobInfos, IsCollectionWithSize.hasSize(1));
    assertThat(jobInfos.get(0).getJobId(), is("deadJob"));
}
项目:java-jwt    文件:PayloadDeserializerTest.java   
@Test
public void shouldGetStringArrayWhenParsingTextNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    TextNode textNode = new TextNode("something");
    tree.put("key", textNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsCollectionWithSize.hasSize(1)));
    assertThat(values, is(IsCollectionContaining.hasItems("something")));
}
项目:java-jwt    文件:PayloadImplTest.java   
@Test
public void shouldGetAudience() throws Exception {
    assertThat(payload, is(notNullValue()));

    assertThat(payload.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(payload.getAudience(), is(IsCollectionContaining.hasItems("audience")));
}
项目:java-jwt    文件:JWTDecoderTest.java   
@Test
public void shouldGetArrayAudience() throws Exception {
    DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsiSG9wZSIsIlRyYXZpcyIsIlNvbG9tb24iXX0.Tm4W8WnfPjlmHSmKFakdij0on2rWPETpoM7Sh0u6-S4");
    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(3)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Hope", "Travis", "Solomon")));
}
项目:java-jwt    文件:JWTDecoderTest.java   
@Test
public void shouldGetStringAudience() throws Exception {
    DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJKYWNrIFJleWVzIn0.a4I9BBhPt1OB1GW67g2P1bEHgi6zgOjGUL4LvhE9Dgc");
    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Jack Reyes")));
}
项目:java-jwt    文件:JWTTest.java   
@Test
public void shouldGetArrayAudience() throws Exception {
    String token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsiSG9wZSIsIlRyYXZpcyIsIlNvbG9tb24iXX0.Tm4W8WnfPjlmHSmKFakdij0on2rWPETpoM7Sh0u6-S4";
    DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
            .build()
            .verify(token);

    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(3)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Hope", "Travis", "Solomon")));
}
项目:java-jwt    文件:JWTTest.java   
@Test
public void shouldGetStringAudience() throws Exception {
    String token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJKYWNrIFJleWVzIn0.a4I9BBhPt1OB1GW67g2P1bEHgi6zgOjGUL4LvhE9Dgc";
    DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
            .build()
            .verify(token);

    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Jack Reyes")));
}
项目:smog    文件:SimpleMatcherExamplesTest.java   
@Test
public void testListSizeMatching() {
    Matcher<Person> matcher =
            is(aPersonThat()
                    .hasPhoneList(IsCollectionWithSize.<Phone>hasSize(1)));

    String descriptionOfMismatch = "phoneList collection size was <2> (expected a collection with size <1>)";

    assertMismatch(bob, matcher, descriptionOfMismatch);
}
项目:Lock.Android    文件:ApplicationGsonTest.java   
@Test
public void shouldReturnApplication() throws Exception {
    final List<Connection> connections = buildApplicationFrom(json(APPLICATION));
    assertThat(connections, is(notNullValue()));
    assertThat(connections, is(notNullValue()));
    assertThat(connections, IsCollectionWithSize.hasSize(1));
    assertThat(connections.get(0), instanceOf(Connection.class));
}
项目:spring-data-solr    文件:ITestSolrRepositoryOperations.java   
/**
 * @see DATASOLR-144
 */
@Test
public void testDerivedDeleteByQueryRemovesDocumentAndReturnsListOfDeletedDocumentsCorrectly() {

    List<ProductBean> result = repo.removeByName(NAMED_PRODUCT.getName());
    Assert.assertThat(repo.exists(NAMED_PRODUCT.getId()), Is.is(false));
    Assert.assertThat(result, IsCollectionWithSize.hasSize(1));
    Assert.assertThat(result.get(0).getId(), IsEqual.equalTo(NAMED_PRODUCT.getId()));
}
项目:spring-data-solr    文件:ITestSolrRepositoryOperations.java   
/**
 * @see DATASOLR-170
 */
@Test
public void findTopNResultAppliesLimitationCorrectly() {

    List<ProductBean> result = repo.findTop2ByNameStartingWith("na");
    Assert.assertThat(result, IsCollectionWithSize.hasSize(2));
}
项目:spring-data-solr    文件:MappingSolrConverterTests.java   
@Test
public void testWriteCollectionToSolrInputDocumentColletion() {
    BeanWithDefaultTypes bean1 = new BeanWithDefaultTypes();
    bean1.stringProperty = "solr";

    BeanWithDefaultTypes bean2 = new BeanWithDefaultTypes();
    bean2.intProperty = 10;

    Collection<SolrInputDocument> result = converter.write(Arrays.asList(bean1, bean2));
    Assert.assertNotNull(result);
    Assert.assertThat(result, IsCollectionWithSize.hasSize(2));
}
项目:spring-data-keyvalue    文件:AbstractRepositoryUnitTests.java   
@Test // DATACMNS-525
public void findPage() {

    repository.saveAll(LENNISTERS);

    Page<Person> page = repository.findByAge(19, PageRequest.of(0, 1));
    assertThat(page.hasNext(), is(true));
    assertThat(page.getTotalElements(), is(2L));
    assertThat(page.getContent(), IsCollectionWithSize.hasSize(1));

    Page<Person> next = repository.findByAge(19, page.nextPageable());
    assertThat(next.hasNext(), is(false));
    assertThat(next.getTotalElements(), is(2L));
    assertThat(next.getContent(), IsCollectionWithSize.hasSize(1));
}
项目:dashboard    文件:MediaControllerDeleteTest.java   
@Test
public void successMediaWeb() throws Exception {
    final String name = "MediaName";
    final MediaType mediaType = MediaType.WEB;
    final String url = "http://perdu.com";
    final MediaMetadataDto mmDto = new MediaMetadataDto.Builder()
            .bundleTag(globalBundleMetadataDto.getUuid())
            .url(url)
            .name(name)
            .mediaType(mediaType)
            .build();
    final Media m = Media.builder().metadata(mediaDtoMapper.fromDto(mmDto)).build();
    mediaService.save(m);

    Path path = fileSystem.getPath(props.getBasePath(), MediaDao.ENTITY_NAME, m.getMetadata().getBundleTag(), m.getMetadata().getUuid() + ".yaml");

    assertTrue(Files.isRegularFile(path));

    final long previousRevision = revisionService.getLatest();

    mockMvc.perform(getAuthenticated("/media/" + m.getMetadata().getUuid()))
            .andExpect(status().isOk());

    mockMvc.perform(deleteAuthenticated("/media/" + m.getMetadata().getUuid()))
            .andExpect(status().isOk());

    mockMvc.perform(getAuthenticated("/media/" + m.getMetadata().getUuid()))
            .andExpect(status().isNotFound());

    assertFalse(Files.exists(path));

    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.DELETE);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.MEDIA);
    assertEquals(revision.getTarget(), m.getMetadata().getUuid());
    assertEquals(revision.getResult(), null);
}
项目:dashboard    文件:MediaControllerCreateTest.java   
@Test
public void successMediaWeb() throws Exception {
    final long previousRevision = revisionService.getLatest();
    final String name = "Killua Zoldik";
    final String url = "http://www.google.fr";
    final MediaType mediaType = MediaType.WEB;

    MvcResult result = mockMvc.perform(fileUploadAuthenticated("/media")
            .param("media", toJson(new MediaMetadataDto.Builder()
                    .name(name)
                    .mediaType(mediaType)
                    .bundleTag(globalBundleMetadataDto.getTag())
                    .url(url)
                    .build()))
    )
            .andExpect(status().isOk())
            .andReturn();

    MediaMetadataDto mediaMetadataDto = fromJson(result.getResponse().getContentAsString(), MediaMetadataDto.class);

    assertEquals(name, mediaMetadataDto.getName());
    Assert.assertEquals(mediaType, MediaType.valueOf(mediaMetadataDto.getMediaType()));
    assertNull(mediaMetadataDto.getValidity());
    assertEquals(url, mediaMetadataDto.getUrl());
    assertEquals(0, mediaMetadataDto.getDuration());
    assertNotNull(mediaMetadataDto.getUuid());

    Path path = fileSystem.getPath(props.getBasePath(), MediaDao.ENTITY_NAME, mediaMetadataDto.getBundleTag(), mediaMetadataDto.getUuid() + ".yaml");
    assertTrue(Files.isRegularFile(path));

    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.ADD);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.MEDIA);
    assertEquals(revision.getTarget(), mediaMetadataDto.getUuid());
    assertEquals(revision.getResult(), null);
}
项目:dashboard    文件:MediaControllerCreateTest.java   
@Test
public void successMediaWebComplete() throws Exception {
    final long previousRevision = revisionService.getLatest();
    final String name = "Killua Zoldik";
    final MediaType mediaType = MediaType.WEB;
    final LocalDateTime startDateTime = LocalDateTime.now().minusMonths(3).minusDays(10);
    final LocalDateTime endDateTime = LocalDateTime.now().plusDays(10);
    final String url = "http://www.google.fr";

    MvcResult result = mockMvc.perform(fileUploadAuthenticated("/media")
            .param("media", toJson(new MediaMetadataDto.Builder()
                    .name(name)
                    .validity(makeValidityDto(startDateTime, endDateTime))
                    .mediaType(mediaType)
                    .url(url)
                    .bundleTag(globalBundleMetadataDto.getTag())
                    .build()))
    )
            .andExpect(status().isOk())
            .andReturn();

    MediaMetadataDto mediaMetadataDto = fromJson(result.getResponse().getContentAsString(), MediaMetadataDto.class);

    assertEquals(name, mediaMetadataDto.getName());
    assertNotNull(mediaMetadataDto.getValidity());
    assertEquals(url, mediaMetadataDto.getUrl());
    assertEquals(0, mediaMetadataDto.getDuration());
    assertNotNull(mediaMetadataDto.getUuid());
    assertEquals(startDateTime, toLocalDateTime(mediaMetadataDto.getValidity().getStart()));
    assertEquals(endDateTime, toLocalDateTime(mediaMetadataDto.getValidity().getEnd()));

    Path path = fileSystem.getPath(props.getBasePath(), MediaDao.ENTITY_NAME, mediaMetadataDto.getBundleTag(), mediaMetadataDto.getUuid() + ".yaml");
    assertTrue(Files.isRegularFile(path));

    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.ADD);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.MEDIA);
    assertEquals(revision.getTarget(), mediaMetadataDto.getUuid());
    assertEquals(revision.getResult(), null);
}
项目:dashboard    文件:MediaControllerCreateTest.java   
@Test
public void successMediaWebDespiteTryingFixUuid() throws Exception {
    final long previousRevision = revisionService.getLatest();
    final String name = "Zelda";
    final String chosenUuid = UUID.randomUUID().toString();
    final MediaType mediaType = MediaType.WEB;
    final String url = "http://www.google.fr";

    MvcResult result = mockMvc.perform(fileUploadAuthenticated("/media")
            .param("media", toJson(new MediaMetadataDto.Builder()
                    .uuid(chosenUuid)
                    .name(name)
                    .mediaType(mediaType)
                    .url(url)
                    .bundleTag(globalBundleMetadataDto.getTag())
                    .build()))
    )
            .andExpect(status().isOk())
            .andReturn();

    MediaMetadataDto mediaMetadataDto = fromJson(result.getResponse().getContentAsString(), MediaMetadataDto.class);

    assertNotEquals(chosenUuid, mediaMetadataDto.getUuid());
    assertEquals(name, mediaMetadataDto.getName());
    assertNull(mediaMetadataDto.getValidity());
    assertEquals(url, mediaMetadataDto.getUrl());
    assertEquals(0, mediaMetadataDto.getDuration());
    assertNotNull(mediaMetadataDto.getUuid());

    Path path = fileSystem.getPath(props.getBasePath(), MediaDao.ENTITY_NAME, mediaMetadataDto.getBundleTag(), mediaMetadataDto.getUuid() + ".yaml");
    assertTrue(Files.isRegularFile(path));

    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.ADD);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.MEDIA);
    assertEquals(revision.getTarget(), mediaMetadataDto.getUuid());
    assertEquals(revision.getResult(), null);
}
项目:dashboard    文件:MediaControllerCreateTest.java   
@Test
public void successMediaImage() throws Exception {
    final long previousRevision = revisionService.getLatest();
    final long size = mediaService.getAll().size();
    final String name = "Zelda";
    final String chosenUuid = UUID.randomUUID().toString();
    final MediaType mediaType = MediaType.IMAGE;
    final MockMultipartFile jsonFile = new MockMultipartFile("file", "texte.jpeg", "image/jpeg", "{json:null}".getBytes());

    MvcResult result = mockMvc.perform(fileUploadAuthenticated("/media")
            .file(jsonFile)
            .param("media", toJson(new MediaMetadataDto.Builder()
                    .uuid(chosenUuid)
                    .name(name)
                    .mediaType(mediaType)
                    .bundleTag(globalBundleMetadataDto.getTag())
                    .build()))
    )
            .andExpect(status().isOk())
            .andReturn();

    // Vérification de l'objet Retour
    MediaMetadataDto mediaMetadataDto = fromJson(result.getResponse().getContentAsString(), MediaMetadataDto.class);

    assertNotEquals(chosenUuid, mediaMetadataDto.getUuid());
    assertEquals(name, mediaMetadataDto.getName());
    assertNull(mediaMetadataDto.getValidity());
    assertNotNull(mediaMetadataDto.getUrl());
    assertEquals(0, mediaMetadataDto.getDuration());
    assertNotNull(mediaMetadataDto.getUuid());

    // Vérification de la persistence
    Path path = fileSystem.getPath(props.getBasePath(), MediaDao.ENTITY_NAME, mediaMetadataDto.getBundleTag(), mediaMetadataDto.getUuid() + ".yaml");
    assertTrue(Files.isRegularFile(path));

    assertEquals(size + 1, mediaService.getAll().size());

    // Vérification de la peristence de l'écriture
    path = fileSystem.getPath(props.getBaseResources(), mediaMetadataDto.getUrl().substring(mediaMetadataDto.getUrl().lastIndexOf("/") + 1));
    assertTrue(Files.isRegularFile(path));

    // Vérification de la persistence de l'historique
    assertEquals(previousRevision + 1, revisionService.getLatest());

    List<Revision> revisions = revisionService.getDiffs(previousRevision);
    assertThat(revisions, IsCollectionWithSize.hasSize(1));

    Revision revision = revisions.get(0);
    assertEquals(revision.getAction(), Revision.Action.ADD);
    assertEquals(((long) revision.getRevision()), previousRevision + 1);
    assertEquals(revision.getType(), Revision.Type.MEDIA);
    assertEquals(revision.getTarget(), mediaMetadataDto.getUuid());
    assertEquals(revision.getResult(), null);
}