This is an automated email from the git hooks/post-receive script. New commit to branch feature/1110 in repository pollen. See http://git.chorem.org/pollen.git commit 98c6494a966cd461825e32c890e34947c92ff0c3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Sep 21 07:22:03 2014 +0200 refs #1110 clean dto (remove unecessary links + add more test data) --- .../org/chorem/pollen/io/PollenDataStorage.java | 29 +- .../org/chorem/pollen/io/dto/PollenPrincipal.java | 12 - .../main/java/org/chorem/pollen/io/dto/Vote.java | 21 +- .../org/chorem/pollen/io/dto/VoteToChoice.java | 18 +- .../chorem/pollen/io/PollenDataStorageTest.java | 331 ++++++++++++++++++++- pollen-io-api/src/test/resources/store.zip | Bin 1572 -> 2956 bytes 6 files changed, 349 insertions(+), 62 deletions(-) diff --git a/pollen-io-api/src/main/java/org/chorem/pollen/io/PollenDataStorage.java b/pollen-io-api/src/main/java/org/chorem/pollen/io/PollenDataStorage.java index a0b59de..5e3067b 100644 --- a/pollen-io-api/src/main/java/org/chorem/pollen/io/PollenDataStorage.java +++ b/pollen-io-api/src/main/java/org/chorem/pollen/io/PollenDataStorage.java @@ -29,9 +29,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Type; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; import java.util.Date; import java.util.Enumeration; import java.util.LinkedHashSet; @@ -53,6 +50,8 @@ public class PollenDataStorage { /** Logger. */ private static final Log log = LogFactory.getLog(PollenDataStorage.class); + public static final String VERSION_FROM_POLLEN_1_6 = "1.6-legacy"; + private final Gson gson; public PollenDataStorage() { @@ -65,7 +64,7 @@ public class PollenDataStorage { gsonBuilder.setExclusionStrategies(new ExclusionStrategy() { - Set<String> skipFiledNames = ImmutableSet.copyOf(new String[]{"polls", "users", "resources"}); + Set<String> skipFiledNames = ImmutableSet.copyOf(new String[]{"polls", "users", "resources", "zipEntryName"}); Set<Class<?>> skipTypes = ImmutableSet.copyOf(new Class<?>[]{ZipFile.class, ZipEntry.class, File.class}); @@ -253,28 +252,6 @@ public class PollenDataStorage { } - public class ZipURLStreamHandler extends URLStreamHandler { - public ZipURLStreamHandler() { - } - - public URLConnection openConnection(final URL u) throws IOException { - - if ("zip".equals(u.getProtocol())) { - return new URLConnection(u) { - - URL url = u; - - - @Override - public void connect() throws IOException { - - } - }; - } - return null; - } - } - protected void storeMetas(PollenData data, ZipOutputStream outputStream) throws IOException { ZipEntry zipEntry = new ZipEntry("meta"); diff --git a/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/PollenPrincipal.java b/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/PollenPrincipal.java index 36aaaa5..cfcc244 100644 --- a/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/PollenPrincipal.java +++ b/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/PollenPrincipal.java @@ -1,15 +1,11 @@ package org.chorem.pollen.io.dto; -import java.lang.String; - public class PollenPrincipal { protected String name; protected String email; - protected PollenUser pollenUser; - protected PollenToken permission; public String getName() { @@ -28,14 +24,6 @@ public class PollenPrincipal { this.email = email; } - public PollenUser getPollenUser() { - return pollenUser; - } - - public void setPollenUser(PollenUser pollenUser) { - this.pollenUser = pollenUser; - } - public PollenToken getPermission() { return permission; } diff --git a/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/Vote.java b/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/Vote.java index b6516fc..0223ae8 100644 --- a/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/Vote.java +++ b/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/Vote.java @@ -1,6 +1,7 @@ package org.chorem.pollen.io.dto; -import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Set; public class Vote { @@ -8,11 +9,13 @@ public class Vote { protected boolean anonymous; - protected Collection<VoteToChoice> voteToChoices; + protected PollenPrincipal voter; - protected VoterListMember voterListMember; + protected final Set<VoteToChoice> voteToChoices; - protected PollenPrincipal voter; + public Vote() { + voteToChoices = new LinkedHashSet<>(); + } public double getWeight() { return weight; @@ -30,7 +33,7 @@ public class Vote { this.anonymous = anonymous; } - public Collection<VoteToChoice> getVoteToChoices() { + public Set<VoteToChoice> getVoteToChoices() { return voteToChoices; } @@ -38,14 +41,6 @@ public class Vote { voteToChoices.add(voteToChoice); } - public VoterListMember getVoterListMember() { - return voterListMember; - } - - public void setVoterListMember(VoterListMember voterListMember) { - this.voterListMember = voterListMember; - } - public PollenPrincipal getVoter() { return voter; } diff --git a/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/VoteToChoice.java b/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/VoteToChoice.java index 5977600..096036d 100644 --- a/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/VoteToChoice.java +++ b/pollen-io-api/src/main/java/org/chorem/pollen/io/dto/VoteToChoice.java @@ -4,9 +4,17 @@ import java.lang.Double; public class VoteToChoice { + protected int choiceNumber; + protected Double voteValue; - protected Choice choice; + public int getChoiceNumber() { + return choiceNumber; + } + + public void setChoiceNumber(int choiceNumber) { + this.choiceNumber = choiceNumber; + } public Double getVoteValue() { return voteValue; @@ -16,12 +24,4 @@ public class VoteToChoice { this.voteValue = voteValue; } - public Choice getChoice() { - return choice; - } - - public void setChoice(Choice choice) { - this.choice = choice; - } - } diff --git a/pollen-io-api/src/test/java/org/chorem/pollen/io/PollenDataStorageTest.java b/pollen-io-api/src/test/java/org/chorem/pollen/io/PollenDataStorageTest.java index a185d04..fb64eec 100644 --- a/pollen-io-api/src/test/java/org/chorem/pollen/io/PollenDataStorageTest.java +++ b/pollen-io-api/src/test/java/org/chorem/pollen/io/PollenDataStorageTest.java @@ -4,11 +4,24 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.io.dto.Choice; +import org.chorem.pollen.io.dto.ChoiceType; +import org.chorem.pollen.io.dto.Comment; +import org.chorem.pollen.io.dto.CommentVisibility; import org.chorem.pollen.io.dto.FavoriteList; import org.chorem.pollen.io.dto.FavoriteListMember; +import org.chorem.pollen.io.dto.Poll; +import org.chorem.pollen.io.dto.PollType; import org.chorem.pollen.io.dto.PollenData; +import org.chorem.pollen.io.dto.PollenPrincipal; import org.chorem.pollen.io.dto.PollenResourceFile; import org.chorem.pollen.io.dto.PollenUser; +import org.chorem.pollen.io.dto.ResultVisibility; +import org.chorem.pollen.io.dto.Vote; +import org.chorem.pollen.io.dto.VoteToChoice; +import org.chorem.pollen.io.dto.VoteVisibility; +import org.chorem.pollen.io.dto.VoterList; +import org.chorem.pollen.io.dto.VoterListMember; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -22,6 +35,9 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; +import java.util.Collection; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; public class PollenDataStorageTest { @@ -76,6 +92,20 @@ public class PollenDataStorageTest { saveResult(zipFile); + try (ZipFile zip = new ZipFile(zipFile)) { + + assertZipEntryExists(zip, "meta"); + assertZipEntryExists(zip, "users/user1"); + assertZipEntryExists(zip, "users/user2"); + assertZipEntryExists(zip, "polls/poll1"); + assertZipEntryExists(zip, "polls/poll2"); + assertZipEntryExists(zip, "resources/pollenResource1.meta"); + assertZipEntryExists(zip, "resources/pollenResource1.content"); + assertZipEntryExists(zip, "resources/pollenResource2.meta"); + assertZipEntryExists(zip, "resources/pollenResource2.content"); + + } + } @Test @@ -89,11 +119,35 @@ public class PollenDataStorageTest { PollenData actual = storage.load(zipFile); + assertEqualsByJson(storage, expected, actual); + assertCollectionEqualsByJson(storage, expected.getUsers(), actual.getUsers()); + assertCollectionEqualsByJson(storage, expected.getPolls(), actual.getPolls()); + assertCollectionEqualsByJson(storage, expected.getResources(), actual.getResources()); + + } + + protected void assertZipEntryExists(ZipFile zip, String entryName) { + + ZipEntry entry = zip.getEntry(entryName); + Assert.assertNotNull("Could not find entry: " + entryName, entry); + + } + + protected <O> void assertCollectionEqualsByJson(PollenDataStorage storage, Collection<O> expected, Collection<O> actual) { + + Assert.assertEquals(expected.size(), actual.size()); + + assertEqualsByJson(storage, expected, actual); + + } + + protected <O> void assertEqualsByJson(PollenDataStorage storage, O expected, O actual) { + String expectedJson = storage.toJson(expected); String actualJson = storage.toJson(actual); - if (log.isDebugEnabled()) { - log.debug("Loaded json: " + actualJson); + if (log.isInfoEnabled()) { + log.info("Loaded json: " + actualJson); } Assert.assertEquals(expectedJson, actualJson); @@ -220,6 +274,279 @@ public class PollenDataStorageTest { pollenData.addResource(pollenResource); } + { + Poll poll = new Poll(); + poll.setId("poll1"); + poll.setTitle("Poll1"); + poll.setDescription("Poll1 description"); + poll.setAnonymousVoteAllowed(true); + poll.setBeginChoiceDate(DateUtil.createDate(10, 9, 2015)); + poll.setEndChoiceDate(DateUtil.createDate(12, 9, 2015)); + + poll.setBeginDate(DateUtil.createDate(13, 9, 2015)); + poll.setEndDate(DateUtil.createDate(15, 9, 2015)); + + poll.setChoiceAddAllowed(true); + poll.setCommentVisibility(CommentVisibility.EVERYBODY); + poll.setContinuousResults(true); + + PollenPrincipal creator = new PollenPrincipal(); + creator.setEmail("creator1@pollen.org"); + creator.setName("TheCreator"); + poll.setCreator(creator); + + poll.setMaxChoiceNumber(2); + poll.setPollType(PollType.FREE); + poll.setResultVisibility(ResultVisibility.EVERYBODY); + poll.setVoteCountingType(1); + poll.setVoteVisibility(VoteVisibility.EVERYBODY); + + pollenData.addPoll(poll); + + { + Choice choice = new Choice(); + choice.setDescription("Choice description"); + choice.setChoiceOrder(0); + choice.setChoiceType(ChoiceType.TEXT); + choice.setChoiceValue("Choice1"); + poll.addChoice(choice); + } + { + Choice choice = new Choice(); + choice.setChoiceOrder(1); + choice.setChoiceType(ChoiceType.DATE); + choice.setChoiceValue(String.valueOf(DateUtil.createDate(10, 9, 2014).getTime())); + choice.setDescription("Choice2 description"); + poll.addChoice(choice); + } + { + Choice choice = new Choice(); + choice.setChoiceOrder(2); + choice.setChoiceType(ChoiceType.RESOURCE); + choice.setChoiceValue("resource1.txt"); + choice.setDescription("Choice3 description"); + poll.addChoice(choice); + } + + { + Comment comment = new Comment(); + comment.setPostDate(DateUtil.createDate(10, 9, 2014)); + comment.setText("Comment 1"); + PollenPrincipal author = new PollenPrincipal(); + author.setEmail("commentAuthor@pollen.org"); + author.setName("commentAuthor"); + comment.setAuthor(author); + poll.addComment(comment); + } + { + Comment comment = new Comment(); + comment.setPostDate(DateUtil.createDate(10, 9, 2014)); + comment.setText("Comment 2"); + PollenPrincipal author = new PollenPrincipal(); + author.setEmail("commentAuthor2@pollen.org"); + author.setName("commentAuthor2"); + comment.setAuthor(author); + poll.addComment(comment); + } + + { + Vote vote = new Vote(); + vote.setWeight(1f); + vote.setAnonymous(false); + PollenPrincipal voter = new PollenPrincipal(); + voter.setName("voter1"); + voter.setEmail("voter1@pollen.org"); + vote.setVoter(voter); + + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(0); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(1); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + poll.addVote(vote); + } + { + Vote vote = new Vote(); + vote.setWeight(1f); + vote.setAnonymous(false); + PollenPrincipal voter = new PollenPrincipal(); + voter.setName("voter2"); + voter.setEmail("voter2@pollen.org"); + vote.setVoter(voter); + + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(1); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(2); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + poll.addVote(vote); + } + + } + { + Poll poll = new Poll(); + poll.setId("poll2"); + poll.setTitle("Poll2"); + poll.setDescription("Poll2 description"); + poll.setAnonymousVoteAllowed(false); + poll.setBeginChoiceDate(DateUtil.createDate(10, 9, 2015)); + poll.setEndChoiceDate(DateUtil.createDate(12, 9, 2015)); + + poll.setBeginDate(DateUtil.createDate(13, 9, 2015)); + poll.setEndDate(DateUtil.createDate(15, 9, 2015)); + + poll.setChoiceAddAllowed(false); + poll.setCommentVisibility(CommentVisibility.NOBODY); + poll.setContinuousResults(false); + + PollenPrincipal creator = new PollenPrincipal(); + creator.setEmail("creator1@pollen.org"); + creator.setName("TheCreator"); + poll.setCreator(creator); + + poll.setMaxChoiceNumber(1); + poll.setPollType(PollType.RESTRICTED); + poll.setResultVisibility(ResultVisibility.CREATOR); + poll.setVoteCountingType(2); + poll.setVoteVisibility(VoteVisibility.CREATOR); + + pollenData.addPoll(poll); + + { + Choice choice = new Choice(); + choice.setDescription("Choice description"); + choice.setChoiceOrder(0); + choice.setChoiceType(ChoiceType.TEXT); + choice.setChoiceValue("Choice1"); + poll.addChoice(choice); + } + { + Choice choice = new Choice(); + choice.setChoiceOrder(1); + choice.setChoiceType(ChoiceType.DATE); + choice.setChoiceValue(String.valueOf(DateUtil.createDate(10, 9, 2014).getTime())); + choice.setDescription("Choice2 description"); + poll.addChoice(choice); + } + { + Choice choice = new Choice(); + choice.setChoiceOrder(2); + choice.setChoiceType(ChoiceType.RESOURCE); + choice.setChoiceValue("resource2.properties"); + choice.setDescription("Choice3 description"); + poll.addChoice(choice); + } + + { + Comment comment = new Comment(); + comment.setPostDate(DateUtil.createDate(10, 9, 2014)); + comment.setText("Comment 1"); + PollenPrincipal author = new PollenPrincipal(); + author.setEmail("commentAuthor@pollen.org"); + author.setName("commentAuthor"); + comment.setAuthor(author); + poll.addComment(comment); + } + { + Comment comment = new Comment(); + comment.setPostDate(DateUtil.createDate(10, 9, 2014)); + comment.setText("Comment 2"); + PollenPrincipal author = new PollenPrincipal(); + author.setEmail("commentAuthor2@pollen.org"); + author.setName("commentAuthor2"); + comment.setAuthor(author); + poll.addComment(comment); + } + + { + VoterList voterList = new VoterList(); + voterList.setName("Restricted"); + voterList.setWeight(1f); + poll.addVoterList(voterList); + + { + VoterListMember member = new VoterListMember(); + PollenPrincipal principal = new PollenPrincipal(); + principal.setName("voter1"); + principal.setEmail("voter1@pollen.org"); + member.setMember(principal); + member.setWeight(1f); + voterList.addMember(member); + } + { + VoterListMember member = new VoterListMember(); + PollenPrincipal principal = new PollenPrincipal(); + principal.setName("voter2"); + principal.setEmail("voter2@pollen.org"); + member.setMember(principal); + member.setWeight(1f); + voterList.addMember(member); + } + } + + { + Vote vote = new Vote(); + vote.setWeight(1f); + vote.setAnonymous(false); + PollenPrincipal voter = new PollenPrincipal(); + voter.setName("voter1"); + voter.setEmail("voter1@pollen.org"); + vote.setVoter(voter); + + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(0); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(1); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + poll.addVote(vote); + } + { + Vote vote = new Vote(); + vote.setWeight(1f); + vote.setAnonymous(false); + PollenPrincipal voter = new PollenPrincipal(); + voter.setName("voter2"); + voter.setEmail("voter2@pollen.org"); + vote.setVoter(voter); + + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(1); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + { + VoteToChoice voteToChoice = new VoteToChoice(); + voteToChoice.setChoiceNumber(2); + voteToChoice.setVoteValue(1d); + vote.addVoteToChoice(voteToChoice); + } + poll.addVote(vote); + } + + } + return pollenData; } diff --git a/pollen-io-api/src/test/resources/store.zip b/pollen-io-api/src/test/resources/store.zip index 8c6d121..5feecbf 100644 Binary files a/pollen-io-api/src/test/resources/store.zip and b/pollen-io-api/src/test/resources/store.zip differ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.