Last active
December 18, 2015 02:19
-
-
Save spg/5709997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import javax.inject.Inject; | |
import org.jukito.JukitoModule; | |
import org.jukito.JukitoRunner; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import com.google.inject.assistedinject.FactoryModuleBuilder; | |
import com.sceneverse.shozon.server.dao.StoryDao; | |
import com.sceneverse.shozon.server.dao.StoryElementDao; | |
import com.sceneverse.shozon.server.dao.StoryRevisionDao; | |
import com.sceneverse.shozon.server.rest.StoriesResource; | |
import com.sceneverse.shozon.server.rest.StoryResource; | |
import com.sceneverse.shozon.server.rest.SubresourceFactory; | |
import com.sceneverse.shozon.server.testutil.DaoTestBase; | |
import com.sceneverse.shozon.shared.domain.Story; | |
import com.sceneverse.shozon.shared.domain.StoryElement; | |
import com.sceneverse.shozon.shared.domain.StoryRevision; | |
import com.sceneverse.shozon.shared.domain.TextStoryElement; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
@RunWith(JukitoRunner.class) | |
public class StoriesResourceTest extends DaoTestBase { | |
public static class MyModule extends JukitoModule { | |
@Override | |
protected void configureTest() { | |
install(new FactoryModuleBuilder().build(SubresourceFactory.class)); | |
} | |
} | |
@Inject | |
StoriesResource storiesResource; | |
@Inject | |
StoryElementDao storyElementDao; | |
@Inject | |
StoryRevisionDao storyRevisionDao; | |
@Inject | |
SubresourceFactory subresourceFactory; | |
@Inject | |
StoryDao storyDao; | |
@Test | |
public void sometest() { | |
//I create a story | |
Long storyId = storiesResource.createStory(); | |
//no storyements are created | |
List<StoryElement> storyElements = storyElementDao.getAll(); | |
assertTrue(storyElements.isEmpty()); | |
//no storyRevisions are created | |
List<StoryRevision> storyRevisions = storyRevisionDao.getAll(); | |
assertTrue(storyRevisions.isEmpty()); | |
//I add a storyElement to the story | |
Story story = storyDao.get(storyId); | |
TextStoryElement textStoryElement = new TextStoryElement(); | |
textStoryElement.setText("some text"); | |
List<StoryElement> storyElements1 = new ArrayList<StoryElement>(); | |
storyElements1.add(textStoryElement); | |
story.setStoryElements(storyElements1); | |
StoryResource storyResource = subresourceFactory.createStoryResource(storyId); | |
storyResource.putStory(story); | |
// I verify that 2 StoryElement has been saved in the datastore | |
List<StoryElement> storyElements2 = storyElementDao.getAll(); | |
assertEquals(2, storyElements2.size()); | |
List<StoryElement> storyElements3 = storyElementDao.getStoryElements(Story.class, storyId); | |
assertEquals(2, storyElements3.size()); | |
Long storyRevisionId = storyRevisionDao.getAll().get(0).getId(); | |
List<StoryElement> storyElements4 = storyElementDao.getStoryElements(StoryRevision.class, storyRevisionId); | |
assertEquals(0, storyElements4.size()); | |
List<Story> stories = storyDao.getAll(); | |
assertEquals(1, stories.size()); | |
List<StoryRevision> storyRevisions1 = storyRevisionDao.getAll(); | |
assertEquals(1, storyRevisions1.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment