/** Tests getting a random story */ public void testRandomStory() { sm = ServerManager.getInstance(); sm.setTestServer(); UUID id1 = UUID.fromString("f1bda3a9-4560-4530-befc-2d58db9419b7"); UUID id2 = UUID.fromString("e4558e4e-5140-4838-be40-e4d5be0b5299"); Story story = new Story(id1, "Harry Potter test", "oprah", "the emo boy", "232"); Story story2 = new Story(id2, "Ugly Duckling test", "oprah", "the emo boy", "232"); Chapter chap = new Chapter(story.getId(), "on a dark cold night"); Chapter chap2 = new Chapter(story.getId(), "he lughe"); Choice c1 = new Choice(chap.getId(), chap2.getId(), "hit me!"); chap.getChoices().add(c1); story.getChapters().add(chap); story.getChapters().add(chap2); sm.insert(story); sm.insert(story2); story = sm.getRandom(); assertNotNull(story); // Cleaning up server sm.remove(story.getId().toString()); sm.remove(story2.getId().toString()); }
public void testUpdateStory() throws InterruptedException { sm = ServerManager.getInstance(); sm.setTestServer(); UUID id1 = UUID.fromString("f1bda3a9-4560-4530-befc-2d58db9419b7"); Story story = new Story(id1, "Harry Potter test", "oprah", "the emo boy", "232"); Chapter chap = new Chapter(story.getId(), "on a dark cold night"); Chapter chap2 = new Chapter(story.getId(), "he lughe"); Choice c1 = new Choice(chap.getId(), chap2.getId(), "hit me!"); // adding choices + chapters chap.getChoices().add(c1); story.getChapters().add(chap); story.getChapters().add(chap2); sm.insert(story); Thread.sleep(5000); Story newStory = sm.getById(story.getId()); assertNotNull(newStory); newStory = new Story(story.getId(), "new title", "new author", "new des", "125"); chap = new Chapter(story.getId(), "on a dark cold night"); c1 = new Choice(chap.getId(), UUID.randomUUID(), "hit me!"); chap.getChoices().add(c1); newStory.setFirstChapterId(chap.getId()); newStory.getChapters().add(chap); sm.update(newStory); Thread.sleep(5000); newStory = sm.getById(id1); ArrayList<Chapter> chaps = newStory.getChapters(); assertEquals(chaps.size(), 1); assertTrue(newStory.getAuthor().equals("new author")); assertTrue(newStory.getTitle().equals("new title")); // cleaning up server sm.remove(story.getId().toString()); }
/** * Tests inserting stories into server, retrieving them by id, retrieving them by keywords, and * deleting them. * * @throws InterruptedException */ public void testInsertRetrieveSearchRemove() throws InterruptedException { sm = ServerManager.getInstance(); sm.setTestServer(); Story story = new Story("Harry Potter test", "oprah", "the emo boy", "232"); Story story2 = new Story("Ugly Duckling test", "oprah", "the emo boy", "232"); Chapter chap = new Chapter(story.getId(), "on a dark cold night"); Chapter chap2 = new Chapter(story.getId(), "he lughe"); Choice c1 = new Choice(chap.getId(), chap2.getId(), "hit me!"); chap.getChoices().add(c1); story.getChapters().add(chap); story.getChapters().add(chap2); sm.insert(story); sm.insert(story2); // By Id story = sm.getById(story.getId()); assertNotNull(story); Thread.sleep(2000); // By keywords ArrayList<Story> results = sm.searchByKeywords("Ugly duckling test"); assertNotSame(results.size(), 0); story = results.get(0); assertTrue(story.getTitle().equals("Ugly Duckling test")); // testing remove sm.remove(story2.getId().toString()); sm.remove(story.getId().toString()); Thread.sleep(8000); Story newStory = sm.getById(story2.getId()); assertNull(newStory); newStory = sm.getById(story.getId()); assertNull(newStory); }