@Before public void setUp() { Datastore datastore = new Morphia().createDatastore(fongoRule.getMongo(), "streamflow"); serializationDao = new MongoSerializationDao(datastore); // Preload some items into the datastore Serialization serialization1 = new Serialization(); serialization1.setId("first-serialization"); serialization1.setFramework("test"); serialization1.setTypeClass("streamflow.test.First"); Serialization serialization2 = new Serialization(); serialization2.setId("second-serialization"); serialization2.setFramework("sample"); serialization2.setTypeClass("streamflow.test.second"); Serialization serialization3 = new Serialization(); serialization3.setId("third-serialization"); serialization3.setFramework("test"); serialization3.setTypeClass("streamflow.test.third"); serializationDao.save(serialization3); serializationDao.save(serialization1); serializationDao.save(serialization2); }
@Test public void findSerializationByTypeClass() { Serialization validSerialization = serializationDao.findByTypeClass("streamflow.test.First"); assertNotNull( "The returned serialization should not be null with valid query values", validSerialization); Serialization invalidSerialization = serializationDao.findByTypeClass("streamflow.test.Invalid"); assertNull( "The returned serialization should be null with invalid query values", invalidSerialization); }
@Test public void findAllSerializationsWithFramework() { List<Serialization> serializations = serializationDao.findAllWithFramework("test"); assertEquals( "There should be 2 serializations with the given framework", 2, serializations.size()); // Check proper sorting of the elements by label assertEquals( "The first item in the serialization list should have and id of \"first-serialization\"", "first-serialization", serializations.get(0).getId()); assertEquals( "The second item in the serialization list should have and id of \"third-serializations\"", "third-serialization", serializations.get(1).getId()); }
@Test public void findAllSerializations() { List<Serialization> serializations = serializationDao.findAll(); assertEquals("There should be 3 serializations in the datastore", 3, serializations.size()); // Check proper sorting of the elements by label assertEquals( "The first item in the serialization list should have and id of \"first-serialization\"", "first-serialization", serializations.get(0).getId()); assertEquals( "The second item in the serialization list should have and id of \"second-serialization\"", "second-serialization", serializations.get(1).getId()); assertEquals( "The third item in the serialization list should have and id of \"third-serialization\"", "third-serialization", serializations.get(2).getId()); }