r3889 - in trunk: pollen-persistence/src/main/xmi pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 pollen-rest-api/src/main/resources pollen-rest-api/src/test/java/org/chorem/pollen/rest/api pollen-services/src/main/java/org/chorem/pollen/services/service pollen-services/src/test/java/org/chorem/pollen/service
Author: tchemit Date: 2014-04-29 21:10:38 +0200 (Tue, 29 Apr 2014) New Revision: 3889 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3889 Log: pass ChoiceType to Choice, no more to Poll + add Rest Doc action + begin to add Rest API tests Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocService.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java trunk/pollen-rest-api/src/main/resources/mapping trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocService.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -0,0 +1,29 @@ +package org.chorem.pollen.rest.api.v1; + +import org.apache.commons.io.IOUtils; +import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.render.Render; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Created on 4/29/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class DocService extends WebMotionController { + + public Render showMapping() { + + InputStream mappingUrl = getClass().getResourceAsStream("/mapping"); + try { + String content = IOUtils.toString(mappingUrl); + return renderContent(content, "text/plain"); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } +} Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/DocService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -23,7 +23,6 @@ * #L% */ -import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; @@ -41,8 +40,8 @@ */ public class PollService extends WebMotionController { - public Poll getNewPoll(PollenRestApiRequestContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException { - return context.getPollService().getNewPoll(userId, choiceType); + public Poll getNewPoll(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { + return context.getPollService().getNewPoll(userId); } public Set<Poll> getPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -62,6 +62,11 @@ return context.getPollenUserService().editUser(user); } + public void deleteUser(PollenRestApiRequestContext context, + String userId) throws EntityNotFoundException, InvalidPollenUserFormException { + context.getPollenUserService().deleteUser(userId); + } + public void validateUserEmail(PollenRestApiRequestContext context, String userId, String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException { Modified: trunk/pollen-rest-api/src/main/resources/mapping =================================================================== --- trunk/pollen-rest-api/src/main/resources/mapping 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-rest-api/src/main/resources/mapping 2014-04-29 19:10:38 UTC (rev 3889) @@ -26,6 +26,9 @@ [actions] +# Doc + +GET /v1/doc DocService.showMapping # AuthService PUT /v1/login AuthService.login @@ -84,6 +87,7 @@ GET /v1/users/{userId} PollenUserService.getUser POST /v1/users PollenUserService.createUser PUT /v1/users/{userId} PollenUserService.editUser +DELETE /v1/users/{userId} PollenUserService.deleteUser PUT /v1/users/{userId}?token={} PollenUserService.validateUserEmail # VoteCountingService Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -30,6 +30,7 @@ import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.config.PollenServiceConfig; import org.hibernate.cfg.Environment; +import org.nuiton.util.DateUtil; import java.io.File; import java.util.HashMap; @@ -72,6 +73,7 @@ serviceContext.setPollenServiceConfig(getApplicationConfig()); serviceContext.setTopiaApplicationContext(getTopiaApplicationContext()); serviceContext.setLocale(locale); + serviceContext.setDate(DateUtil.createDate(1, 1, 2014)); return serviceContext; } Added: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java (rev 0) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -0,0 +1,110 @@ +package org.chorem.pollen.rest.api; + +import org.apache.http.client.fluent.Request; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; + +import static org.junit.Assert.assertNotNull; + +/** + * Created on 4/29/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +@Ignore +public class PollServiceTest extends AbstractPollenRestApiTest { + + @Test + public void getPollsNew() throws URISyntaxException, IOException { + Request request = createRequest("/v1/polls/new").Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void getPolls() throws URISyntaxException, IOException { + Request request = createRequest("/v1/polls").Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void getPollsCreated() throws URISyntaxException, IOException { + Request request = createRequest("/v1/polls/created").Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void getPollsInvited() throws URISyntaxException, IOException { + Request request = createRequest("/v1/polls/invited").Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void getPollsParticipated() throws URISyntaxException, IOException { + Request request = createRequest("/v1/polls/participated").Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void getPoll() throws URISyntaxException, IOException { + String pollId = ""; + Request request = createRequest("/v1/polls/" + pollId).Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void postPoll() throws URISyntaxException, IOException { + Request request = createRequest("/v1/polls").Post(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void putPoll() throws URISyntaxException, IOException { + String pollId = ""; + Request request = createRequest("/v1/polls/" + pollId).Put(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void deletePoll() throws URISyntaxException, IOException { + String pollId = ""; + Request request = createRequest("/v1/polls/" + pollId).Delete(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void clonePoll() throws URISyntaxException, IOException { + String pollId = ""; + Request request = createRequest("/v1/polls/" + pollId).Post(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void exportPoll() throws URISyntaxException, IOException { + String pollId = ""; + Request request = createRequest("/v1/polls/" + pollId + "/export").Get(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } + + @Test + public void closePoll() throws URISyntaxException, IOException { + String pollId = ""; + Request request = createRequest("/v1/polls/" + pollId + "/close").Post(); + String content = request.execute().returnContent().asString(); + assertNotNull(content); + } +} Property changes on: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -25,6 +25,7 @@ import org.apache.http.client.fluent.Request; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.assertTrue; @@ -35,6 +36,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ +@Ignore public class PollenUserServiceTest extends AbstractPollenRestApiTest { @@ -45,38 +47,53 @@ } @Test - public void testGetUsers() throws Exception { + public void getUsers() throws Exception { Request request = createRequest("/v1/users").Get(); String result = request.execute().returnContent().asString(); assertTrue(result.contains("email")); + } + @Test + public void getUser() throws Exception { + String userId = ""; + Request request = createRequest("/v1/users/" + userId).Get(); + String result = request.execute().returnContent().asString(); + assertTrue(result.contains("email")); } -// @Test -// public void testGetUser() throws Exception { -// -// } -// -// @Test -// public void testCreateUser() throws Exception { -// -// } -// -// @Test -// public void testEditUser() throws Exception { -// -// } -// -// @Test -// public void testValidateUserEmail() throws Exception { -// -// } -// -// @Test -// public void testChangePassword() throws Exception { -// -// } + @Test + public void postUser() throws Exception { + Request request = createRequest("/v1/users").Post(); + String result = request.execute().returnContent().asString(); + + assertTrue(result.contains("email2")); + } + + @Test + public void putUser() throws Exception { + String userId = ""; + Request request = createRequest("/v1/users/" + userId).Get(); + String result = request.execute().returnContent().asString(); + assertTrue(result.contains("email3")); + } + + @Test + public void deleteUser() throws Exception { + String userId = ""; + Request request = createRequest("/v1/users/" + userId).Delete(); + String result = request.execute().returnContent().asString(); + assertTrue(result.contains("OK!")); + } + + @Test + public void validateUserEmail() throws Exception { + String userId = ""; + String token = ""; + Request request = createRequest("/v1/users/" + userId + "?token=" + token).Put(); + String result = request.execute().returnContent().asString(); + assertTrue(result.contains("OK!")); + } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -120,8 +120,7 @@ return result; } - protected Choice saveChoice(Poll poll, - Choice choice) throws EntityNotFoundException { + protected Choice saveChoice(Poll poll, Choice choice) throws EntityNotFoundException { ChoiceTopiaDao choiceDao = getChoiceDao(); @@ -151,7 +150,7 @@ poll.addChoice(choiceToPersist); } - switch (poll.getChoiceType()) { + switch (choice.getChoiceType()) { case TEXT: choiceToPersist.setName(choice.getName()); @@ -178,21 +177,22 @@ Set<String> choiceNames = Sets.newHashSet(); + checkNotNull(errors, "choiceType", choice.getChoiceType(), "choiceType can not be null"); if (!poll.isChoiceEmpty()) { // get all used names - for (Choice member : poll.getChoice()) { + for (Choice choice1 : poll.getChoice()) { if (choiceExists && - member.getTopiaId().equals(choice.getTopiaId())) { + choice1.getTopiaId().equals(choice.getTopiaId())) { continue; } - choiceNames.add(member.getName()); + choiceNames.add(choice1.getName()); } } - switch (poll.getChoiceType()) { + switch (choice.getChoiceType()) { case TEXT: Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -30,7 +30,6 @@ import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollTopiaDao; import org.chorem.pollen.persistence.entity.PollenPrincipal; @@ -88,12 +87,10 @@ return result; } - public Poll getNewPoll(String userId, ChoiceType choiceType) throws EntityNotFoundException { + public Poll getNewPoll(String userId) throws EntityNotFoundException { Poll result = getPollDao().newInstance(); - result.setChoiceType(choiceType); - // -- default values -- // result.setVoteCountingType(getPollenServiceConfig().getDefaultVoteCountingType()); @@ -232,7 +229,7 @@ toSave.setVoteCountingType(poll.getVoteCountingType()); toSave.setVoteVisibility(poll.getVoteVisibility()); toSave.setCommentVisibility(poll.getCommentVisibility()); - toSave.setChoiceType(poll.getChoiceType()); +// toSave.setChoiceType(poll.getChoiceType()); toSave.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed()); toSave.setChoiceAddAllowed(poll.isChoiceAddAllowed()); @@ -273,7 +270,6 @@ Multimap<String, String> errors = ArrayListMultimap.create(); checkNotNull(errors, "pollType", poll.getPollType(), "pollType can not be null"); - checkNotNull(errors, "choiceType", poll.getChoiceType(), "choiceType can not be null"); checkNotNull(errors, "commentVisibility", poll.getCommentVisibility(), "commentVisibility can not be null"); checkNotNull(errors, "voteVisibility", poll.getVoteVisibility(), "voteVisibility can not be null"); checkNotNull(errors, "voteCountingType", poll.getVoteCountingType(), "voteCountingType can not be null"); @@ -299,21 +295,27 @@ String choiceField = "choice[" + (choiceIndex++) + "]"; - switch (poll.getChoiceType()) { + checkNotNull(errors, + choiceField + ".choiceType", + choice.getChoiceType(), + "choiceType can not be null"); + if (choice.getChoiceType()!=null) { + switch (choice.getChoiceType()) { - case TEXT: + case TEXT: - checkNotBlank(errors, - choiceField + ".name", - choice.getName(), - "choice name can not be empty"); + checkNotBlank(errors, + choiceField + ".name", + choice.getName(), + "choice name can not be empty"); - break; - case DATE: - throw new IllegalStateException("Not implemented"); + break; + case DATE: + throw new IllegalStateException("Not implemented"); - case IMAGE: - throw new IllegalStateException("Not implemented"); + case IMAGE: + throw new IllegalStateException("Not implemented"); + } } } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -97,6 +97,14 @@ return result; } + public void deleteUser(String userId) throws EntityNotFoundException, InvalidPollenUserFormException { + Preconditions.checkNotNull(userId); + + PollenUser user = getUser(userId); + getPollenUserDao().delete(user); + commit(); + } + public void changePassword(String userId, String oldPassword, String newPassword) throws EntityNotFoundException, UserInvalidPasswordException { Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-04-29 09:46:36 UTC (rev 3888) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-04-29 19:10:38 UTC (rev 3889) @@ -71,7 +71,7 @@ @Test public void testCreateFreePoll() throws EntityNotFoundException, InvalidPollFormException { - Poll poll = service.getNewPoll(null, ChoiceType.TEXT); + Poll poll = service.getNewPoll(null); poll.setPollType(PollType.FREE); @@ -91,6 +91,14 @@ try { service.createPoll(null, poll); } catch (InvalidPollFormException e) { + // missing choice type + assertErrorKeyFound(e, "choice[0].choiceType"); + } + + choice1.setChoiceType(ChoiceType.TEXT); + try { + service.createPoll(null, poll); + } catch (InvalidPollFormException e) { // missing choice name assertErrorKeyFound(e, "choice[0].name"); } @@ -100,6 +108,7 @@ Choice choice2 = new ChoiceImpl(); + choice2.setChoiceType(ChoiceType.TEXT); choice2.setName("A"); choice2.setDescription("Choice B"); poll.addChoice(choice2); @@ -165,18 +174,20 @@ @Test public void testCreateRestrictedPoll() throws EntityNotFoundException, InvalidPollFormException { - Poll poll = service.getNewPoll(null, ChoiceType.TEXT); + Poll poll = service.getNewPoll(null); poll.setPollType(PollType.RESTRICTED); poll.setTitle("poll1"); Choice choice1 = new ChoiceImpl(); + choice1.setChoiceType(ChoiceType.TEXT); choice1.setName("A"); choice1.setDescription("Choice A"); poll.addChoice(choice1); Choice choice2 = new ChoiceImpl(); + choice2.setChoiceType(ChoiceType.TEXT); choice2.setName("B"); choice2.setDescription("Choice B");
participants (1)
-
tchemit@users.chorem.org