use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class CombinedFeedResourceTest method testDelete.
@Test
public void testDelete() {
// Saving entity
CombinedFeed feed = combinedFeed("1");
datastore.put(feed.getId(), feed);
// Deleting entity
Response deleteResp = target.path(feed.getId()).request().delete();
assertEquals(Status.NO_CONTENT.getStatusCode(), deleteResp.getStatus());
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class CombinedFeedServiceTest method testSaveWithRefreshPeriod.
@Test
public void testSaveWithRefreshPeriod() {
String id = "1";
CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http://localhost").title("title").description("description").refreshPeriod(10).build();
expect(idGenerator.getId()).andReturn(id);
expect(datastore.put(eq(id), eq(feed))).andReturn(null);
replayAll();
CombinedFeed actual = testedClass.save(feed);
verifyAll();
assertEquals(feed, actual);
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class ReadWriteLockDataStoreTest method testGetEntityWrongCast.
@Test(expected = ClassCastException.class)
public void testGetEntityWrongCast() {
String id = "1";
CombinedFeed feed = getCombinedFeed(id);
observer.save(feed);
replayAll();
// save entity
testedClass.put(id, feed);
testedClass.get(id, FeedEntry.class);
verifyAll();
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class ReadWriteLockDataStoreTest method testLoadDatastore.
@Test
public void testLoadDatastore() {
// Insert new combined Feed
String id = "1";
CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http://localhost").title("title").description("description").refreshPeriod(5L).build();
// call save mock
observer.save(feed);
// Create a datastore with one Combined Feed and serialize it
String id2 = "2";
CombinedFeed deserializedFeed = new CombinedFeed.CombinedFeedBuilder(id2, "http://localhost").title("deserialized_title").description("deserialized_description").refreshPeriod(5L).build();
HashMap<String, Serializable> datastore = new HashMap<>();
datastore.put(id2, deserializedFeed);
// call mocks after a load of the datastore
Capture<Set<String>> captureRemoveAll = EasyMock.newCapture();
Capture<Collection<Serializable>> captureSaveAll = EasyMock.newCapture();
observer.removeAll(capture(captureRemoveAll));
observer.saveAll(capture(captureSaveAll));
replayAll();
// Insert feed into the old datastore
testedClass.put(id, feed);
byte[] serializedDatastore = SerializationUtils.serialize(datastore);
// Load the serialized datastore
ByteArrayInputStream input = new ByteArrayInputStream(serializedDatastore);
try {
testedClass.load(input);
// Test that the new datastore does not contain old Combined Feed
CombinedFeed previousCombinedFeed = testedClass.get(id, CombinedFeed.class);
if (previousCombinedFeed != null) {
fail("The previous combined feed should be deleted.");
}
// Test that the new datastore contains new Combined Feed
CombinedFeed newCombinedFeed = testedClass.get(id2, CombinedFeed.class);
assertEquals(deserializedFeed, newCombinedFeed);
} catch (IOException e) {
fail(e.getMessage());
}
verifyAll();
// Verify captured values
// Check whether the registered observer was called because of removing entities
Set<String> previousKeySet = captureRemoveAll.getValue();
if (!previousKeySet.contains(id)) {
fail("The previous keys should be deleted.");
}
// Check whether the registered observer was called because of saving entities
Collection<Serializable> newlySavedEntities = captureSaveAll.getValue();
assertEquals(1, newlySavedEntities.size());
boolean exists = newlySavedEntities.stream().map(CombinedFeed.class::cast).anyMatch(entity -> Objects.equals(entity.getId(), id2));
if (!exists) {
fail("The new stored CombinedFeed was not found.");
}
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class ReadWriteLockDataStoreTest method testRemoveEntity.
@Test
public void testRemoveEntity() {
String id = "1";
CombinedFeed feed = getCombinedFeed(id);
observer.save(feed);
observer.remove(id);
replayAll();
// save entity
testedClass.put(id, feed);
Serializable removedEntity = testedClass.put(id, null);
verifyAll();
if (!(removedEntity instanceof CombinedFeed)) {
fail("The previous entity is not an instance of CombinedFeed");
}
assertEquals(feed, removedEntity);
}
Aggregations