Search in sources :

Example 21 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedResourceTest method testDeleteNotFound.

@Test
public void testDeleteNotFound() {
    // Saving entity
    CombinedFeed feed = combinedFeed("1");
    datastore.put(feed.getId(), feed);
    // Deleting entity
    Response deleteResp = target.path("wrong_id").request().delete();
    assertEquals(Status.NOT_FOUND.getStatusCode(), deleteResp.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 22 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedResourceTest method testCreate.

@Test
public void testCreate() {
    CombinedFeed feed = combinedFeed("1");
    Entity<CombinedFeed> entity = Entity.entity(feed, APPLICATION_JSON_TYPE);
    Response response = target.request(MediaType.APPLICATION_JSON).post(entity);
    assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
    assertEquals(feed, response.readEntity(CombinedFeed.class));
}
Also used : Response(javax.ws.rs.core.Response) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 23 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedServiceTest method testGetAll.

@Test
public void testGetAll() {
    ReadWriteLockDataStore datastoreMock = createMock("datastore", ReadWriteLockDataStore.class);
    testedClass = new CombinedFeedService(datastoreMock, idGenerator, DEFAULT_REFRESH_PERIOD);
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder("1", "http://localhost").title("title").description("description").build();
    List<Serializable> entities = Arrays.asList(feed, "fakeObject");
    expect(datastoreMock.getAll()).andReturn(entities);
    replay(datastoreMock);
    List<CombinedFeed> actual = testedClass.getAll();
    verify(datastoreMock);
    assertEquals(1, actual.size());
    assertEquals(feed, actual.get(0));
}
Also used : Serializable(java.io.Serializable) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) ReadWriteLockDataStore(org.glassfish.jersey.examples.feedcombiner.store.ReadWriteLockDataStore) Test(org.junit.Test)

Example 24 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedServiceTest method testSaveWithoutRefreshPeriod.

@Test
public void testSaveWithoutRefreshPeriod() {
    String id = "1";
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http://localhost").title("title").description("description").build();
    CombinedFeed expected = CombinedFeed.CombinedFeedBuilder.of(feed).refreshPeriod(Long.parseLong(DEFAULT_REFRESH_PERIOD)).build();
    expect(idGenerator.getId()).andReturn(id);
    expect(datastore.put(eq(id), eq(expected))).andReturn(null);
    replayAll();
    CombinedFeed actual = testedClass.save(feed);
    verifyAll();
    assertEquals(expected, actual);
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Test(org.junit.Test)

Example 25 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class ReadWriteLockDataStoreTest method testUpdateEntity.

@Test
public void testUpdateEntity() {
    String id = "1";
    CombinedFeed feed = getCombinedFeed(id);
    observer.save(feed);
    replayAll();
    // save entity
    testedClass.put(id, feed);
    CombinedFeed updatedFeed = CombinedFeed.CombinedFeedBuilder.of(feed).title("updated_title").description("updated_description").build();
    // update entity
    Serializable previousEntity = testedClass.put(id, updatedFeed);
    verifyAll();
    if (!(previousEntity instanceof CombinedFeed)) {
        fail("The previous entity is not an instance of CombinedFeed");
    }
    assertEquals(feed, previousEntity);
}
Also used : Serializable(java.io.Serializable) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Test(org.junit.Test)

Aggregations

CombinedFeed (org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)25 Test (org.junit.Test)19 Serializable (java.io.Serializable)7 Response (javax.ws.rs.core.Response)5 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 IOException (java.io.IOException)2 URL (java.net.URL)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 FeedEntry (org.glassfish.jersey.examples.feedcombiner.model.FeedEntry)2 ReadWriteLockDataStore (org.glassfish.jersey.examples.feedcombiner.store.ReadWriteLockDataStore)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1