Search in sources :

Example 11 with CombinedFeed

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

the class ReadWriteLockDataStoreTest method testSaveEntity.

@Test
public void testSaveEntity() {
    String id = "1";
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http://localhost").title("title").description("description").refreshPeriod(5L).build();
    observer.save(feed);
    replayAll();
    Serializable previousEntity = testedClass.put(id, feed);
    verifyAll();
    assertNull(previousEntity);
}
Also used : Serializable(java.io.Serializable) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Test(org.junit.Test)

Example 12 with CombinedFeed

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

the class ReadWriteLockDataStoreTest method testSaveEntityWithNullKey.

@Test(expected = NullPointerException.class)
public void testSaveEntityWithNullKey() {
    String id = null;
    CombinedFeed feed = getCombinedFeed(id);
    observer.save(feed);
    replayAll();
    // save entity
    testedClass.put(id, feed);
    verifyAll();
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Test(org.junit.Test)

Example 13 with CombinedFeed

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

the class ReadWriteLockDataStoreTest method testGetNullEntity.

@Test
public void testGetNullEntity() {
    CombinedFeed combinedFeed = testedClass.get("1", CombinedFeed.class);
    assertNull(combinedFeed);
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Test(org.junit.Test)

Example 14 with CombinedFeed

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

the class ReadWriteLockDataStoreTest method testSaveDatastore.

@Test
public void testSaveDatastore() {
    // Insert new combined Feed
    String id = "1";
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http://localhost").title("title").description("description").refreshPeriod(5L).build();
    observer.save(feed);
    replayAll();
    testedClass.put(id, feed);
    // Copy the datastore into the stream
    try {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        testedClass.save(output);
        // Deserialize the datastore
        Map<String, Serializable> entities = SerializationUtils.<Map<String, Serializable>>deserialize(output.toByteArray());
        // Check whether is the saved entity was deserialized successfully or not
        Serializable serializableEntity = entities.get(id);
        if (serializableEntity instanceof CombinedFeed) {
            CombinedFeed fetchedFeed = (CombinedFeed) serializableEntity;
            assertEquals(feed, fetchedFeed);
        } else {
            fail("Deserialized entity is not CombinedFeed Class");
        }
    } catch (IOException e) {
        fail(e.getMessage());
    }
    verifyAll();
}
Also used : Serializable(java.io.Serializable) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with CombinedFeed

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

the class ReadWriteLockDataStoreTest method testGetEntity.

@Test
public void testGetEntity() {
    String id = "1";
    CombinedFeed feed = getCombinedFeed(id);
    observer.save(feed);
    replayAll();
    // save entity
    testedClass.put(id, feed);
    CombinedFeed fetchedFeed = testedClass.get(id, CombinedFeed.class);
    verifyAll();
    assertEquals(feed, fetchedFeed);
}
Also used : 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