コード例 #1
0
  @Test
  public void testPaginatedWrapper() {
    System.out.println("::: testPaginatedWrapper :::");
    final String rootFeedUriStr = "http://localhost:20090/feed";
    FeedEntryReader<SomeDomain> reader =
        new FeedEntryReader<SomeDomain>(
            httpClient,
            Arrays.<Entry<String, String>>asList(
                new AbstractMap.SimpleEntry<String, String>(
                    Link.REL_ALTERNATE, MediaType.APPLICATION_JSON)),
            SomeDomain.class);
    try {
      int newCount = 20;
      URI uri = new URI(rootFeedUriStr + "?" + SomeDomainResource.COUNT + "=" + newCount);

      Feed feed =
          ClientUtil.readEntity(uri, httpClient, MediaType.APPLICATION_ATOM_XML, Feed.class);
      // Thread.sleep(10000);
      PaginatedEntitiesWrapper<EntityResource<SomeDomain>> domains =
          new PaginatedEntitiesWrapper<EntityResource<SomeDomain>>(feed, httpClient, reader);
      List<EntityResource<SomeDomain>> domainList =
          new ArrayList<EntityResource<SomeDomain>>(SomeDomainResource.DOMAIN_SIZE);
      for (int i = 0; i < (SomeDomainResource.DOMAIN_SIZE / newCount); ++i) {
        domainList.addAll(domains.getEntitiesForCurrentPage());
        domains = domains.next();
      }
      Assert.assertNull(domains);
      Assert.assertEquals(SomeDomainResource.DOMAIN_SIZE, domainList.size());
    } catch (Exception ex) {
      ex.printStackTrace();
      Assert.fail(ex.getMessage());
    }
  }
コード例 #2
0
 @Test
 public void testPaginatedList() {
   System.out.println("::: testPaginatedList :::");
   final String rootFeedUriStr = "http://localhost:20090/feed";
   FeedEntryReader<SomeDomain> reader =
       new FeedEntryReader<SomeDomain>(
           httpClient,
           Arrays.<Entry<String, String>>asList(
               new AbstractMap.SimpleEntry<String, String>(
                   Link.REL_ALTERNATE, MediaType.APPLICATION_JSON)),
           SomeDomain.class);
   try {
     int newCount = 20;
     URI uri = new URI(rootFeedUriStr + "?" + SomeDomainResource.COUNT + "=" + newCount);
     Feed feed =
         ClientUtil.readEntity(uri, httpClient, MediaType.APPLICATION_ATOM_XML, Feed.class);
     PaginatedEntitiesWrapper<EntityResource<SomeDomain>> domains =
         new PaginatedEntitiesWrapper<EntityResource<SomeDomain>>(feed, httpClient, reader);
     List<EntityResource<SomeDomain>> domainList =
         new PaginatedFeedEntitiesList<EntityResource<SomeDomain>>(domains);
     Assert.assertEquals(SomeDomainResource.DOMAIN_SIZE, domainList.size());
     final int midSize = SomeDomainResource.DOMAIN_SIZE / 2;
     domainList = new PaginatedFeedEntitiesList<EntityResource<SomeDomain>>(domains, midSize);
     Assert.assertEquals(
         new Double(Math.ceil(midSize / (double) newCount)).intValue() * newCount,
         domainList.size());
   } catch (Exception ex) {
     ex.printStackTrace();
     Assert.fail(ex.getMessage());
   }
 }
コード例 #3
0
 @Test
 public void testFeedReader() {
   System.out.println("::: testFeedReader :::");
   final String rootFeedUriStr = "http://localhost:20090/feed";
   WebResource resource = client.resource(rootFeedUriStr);
   Feed feed = resource.get(Feed.class);
   FeedEntryReader<SomeDomain> reader =
       new FeedEntryReader<SomeDomain>(
           httpClient,
           Arrays.<Entry<String, String>>asList(
               new AbstractMap.SimpleEntry<String, String>(
                   Link.REL_ALTERNATE, MediaType.APPLICATION_JSON)),
           SomeDomain.class);
   Collection<EntityResource<SomeDomain>> collection = reader.readEntriesFromFeed(feed);
   Assert.assertNotNull(collection);
   Assert.assertEquals(5, collection.size());
   try {
     int newCount = 20;
     URI uri = new URI(rootFeedUriStr + "?count=" + newCount);
     feed = ClientUtil.readEntity(uri, httpClient, MediaType.APPLICATION_ATOM_XML, Feed.class);
     collection = reader.readEntriesFromFeed(feed);
     Assert.assertNotNull(collection);
     Assert.assertEquals(newCount, collection.size());
   } catch (Exception ex) {
     ex.printStackTrace();
     Assert.fail(ex.getMessage());
   }
 }