Skip to content

Instantly share code, notes, and snippets.

@spg
Last active December 18, 2015 02:18
Show Gist options
  • Save spg/5709821 to your computer and use it in GitHub Desktop.
Save spg/5709821 to your computer and use it in GitHub Desktop.
ce test là passe de mon côté
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()); // ca c'est weird!
List<StoryElement> storyElements4 = storyElementDao.getStoryElements(StoryRevision.class, storyId);
assertEquals(2, storyElements4.size()); // ca aussi!
List<Story> stories = storyDao.getAll();
assertEquals(2, 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