From 2777fd189926dbbcdaf95e70b7cd02c2433165d3 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Thu, 21 Apr 2022 20:57:21 +0800 Subject: [PATCH 1/6] migrate groups api --- .gitignore | 2 +- .project | 11 + service/.gitignore | 1 + .../ReviewOpportunitiesFactory.java | 18 +- .../review/ReviewServiceApplication.java | 13 +- .../review/ReviewServiceConfiguration.java | 23 +- .../manager/ReviewOpportunitiesManager.java | 26 +- .../review/util/ParentGroupServiceClient.java | 101 -- .../src/main/resources/review-service.yaml | 3 - .../ReviewOpportunitiesManagerTest.java | 892 +++++++++--------- 10 files changed, 482 insertions(+), 608 deletions(-) delete mode 100644 service/src/main/java/com/appirio/service/review/util/ParentGroupServiceClient.java diff --git a/.gitignore b/.gitignore index 136f46a..1a8f35e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .classpath -.project service/dependency-reduced-pom.xml service/run-config/*/target service/target @@ -10,3 +9,4 @@ service/log *.iml /target/ .settings +.project diff --git a/.project b/.project index 78648aa..259a91a 100644 --- a/.project +++ b/.project @@ -20,4 +20,15 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + + + 1650210132504 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/service/.gitignore b/service/.gitignore index b83d222..e4984d4 100644 --- a/service/.gitignore +++ b/service/.gitignore @@ -1 +1,2 @@ /target/ +.idea \ No newline at end of file diff --git a/service/src/main/java/com/appirio/service/resourcefactory/ReviewOpportunitiesFactory.java b/service/src/main/java/com/appirio/service/resourcefactory/ReviewOpportunitiesFactory.java index 4224809..d0fd5e0 100644 --- a/service/src/main/java/com/appirio/service/resourcefactory/ReviewOpportunitiesFactory.java +++ b/service/src/main/java/com/appirio/service/resourcefactory/ReviewOpportunitiesFactory.java @@ -5,7 +5,6 @@ import com.appirio.service.review.manager.ReviewOpportunitiesManager; import com.appirio.service.review.resources.ReviewOpportunitiesResource; import com.appirio.service.review.util.GroupServiceClient; -import com.appirio.service.review.util.ParentGroupServiceClient; import com.appirio.service.supply.resources.ResourceFactory; import com.appirio.supply.DAOFactory; import com.appirio.supply.SupplyException; @@ -49,8 +48,12 @@ * *

* + *

+ * Version 1.6 (Topcoder Review Service - Migrate Groups API to V5) + *

+ * * @author TCCoder - * @version 1.5 + * @version 1.6 * */ public class ReviewOpportunitiesFactory implements ResourceFactory { @@ -60,20 +63,13 @@ public class ReviewOpportunitiesFactory implements ResourceFactory *

* + *

+ * Version 1.4 (Topcoder Review Service - Migrate Groups API to V5) + *

+ * * * @author TCDEVELOPER, TCSCODER - * @version 1.3 + * @version 1.4 */ public class ReviewServiceApplication extends BaseApplication { /** @@ -138,7 +141,6 @@ public String getName() { protected void prepare(ReviewServiceConfiguration config, Environment env) throws Exception { configDatabases(config, config.getDatabases(), env); config.getGroupServiceClientConfig().setEndpoint(getConfigValueFromEnv(ENV_VAR_PATTERN, config.getGroupServiceClientConfig().getEndpoint())); - config.getParentGroupServiceClientConfig().setEndpoint(getConfigValueFromEnv(ENV_VAR_PATTERN, config.getParentGroupServiceClientConfig().getEndpoint())); } /** @@ -156,8 +158,6 @@ protected void logServiceSpecificConfigs(ReviewServiceConfiguration config) { } logger.info("\tGroup Service Client Configuration "); logger.info("\t\tGroup Service Client Endpoint : " + config.getGroupServiceClientConfig().getEndpoint()); - logger.info("\tParent Group Service Client Configuration "); - logger.info("\t\tParent Group Service Client Endpoint : " + config.getParentGroupServiceClientConfig().getEndpoint()); logger.info("\r\n"); } @@ -179,8 +179,7 @@ protected void registerResources(ReviewServiceConfiguration config, Environment env.jersey().register(new ScorecardQuestionFactory(config, env).getResourceInstance()); GroupServiceClient groupServiceClient = new GroupServiceClient(ClientBuilder.newClient(), config.getGroupServiceClientConfig(), config.getM2mAuthConfiguration()); - ParentGroupServiceClient parentGroupServiceClient = new ParentGroupServiceClient(ClientBuilder.newClient(), config.getParentGroupServiceClientConfig(), config.getM2mAuthConfiguration()); - env.jersey().register(new ReviewOpportunitiesFactory(groupServiceClient, parentGroupServiceClient).getResourceInstance()); + env.jersey().register(new ReviewOpportunitiesFactory(groupServiceClient).getResourceInstance()); } /** diff --git a/service/src/main/java/com/appirio/service/review/ReviewServiceConfiguration.java b/service/src/main/java/com/appirio/service/review/ReviewServiceConfiguration.java index 39bed5f..9d86da6 100644 --- a/service/src/main/java/com/appirio/service/review/ReviewServiceConfiguration.java +++ b/service/src/main/java/com/appirio/service/review/ReviewServiceConfiguration.java @@ -28,8 +28,12 @@ * *

* + *

+ * Version 1.3 (Topcoder Review Service - Migrate Groups API to V5) + *

+ * * @author TCDEVELOPER, TCSCODER - * @version 1.2 + * @version 1.3 * */ public class ReviewServiceConfiguration extends BaseAppConfiguration { @@ -58,14 +62,6 @@ public class ReviewServiceConfiguration extends BaseAppConfiguration { @JsonProperty("groupServiceClient") private final BaseClientConfiguration groupServiceClientConfig = new BaseClientConfiguration(); - /** - * The parent group service client configuration - */ - @Valid - @NotNull - @JsonProperty("parentGroupServiceClient") - private final BaseClientConfiguration parentGroupServiceClientConfig = new BaseClientConfiguration(); - /** * Get the data source factory * @@ -85,15 +81,6 @@ public BaseClientConfiguration getGroupServiceClientConfig() { return this.groupServiceClientConfig; } - /** - * Return the sub group service client configuration - * - * @return the sub group service client configuration - */ - public BaseClientConfiguration getParentGroupServiceClientConfig() { - return parentGroupServiceClientConfig; - } - /** * Get m2m auth configuration * diff --git a/service/src/main/java/com/appirio/service/review/manager/ReviewOpportunitiesManager.java b/service/src/main/java/com/appirio/service/review/manager/ReviewOpportunitiesManager.java index 830cf39..a493994 100644 --- a/service/src/main/java/com/appirio/service/review/manager/ReviewOpportunitiesManager.java +++ b/service/src/main/java/com/appirio/service/review/manager/ReviewOpportunitiesManager.java @@ -9,7 +9,6 @@ import com.appirio.service.review.dao.ChallengeDAO; import com.appirio.service.review.dao.ReviewOpportunitiesDAO; import com.appirio.service.review.util.GroupServiceClient; -import com.appirio.service.review.util.ParentGroupServiceClient; import com.appirio.supply.SupplyException; import com.appirio.tech.core.api.v3.TCID; import com.appirio.tech.core.api.v3.request.FieldSelector; @@ -98,8 +97,12 @@ * - add the support for the design spec review *

* + *

+ * Version 1.8 (Topcoder Review Service - Migrate Groups API to V5) + *

+ * * @author TCCoder - * @version 1.7 + * @version 1.8 */ public class ReviewOpportunitiesManager { /** @@ -242,11 +245,6 @@ public class ReviewOpportunitiesManager { */ private final GroupServiceClient groupServiceClient; - /** - * The parent group service client - */ - private final ParentGroupServiceClient parentGroupServiceClient; - private final ChallengeDAO challengeDao; /** @@ -255,15 +253,13 @@ public class ReviewOpportunitiesManager { * @param reviewOpportunitiesDAO the reviewOpportunitiesDAO to use * @param challengeDao the challengeDao to use * @param groupServiceClient the groupServiceClient to use - * @param parentGroupServiceClient the parent groupServiceClient to use * @throws SupplyException if any error occurs */ public ReviewOpportunitiesManager(ReviewOpportunitiesDAO reviewOpportunitiesDAO, ChallengeDAO challengeDao, - GroupServiceClient groupServiceClient, ParentGroupServiceClient parentGroupServiceClient) throws SupplyException { + GroupServiceClient groupServiceClient) throws SupplyException { this.reviewOpportunitiesDAO = reviewOpportunitiesDAO; this.challengeDao = challengeDao; this.groupServiceClient = groupServiceClient; - this.parentGroupServiceClient = parentGroupServiceClient; } /** @@ -846,15 +842,7 @@ private Map> checkUserChallengeEligibility(AuthUser authUser, Li private Set getAllGroupIds(long userId) throws SupplyException { try { Set groupIds = groupServiceClient.getGroups(userId); - - // get parent groups - Set allGroupIds = new HashSet<>(groupIds); - for (Long groupId : groupIds) { - Set parentGroupIds = parentGroupServiceClient.getGroups(groupId); - allGroupIds.addAll(parentGroupIds); - } - - return allGroupIds; + return groupIds; } catch (Exception e) { throw new SupplyException(e); } diff --git a/service/src/main/java/com/appirio/service/review/util/ParentGroupServiceClient.java b/service/src/main/java/com/appirio/service/review/util/ParentGroupServiceClient.java deleted file mode 100644 index 8e66ae6..0000000 --- a/service/src/main/java/com/appirio/service/review/util/ParentGroupServiceClient.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.appirio.service.review.util; - -import com.appirio.clients.BaseClient; -import com.appirio.clients.BaseClientConfiguration; -import com.appirio.service.review.M2mAuthConfiguration; -import com.appirio.supply.SupplyException; -import com.fasterxml.jackson.databind.JsonNode; -import org.eclipse.jetty.http.HttpStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.HashSet; -import java.util.Set; - -/** - * The client to fetch the parent groups information from the REST API. - * - * Version 1.0 (Topcoder Review Service - Fix Group Checks v1.0) - * - * @author TCSCODER - * @version 1.0 - */ -public class ParentGroupServiceClient extends BaseClient { - /** - * The logger - */ - private final static Logger LOGGER = LoggerFactory.getLogger(ParentGroupServiceClient.class); - - /** - * The M2M auth configuration - */ - private final M2mAuthConfiguration m2mAuthConfiguration; - - /** - * Constructor - * - * @param client the Jersey client - * @param config the configuration - * @param m2mAuthConfiguration the M2M auth configuration - */ - public ParentGroupServiceClient(Client client, BaseClientConfiguration config, M2mAuthConfiguration m2mAuthConfiguration) { - super(client, config); - this.m2mAuthConfiguration = m2mAuthConfiguration; - } - - /** - * Get the group including the sub groups - * - * @param groupId the group id - * @return the group including its sub groups - * @throws Exception if fail to fetch the sub groups - */ - public Set getGroups(long groupId) throws Exception { - String url = String.format(this.config.getEndpoint(), groupId); - WebTarget target = this.client.target(url); - - String m2mToken = Helper.generateAuthToken(this.m2mAuthConfiguration); - - Response response = target.request(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + m2mToken).get(); - - if (response.getStatusInfo().getStatusCode() != HttpStatus.OK_200) { - LOGGER.error("Unable to get groups: {}", response); - throw new SupplyException("Unable to get groups from the API, the returned status code is: " + response.getStatusInfo().getStatusCode()); - } - - JsonNode apiResponse = response.readEntity(JsonNode.class); - JsonNode result = apiResponse.path("result"); - if (result.path("status").asInt() != HttpStatus.OK_200) { - LOGGER.error("Unable to get groups: {}", apiResponse); - - throw new SupplyException("Unable to get groups from the API, the error is: " + result.path("content").asText()); - } - - JsonNode group = result.path("content"); - return parseGroup(group); - } - - /** - * Parse the group from the JSON node - * @param groupNode the JSON node - * @return the group - */ - private Set parseGroup(JsonNode groupNode) { - Set parentGroupIds = new HashSet<>(); - long parentGroupId = groupNode.path("id").asLong(); - if (parentGroupId != 0) { - // exclude null node - parentGroupIds.add(groupNode.path("id").asLong()); - } - - if (groupNode.has("parentGroup")) { - parentGroupIds.addAll(parseGroup(groupNode.path("parentGroup"))); - } - - return parentGroupIds; - } -} diff --git a/service/src/main/resources/review-service.yaml b/service/src/main/resources/review-service.yaml index d6a4418..73ac802 100644 --- a/service/src/main/resources/review-service.yaml +++ b/service/src/main/resources/review-service.yaml @@ -64,9 +64,6 @@ databases: groupServiceClient: endpoint: "${GROUP_SERVICE_ENDPOINT}" -parentGroupServiceClient: - endpoint: "${PARENT_GROUP_SERVICE_ENDPOINT}" - m2mAuthConfig: clientId: "${M2M_AUTH_CLIENT_ID:-dummy}" clientSecret: "${M2M_AUTH_CLIENT_SECRET:-dummy}" diff --git a/service/src/test/java/com/appirio/service/test/manager/ReviewOpportunitiesManagerTest.java b/service/src/test/java/com/appirio/service/test/manager/ReviewOpportunitiesManagerTest.java index 02e80c4..0b101c3 100644 --- a/service/src/test/java/com/appirio/service/test/manager/ReviewOpportunitiesManagerTest.java +++ b/service/src/test/java/com/appirio/service/test/manager/ReviewOpportunitiesManagerTest.java @@ -4,23 +4,22 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.fail; -import com.appirio.service.review.api.Phase; -import com.appirio.service.review.api.ReviewApplication; +import com.appirio.service.review.api.Phase; +import com.appirio.service.review.api.ReviewApplication; import com.appirio.service.review.api.ReviewOpportunitiesDTO; import com.appirio.service.review.api.ReviewOpportunityItem; -import com.appirio.service.review.api.TermsOfUse; -import com.appirio.service.review.dao.ChallengeDAO; +import com.appirio.service.review.api.TermsOfUse; +import com.appirio.service.review.dao.ChallengeDAO; import com.appirio.service.review.dao.ReviewOpportunitiesDAO; import com.appirio.service.review.manager.ReviewOpportunitiesManager; import com.appirio.service.review.util.GroupServiceClient; -import com.appirio.service.review.util.ParentGroupServiceClient; import com.appirio.service.test.dao.GenericDAOTest; -import com.appirio.service.test.dao.TestHelper; +import com.appirio.service.test.dao.TestHelper; import com.appirio.supply.SupplyException; -import com.appirio.supply.dataaccess.db.IdGenerator; -import com.appirio.tech.core.api.v3.TCID; +import com.appirio.supply.dataaccess.db.IdGenerator; +import com.appirio.tech.core.api.v3.TCID; import com.appirio.tech.core.api.v3.request.LimitQuery; import com.appirio.tech.core.api.v3.request.QueryParameter; import com.appirio.tech.core.auth.AuthUser; @@ -31,8 +30,8 @@ import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; -import java.io.IOException; -import java.math.BigDecimal; +import java.io.IOException; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -47,43 +46,45 @@ /** * Test ReviewOpportunitiesManager - * - * Version 1.1 - Topcoder - Create Review Opportunity Application Endpoints v1.0 + * + * Version 1.1 - Topcoder - Create Review Opportunity Application Endpoints v1.0 * - add more tests for the review application methods * * Version 1.2 - Topcoder Review Service - Fix Group Checks - * - add parent group client when creating manager + * - add parent group client when creating manager + * + * Version 1.3 - Topcoder Review Service - Migrate Groups API to V5 * * @author TCCoder - * @version 1.2 + * @version 1.3 */ public class ReviewOpportunitiesManagerTest extends GenericDAOTest { /** - * The SUB_TRACK_MAP field holds the map for the project category names - */ - private static final Map SUB_TRACK_MAP = new HashMap(); - static { - SUB_TRACK_MAP.put("Design", "DESIGN"); - SUB_TRACK_MAP.put("Development", "DEVELOPMENT"); - SUB_TRACK_MAP.put("Testing Competition", "TESTING_COMPETITION"); - SUB_TRACK_MAP.put("Specification", "SPECIFICATION"); - SUB_TRACK_MAP.put("Architecture", "ARCHITECTURE"); - SUB_TRACK_MAP.put("Bug Hunt", "BUG_HUNT"); - SUB_TRACK_MAP.put("Test Suites", "TEST_SUITES"); - SUB_TRACK_MAP.put("Assembly Competition", "ASSEMBLY_COMPETITION"); - SUB_TRACK_MAP.put("Conceptualization", "CONCEPTUALIZATION"); - SUB_TRACK_MAP.put("UI Prototypes", "UI_PROTOTYPES"); - SUB_TRACK_MAP.put("RIA Build", "RIA_BUILD"); - SUB_TRACK_MAP.put("RIA Component", "RIA_COMPONENT"); - SUB_TRACK_MAP.put("Test Scenarios", "TEST_SCENARIOS"); - SUB_TRACK_MAP.put("Copilot Posting", "COPILOT_POSTING"); - SUB_TRACK_MAP.put("Content Creation", "CONTENT_CREATION"); - SUB_TRACK_MAP.put("Reporting", "REPORTING"); - SUB_TRACK_MAP.put("First2Finish", "FIRST_2_FINISH"); - SUB_TRACK_MAP.put("Code", "CODE"); - } - - /** + * The SUB_TRACK_MAP field holds the map for the project category names + */ + private static final Map SUB_TRACK_MAP = new HashMap(); + static { + SUB_TRACK_MAP.put("Design", "DESIGN"); + SUB_TRACK_MAP.put("Development", "DEVELOPMENT"); + SUB_TRACK_MAP.put("Testing Competition", "TESTING_COMPETITION"); + SUB_TRACK_MAP.put("Specification", "SPECIFICATION"); + SUB_TRACK_MAP.put("Architecture", "ARCHITECTURE"); + SUB_TRACK_MAP.put("Bug Hunt", "BUG_HUNT"); + SUB_TRACK_MAP.put("Test Suites", "TEST_SUITES"); + SUB_TRACK_MAP.put("Assembly Competition", "ASSEMBLY_COMPETITION"); + SUB_TRACK_MAP.put("Conceptualization", "CONCEPTUALIZATION"); + SUB_TRACK_MAP.put("UI Prototypes", "UI_PROTOTYPES"); + SUB_TRACK_MAP.put("RIA Build", "RIA_BUILD"); + SUB_TRACK_MAP.put("RIA Component", "RIA_COMPONENT"); + SUB_TRACK_MAP.put("Test Scenarios", "TEST_SCENARIOS"); + SUB_TRACK_MAP.put("Copilot Posting", "COPILOT_POSTING"); + SUB_TRACK_MAP.put("Content Creation", "CONTENT_CREATION"); + SUB_TRACK_MAP.put("Reporting", "REPORTING"); + SUB_TRACK_MAP.put("First2Finish", "FIRST_2_FINISH"); + SUB_TRACK_MAP.put("Code", "CODE"); + } + + /** * The user id for testing. */ private static final String USER_ID = "123"; @@ -92,26 +93,21 @@ public class ReviewOpportunitiesManagerTest extends GenericDAOTest { * The DAO used for testing. */ private final ReviewOpportunitiesDAO dao = PowerMockito.mock(ReviewOpportunitiesDAO.class); - - /** - * The DAO used for testing. - */ - private final ChallengeDAO challengeDao = PowerMockito.mock(ChallengeDAO.class); /** - * The group service client used for testing. + * The DAO used for testing. */ - private final GroupServiceClient groupclient = PowerMockito.mock(GroupServiceClient.class); + private final ChallengeDAO challengeDao = PowerMockito.mock(ChallengeDAO.class); /** - * The parent group service client used for testing. + * The group service client used for testing. */ - private final ParentGroupServiceClient parentGroupclient = PowerMockito.mock(ParentGroupServiceClient.class); + private final GroupServiceClient groupclient = PowerMockito.mock(GroupServiceClient.class); /** * The review opportunity data. */ - private List data = new ArrayList(); + private List data = new ArrayList(); /** * Manager being tested @@ -133,11 +129,11 @@ public void before() throws Exception { // prepare some review opportunities data ReviewOpportunitiesDTO dto1 = new ReviewOpportunitiesDTO(1L, 5, 30005520L, 0, TestHelper.toDate( "2017-12-17 22:21:00.000"), TestHelper.toDate("2017-12-19 22:21:00.000"), 2, "Code", 39, "Contest Review", - "Code1", "1.0", 9L, 4L, 0.00, 0.13, 0.05, 350.0, 0, "Java, JavaScript", "NodeJS, Other", "detailedRequirement1", "submission guidelines1"); + "Code1", "1.0", 9L, 4L, 0.00, 0.13, 0.05, 350.0, 0, "Java, JavaScript", "NodeJS, Other", "detailedRequirement1", "submission guidelines1"); ReviewOpportunitiesDTO dto2 = new ReviewOpportunitiesDTO(2L, 4, 30005521L, 0, TestHelper.toDate( "2017-12-12 22:32:02.583"), TestHelper.toDate("2017-12-13 22:32:00.0"), 1, "First2Finish", 38, "Iterative Review", "F2FRev", "1.0", 8L, 21L, 0.00, 0.02, 0.04, 800.0, 0, "ActionScript, Active Directory", - "Beanstalk, Brivo Labs", "detailedRequirement2", "submission guidelines2"); + "Beanstalk, Brivo Labs", "detailedRequirement2", "submission guidelines2"); ReviewOpportunitiesDTO dto3 = new ReviewOpportunitiesDTO(3L, 3, 30005530L, 0, TestHelper.toDate( "2017-12-14 19:40:23.546"), TestHelper.toDate("2017-12-14 21:40:00.000"), 1, "Assembly Competition", 14, "Spec Review", "Assembly1", "1.0", 1L, 18L, 50.00, 0.0, 0.0, 1400.0, 0, "JavaScript", "Facebook, Google", "detailedRequirement3", "submission guidelines3"); @@ -147,56 +143,56 @@ public void before() throws Exception { data.add(dto3); // return correct review opportunities for specific challenge - Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 39)))).thenReturn(Arrays + Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 39)))).thenReturn(Arrays .asList(dto1)); - Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 38)))).thenReturn(Arrays + Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 38)))).thenReturn(Arrays .asList(dto2)); - Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 14)))).thenReturn(Arrays + Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 14)))).thenReturn(Arrays .asList(dto3)); Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 18)))).thenReturn(Arrays .asList(designSpecDto)); // all challenge - Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 0)))).thenReturn(data); - - - // setup tests for the review applications + Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new IdMatcher("challenge_type_id", 0)))).thenReturn(data); + + + // setup tests for the review applications Mockito.when(challengeDao.getChallenge(Mockito.eq(30005530L))).thenReturn(Mockito.mock(com.appirio.service.review.api.Challenge.class)); - Mockito.when(challengeDao.getChallenge(Mockito.eq(30005521L))).thenReturn(Mockito.mock(com.appirio.service.review.api.Challenge.class)); - - IdGenerator idGenerator = Mockito.mock(IdGenerator.class); - Mockito.when(idGenerator.getNextId()).thenReturn(1L); - - Mockito.doNothing().when(dao).deleteReviewApplications(Mockito.eq(132456L), Mockito.eq(3L), Mockito.anyObject()); - Mockito.doNothing().when(dao).updateReviewApplicationStatus(Mockito.eq(1L), Mockito.eq(2L), Mockito.eq(1L), Mockito.eq(132456L), Mockito.eq(3L)); - Mockito.doNothing().when(dao).addReviewApplication(Mockito.eq(132456L), Mockito.eq(3L), Mockito.eq(1), Mockito.eq(1)); - - List pendingIds = new ArrayList(); - TCID pid = new TCID(2); - pendingIds.add(pid); - Mockito.when(dao.getReviewApplicationRoleIds(Mockito.eq(132456L), Mockito.eq(3L), Mockito.argThat(new IdMatcher("reviewApplicationStatusId", 1)))).thenReturn(pendingIds); - - List cancelIds = new ArrayList(); - TCID cid = new TCID(1); - cancelIds.add(cid); - Mockito.when(dao.getReviewApplicationRoleIds(Mockito.eq(132456L), Mockito.eq(3L), Mockito.argThat(new IdMatcher("reviewApplicationStatusId", 2)))).thenReturn(cancelIds); - - + Mockito.when(challengeDao.getChallenge(Mockito.eq(30005521L))).thenReturn(Mockito.mock(com.appirio.service.review.api.Challenge.class)); + + IdGenerator idGenerator = Mockito.mock(IdGenerator.class); + Mockito.when(idGenerator.getNextId()).thenReturn(1L); + + Mockito.doNothing().when(dao).deleteReviewApplications(Mockito.eq(132456L), Mockito.eq(3L), Mockito.anyObject()); + Mockito.doNothing().when(dao).updateReviewApplicationStatus(Mockito.eq(1L), Mockito.eq(2L), Mockito.eq(1L), Mockito.eq(132456L), Mockito.eq(3L)); + Mockito.doNothing().when(dao).addReviewApplication(Mockito.eq(132456L), Mockito.eq(3L), Mockito.eq(1), Mockito.eq(1)); + + List pendingIds = new ArrayList(); + TCID pid = new TCID(2); + pendingIds.add(pid); + Mockito.when(dao.getReviewApplicationRoleIds(Mockito.eq(132456L), Mockito.eq(3L), Mockito.argThat(new IdMatcher("reviewApplicationStatusId", 1)))).thenReturn(pendingIds); + + List cancelIds = new ArrayList(); + TCID cid = new TCID(1); + cancelIds.add(cid); + Mockito.when(dao.getReviewApplicationRoleIds(Mockito.eq(132456L), Mockito.eq(3L), Mockito.argThat(new IdMatcher("reviewApplicationStatusId", 2)))).thenReturn(cancelIds); + + Mockito.when(challengeDao.getChallenge(Mockito.eq(30005530L))).thenReturn(Mockito.mock(com.appirio.service.review.api.Challenge.class)); - Mockito.when(challengeDao.getChallenge(Mockito.eq(30005531L))).thenReturn(Mockito.mock(com.appirio.service.review.api.Challenge.class)); - Phase phase = new Phase(30005530L, 1L, "Spec Review", "Opened", TestHelper.toDate("2017-12-19 22:21:00.000"), - TestHelper.toDate("2017-12-20 22:21:00.000"), TestHelper.toDate("2017-12-19 22:21:00.000"), TestHelper.toDate("2017-12-20 22:21:00.000")); - Mockito.when(dao.getChallengePhases(Mockito.argThat(new InQueryMatcher("challengeIds", new long[]{30005530L})))).thenReturn(Arrays.asList(phase)); - - TermsOfUse termsOfUse = new TermsOfUse(30005530L, 1L, "role", "agreeabilityType", "title", "url", false); - Mockito.when(dao.getTermsOfUse(Mockito.argThat(new InQueryMatcher("challengeIds", new long[]{30005530L})))).thenReturn(Arrays.asList(termsOfUse)); - - ReviewApplication application = new ReviewApplication(3L, "handle", "role", "pending", TestHelper.toDate("2017-12-19 22:21:00.000")); - Mockito.when(dao.getReviewApplications(Mockito.argThat(new InQueryMatcher("reviewAuctionIds", new long[]{3L})))).thenReturn(Arrays.asList(application)); - - Map ct = new HashMap<>(); - ct.put("ct", new BigDecimal(1)); - Mockito.when(dao.allowToReviewChallenge(Mockito.anyLong(), Mockito.anyLong())).thenReturn(ct); - + Mockito.when(challengeDao.getChallenge(Mockito.eq(30005531L))).thenReturn(Mockito.mock(com.appirio.service.review.api.Challenge.class)); + Phase phase = new Phase(30005530L, 1L, "Spec Review", "Opened", TestHelper.toDate("2017-12-19 22:21:00.000"), + TestHelper.toDate("2017-12-20 22:21:00.000"), TestHelper.toDate("2017-12-19 22:21:00.000"), TestHelper.toDate("2017-12-20 22:21:00.000")); + Mockito.when(dao.getChallengePhases(Mockito.argThat(new InQueryMatcher("challengeIds", new long[]{30005530L})))).thenReturn(Arrays.asList(phase)); + + TermsOfUse termsOfUse = new TermsOfUse(30005530L, 1L, "role", "agreeabilityType", "title", "url", false); + Mockito.when(dao.getTermsOfUse(Mockito.argThat(new InQueryMatcher("challengeIds", new long[]{30005530L})))).thenReturn(Arrays.asList(termsOfUse)); + + ReviewApplication application = new ReviewApplication(3L, "handle", "role", "pending", TestHelper.toDate("2017-12-19 22:21:00.000")); + Mockito.when(dao.getReviewApplications(Mockito.argThat(new InQueryMatcher("reviewAuctionIds", new long[]{3L})))).thenReturn(Arrays.asList(application)); + + Map ct = new HashMap<>(); + ct.put("ct", new BigDecimal(1)); + Mockito.when(dao.allowToReviewChallenge(Mockito.anyLong(), Mockito.anyLong())).thenReturn(ct); + // prepare some group permissions List> groupPerms = new ArrayList>(); Map groupPerm1 = new HashMap(); @@ -222,19 +218,19 @@ public void before() throws Exception { groupPerms.add(groupPerm3); groupPerms.add(groupPerm4); - Mockito.when(dao.getChallengeAccessibilityAndGroups(Mockito.eq(123L), Mockito.argThat(new IdMatcher( - "challenge_type_id", 0)))).thenReturn(groupPerms); - Mockito.when(dao.getChallengeAccessibilityAndGroups(Mockito.eq(456L), Mockito.argThat(new IdMatcher( - "challenge_type_id", 0)))).thenReturn(groupPerms); - Mockito.when(dao.getChallengeAccessibilityAndGroups(Mockito.eq(0), Mockito.argThat(new IdMatcher( - "challenge_type_id", 0)))).thenReturn(Collections.emptyList()); + Mockito.when(dao.getChallengeAccessibilityAndGroups(Mockito.eq(123L), Mockito.argThat(new IdMatcher( + "challenge_type_id", 0)))).thenReturn(groupPerms); + Mockito.when(dao.getChallengeAccessibilityAndGroups(Mockito.eq(456L), Mockito.argThat(new IdMatcher( + "challenge_type_id", 0)))).thenReturn(groupPerms); + Mockito.when(dao.getChallengeAccessibilityAndGroups(Mockito.eq(0), Mockito.argThat(new IdMatcher( + "challenge_type_id", 0)))).thenReturn(Collections.emptyList()); Set groupIds = new HashSet(); groupIds.add(1000456L); Mockito.when(groupclient.getGroups(Mockito.eq(Long.parseLong(USER_ID)))).thenReturn(groupIds); // create manager - manager = new ReviewOpportunitiesManager(dao, challengeDao, groupclient, parentGroupclient); + manager = new ReviewOpportunitiesManager(dao, challengeDao, groupclient); } /** @@ -254,36 +250,36 @@ public void testGetReviewOpportunities_All() throws SupplyException { checkReviewOpportunityItem(item, data); } } - - - /** - * Test ReviewOpportunitiesManager.getReviewOpportunitiesByChallengeId - * - * It will check the phases, terms and review applications - * - * @throws SupplyException if any errror occurs - */ - @Test - public void testGetReviewOpportunitiesByChallengeId() throws SupplyException { - ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), 30005530); - - // Verify result - checkReviewOpportunityItem(item, data); - - // check phases - assertNotNull("Should not be null", item.getChallenge().get("phases")); - assertEquals("Phase type is not equal", ((List) item.getChallenge().get("phases")).get(0).getType(), "Spec Review"); - assertTrue("Phase type is not equal", ((List) item.getChallenge().get("phases")).get(0).getId() == 1L); - - // check terms - assertNotNull("Should not be null", item.getChallenge().get("terms")); - assertEquals("terms title is not equal", ((List) item.getChallenge().get("terms")).get(0).getTitle(), "title"); - - // check review application - assertNotNull("review application should not be null", item.getApplications()); - assertEquals("review application size is not equal", item.getApplications().size(), 1); - assertEquals("review application handle is not equal", item.getApplications().get(0).getHandle(), "handle"); - assertEquals("review application handle is not equal", item.getApplications().get(0).getStatus(), "pending"); + + + /** + * Test ReviewOpportunitiesManager.getReviewOpportunitiesByChallengeId + * + * It will check the phases, terms and review applications + * + * @throws SupplyException if any errror occurs + */ + @Test + public void testGetReviewOpportunitiesByChallengeId() throws SupplyException { + ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), 30005530); + + // Verify result + checkReviewOpportunityItem(item, data); + + // check phases + assertNotNull("Should not be null", item.getChallenge().get("phases")); + assertEquals("Phase type is not equal", ((List) item.getChallenge().get("phases")).get(0).getType(), "Spec Review"); + assertTrue("Phase type is not equal", ((List) item.getChallenge().get("phases")).get(0).getId() == 1L); + + // check terms + assertNotNull("Should not be null", item.getChallenge().get("terms")); + assertEquals("terms title is not equal", ((List) item.getChallenge().get("terms")).get(0).getTitle(), "title"); + + // check review application + assertNotNull("review application should not be null", item.getApplications()); + assertEquals("review application size is not equal", item.getApplications().size(), 1); + assertEquals("review application handle is not equal", item.getApplications().get(0).getHandle(), "handle"); + assertEquals("review application handle is not equal", item.getApplications().get(0).getStatus(), "pending"); } /** @@ -311,40 +307,40 @@ public void testGetReviewOpportunities_by_challengeId_for_DesignChallenge_SpecRe ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), 30005531L); assertEquals("The challenge id should be equal", item.getChallengeId(), 30005531L); - } - - /** - * Test ReviewOpportunitiesManager.getReviewOpportunitiesByChallengeId - * - * - * @throws SupplyException if any errror occurs - */ - @Test - public void testGetReviewOpportunitiesByChallengeId_challengeIdNotFound() throws SupplyException { - try { - ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), 30005599); - fail("should not be here"); - } catch (SupplyException e) { - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("The challenge id does not exist:30005599", e.getMessage()); - } - } - - /** - * Test ReviewOpportunitiesManager.getReviewOpportunitiesByChallengeId - * - * - * @throws SupplyException if any errror occurs - */ - @Test - public void testGetReviewOpportunitiesByChallengeId_challengeIdNotPositive() throws SupplyException { - try { - ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), -30005530); - fail("should not be here"); - } catch (SupplyException e) { - assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); - assertEquals("The challenge id should be positive", e.getMessage()); - } + } + + /** + * Test ReviewOpportunitiesManager.getReviewOpportunitiesByChallengeId + * + * + * @throws SupplyException if any errror occurs + */ + @Test + public void testGetReviewOpportunitiesByChallengeId_challengeIdNotFound() throws SupplyException { + try { + ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), 30005599); + fail("should not be here"); + } catch (SupplyException e) { + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("The challenge id does not exist:30005599", e.getMessage()); + } + } + + /** + * Test ReviewOpportunitiesManager.getReviewOpportunitiesByChallengeId + * + * + * @throws SupplyException if any errror occurs + */ + @Test + public void testGetReviewOpportunitiesByChallengeId_challengeIdNotPositive() throws SupplyException { + try { + ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser(USER_ID), -30005530); + fail("should not be here"); + } catch (SupplyException e) { + assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); + assertEquals("The challenge id should be positive", e.getMessage()); + } } /** @@ -357,7 +353,7 @@ public void testGetReviewOpportunitiesByChallengeId_challengeIdNotPositive() thr public void testGetReviewOpportunitiesByChallengeId_Group_Limited() throws SupplyException { ReviewOpportunityItem item = manager.getReviewOpportunitiesByChallengeId(createUser("456"), 30005521); assertNull("Should be null when not eligible", item); - } + } /** * Test ReviewOpportunitiesManager.getReviewOpportunities when retrieving all review opportunities for specific @@ -551,127 +547,127 @@ public void testGetReviewOpportunities_NoGroup_NoAuth() throws SupplyException { checkReviewOpportunityItem(item, data); } } - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_update() throws SupplyException, IOException { - manager.createReviewApplications(this.createUser("132456"), 30005530, "1"); - Mockito.verify(dao).updateReviewApplicationStatus(Mockito.eq(1L), Mockito.eq(2L), Mockito.eq(1L), Mockito.eq(132456L), Mockito.eq(3L)); - } - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_insert() throws SupplyException, IOException { - List cancelIds = new ArrayList(); - Mockito.when(dao.getReviewApplicationRoleIds(Mockito.eq(132456L), Mockito.eq(3L), Mockito.argThat(new IdMatcher("reviewApplicationStatusId", 2)))).thenReturn(cancelIds); - manager.createReviewApplications(this.createUser("132456"), 30005530, "1"); - Mockito.verify(dao).addReviewApplication(Mockito.eq(132456L), Mockito.eq(3L), Mockito.eq(1), Mockito.eq(1)); - } - - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_RoleNotAvailable() throws SupplyException, IOException { - try { - manager.createReviewApplications(this.createUser("132456"), 30005530, "2"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("The review application role ids are not available for the challenge:[2]", e.getMessage()); - } - - } - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_ChallengeIdNotFound() throws SupplyException, IOException { - try { - manager.createReviewApplications(this.createUser("132456"), 9999, "7"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("The challenge id does not exists:9999", e.getMessage()); - } - - } - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_NoReviewRoleFound() throws SupplyException, IOException { - try { - manager.createReviewApplications(this.createUser("132456"), 30005530, "3"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("The review application role ids are not available for the challenge:[3]", e.getMessage()); - } - - } - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_InvalidRoleId() throws SupplyException, IOException { - try { - manager.createReviewApplications(this.createUser("132456"), 30005530, "33"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); - assertEquals("The review application role ids are invalid:33", e.getMessage()); - } - - } - - /** - * Test createReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testCreateReviewApplications_ChallengeIdNotPositive() throws SupplyException, IOException { - try { - manager.createReviewApplications(this.createUser("132456"), -30005530, "2"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); - assertEquals("Challenge id should be positive", e.getMessage()); - } - + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_update() throws SupplyException, IOException { + manager.createReviewApplications(this.createUser("132456"), 30005530, "1"); + Mockito.verify(dao).updateReviewApplicationStatus(Mockito.eq(1L), Mockito.eq(2L), Mockito.eq(1L), Mockito.eq(132456L), Mockito.eq(3L)); + } + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_insert() throws SupplyException, IOException { + List cancelIds = new ArrayList(); + Mockito.when(dao.getReviewApplicationRoleIds(Mockito.eq(132456L), Mockito.eq(3L), Mockito.argThat(new IdMatcher("reviewApplicationStatusId", 2)))).thenReturn(cancelIds); + manager.createReviewApplications(this.createUser("132456"), 30005530, "1"); + Mockito.verify(dao).addReviewApplication(Mockito.eq(132456L), Mockito.eq(3L), Mockito.eq(1), Mockito.eq(1)); + } + + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_RoleNotAvailable() throws SupplyException, IOException { + try { + manager.createReviewApplications(this.createUser("132456"), 30005530, "2"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("The review application role ids are not available for the challenge:[2]", e.getMessage()); + } + + } + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_ChallengeIdNotFound() throws SupplyException, IOException { + try { + manager.createReviewApplications(this.createUser("132456"), 9999, "7"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("The challenge id does not exists:9999", e.getMessage()); + } + + } + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_NoReviewRoleFound() throws SupplyException, IOException { + try { + manager.createReviewApplications(this.createUser("132456"), 30005530, "3"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("The review application role ids are not available for the challenge:[3]", e.getMessage()); + } + + } + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_InvalidRoleId() throws SupplyException, IOException { + try { + manager.createReviewApplications(this.createUser("132456"), 30005530, "33"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); + assertEquals("The review application role ids are invalid:33", e.getMessage()); + } + + } + + /** + * Test createReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testCreateReviewApplications_ChallengeIdNotPositive() throws SupplyException, IOException { + try { + manager.createReviewApplications(this.createUser("132456"), -30005530, "2"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); + assertEquals("Challenge id should be positive", e.getMessage()); + } + } /** @@ -691,116 +687,116 @@ public void testCreateReviewApplications_Group_Limited() throws SupplyException, assertEquals("User is not eligible to access this challenge:30005521", e.getMessage()); } - } - - /** - * Test deleteReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testDeleteReviewApplications() throws SupplyException, IOException { - List reviewData = new ArrayList();; - reviewData.add(data.get(2)); - Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new InQueryMatcher("challengeIds", 30005530L)))).thenReturn(reviewData); - manager.deleteReviewApplications(this.createUser("132456"), 30005530, "2"); - Mockito.verify(dao).deleteReviewApplications(Mockito.eq(132456L), Mockito.eq(3L), Mockito.anyObject()); - } - - /** - * Test deleteReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testDeleteReviewApplications_PendingRoleNotFound() throws SupplyException, IOException { - try { - manager.deleteReviewApplications(this.createUser("132456"), 30005530, "1"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("There are no pending application for the role ids:[1]", e.getMessage()); - } - - } - - /** - * Test deleteReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testDeleteReviewApplications_NoPendingRole() throws SupplyException, IOException { - try { - manager.deleteReviewApplications(this.createUser("132456"), 30005530, "5"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("There are no pending application for the role ids:[5]", e.getMessage()); - } - - } - - /** - * Test deleteReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testDeleteReviewApplications_ChallengeIdNotFound() throws SupplyException, IOException { - try { - manager.deleteReviewApplications(this.createUser("132456"), 9999, "1"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); - assertEquals("The challenge id does not exists:9999", e.getMessage()); - } - - } - - /** - * Test deleteReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testDeleteReviewApplications_InvalidRoleId() throws SupplyException, IOException { - try { - manager.deleteReviewApplications(this.createUser("132456"), 999, "19"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); - assertEquals("The review application role ids are invalid:19", e.getMessage()); - } - - } - - /** - * Test deleteReviewApplications - * - * @throws SupplyException Exception for supply - * @throws IOException Exception for IO - */ - @Test - public void testDeleteReviewApplications_ChallengeIdNotPositive() throws SupplyException, IOException { - try { - manager.deleteReviewApplications(this.createUser("132456"), -30005530, "1"); - fail("Should not be here"); - } catch (SupplyException e) { - // expected - assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); - assertEquals("Challenge id should be positive", e.getMessage()); - } - + } + + /** + * Test deleteReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testDeleteReviewApplications() throws SupplyException, IOException { + List reviewData = new ArrayList();; + reviewData.add(data.get(2)); + Mockito.when(dao.getReviewOpportunities(Mockito.argThat(new InQueryMatcher("challengeIds", 30005530L)))).thenReturn(reviewData); + manager.deleteReviewApplications(this.createUser("132456"), 30005530, "2"); + Mockito.verify(dao).deleteReviewApplications(Mockito.eq(132456L), Mockito.eq(3L), Mockito.anyObject()); + } + + /** + * Test deleteReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testDeleteReviewApplications_PendingRoleNotFound() throws SupplyException, IOException { + try { + manager.deleteReviewApplications(this.createUser("132456"), 30005530, "1"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("There are no pending application for the role ids:[1]", e.getMessage()); + } + + } + + /** + * Test deleteReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testDeleteReviewApplications_NoPendingRole() throws SupplyException, IOException { + try { + manager.deleteReviewApplications(this.createUser("132456"), 30005530, "5"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("There are no pending application for the role ids:[5]", e.getMessage()); + } + + } + + /** + * Test deleteReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testDeleteReviewApplications_ChallengeIdNotFound() throws SupplyException, IOException { + try { + manager.deleteReviewApplications(this.createUser("132456"), 9999, "1"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_NOT_FOUND, e.getStatusCode()); + assertEquals("The challenge id does not exists:9999", e.getMessage()); + } + + } + + /** + * Test deleteReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testDeleteReviewApplications_InvalidRoleId() throws SupplyException, IOException { + try { + manager.deleteReviewApplications(this.createUser("132456"), 999, "19"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); + assertEquals("The review application role ids are invalid:19", e.getMessage()); + } + + } + + /** + * Test deleteReviewApplications + * + * @throws SupplyException Exception for supply + * @throws IOException Exception for IO + */ + @Test + public void testDeleteReviewApplications_ChallengeIdNotPositive() throws SupplyException, IOException { + try { + manager.deleteReviewApplications(this.createUser("132456"), -30005530, "1"); + fail("Should not be here"); + } catch (SupplyException e) { + // expected + assertEquals(HttpServletResponse.SC_BAD_REQUEST, e.getStatusCode()); + assertEquals("Challenge id should be positive", e.getMessage()); + } + } /** @@ -820,8 +816,8 @@ public void testDeleteReviewApplications_Group_Limited() throws SupplyException, assertEquals("User is not eligible to access this challenge:30005521", e.getMessage()); } - } - + } + /** * Verify that a review opportunity item from manager contains correct information. * @@ -845,7 +841,7 @@ private static void checkReviewOpportunityItem(ReviewOpportunityItem item, List< assertEquals("Incorrect challenge title", dto.getChallengeName(), challenge.get("title")); assertEquals("Incorrect challenge version", dto.getChallengeVersion(), challenge.get("version")); assertEquals("Incorrect challenge track", "DEVELOP", challenge.get("track")); - assertEquals("Incorrect challenge subTrack", SUB_TRACK_MAP.get(dto.getChallengeType()), challenge.get("subTrack")); + assertEquals("Incorrect challenge subTrack", SUB_TRACK_MAP.get(dto.getChallengeType()), challenge.get("subTrack")); String[] technologies = (String[]) challenge.get("technologies"); for (String technology : technologies) { @@ -861,58 +857,58 @@ private static void checkReviewOpportunityItem(ReviewOpportunityItem item, List< } /** - * Argument matcher for mock ReviewOpportunitiesDAO to return correct data based on provided id + * Argument matcher for mock ReviewOpportunitiesDAO to return correct data based on provided id * filter. * * @author TCCODER * @version 1.0 */ - private static class IdMatcher extends ArgumentMatcher { - private final int id; - private final String idFieldName; - - public IdMatcher(String idFieldName, int id) { - super(); - this.idFieldName = idFieldName; - this.id = id; - } - - @Override - public boolean matches(Object argument) { - QueryParameter parameter = (QueryParameter) argument; - if (parameter == null) { - return true; - } - String passedValue = (String) parameter.getFilter().get(this.idFieldName); - if (passedValue == null) { - return true; - } - - return id == Integer.parseInt(passedValue); - } - } - - /** - * Argument matcher for mock ReviewOpportunitiesDAO to return correct data based on provided in query filter. - * - * @author TCCODER - * @version 1.0 - */ - private static class InQueryMatcher extends ArgumentMatcher { - private final String fieldName; - private final StringBuilder ids = new StringBuilder(); - public InQueryMatcher(String fieldName, long... ids) { + private static class IdMatcher extends ArgumentMatcher { + private final int id; + private final String idFieldName; + + public IdMatcher(String idFieldName, int id) { + super(); + this.idFieldName = idFieldName; + this.id = id; + } + + @Override + public boolean matches(Object argument) { + QueryParameter parameter = (QueryParameter) argument; + if (parameter == null) { + return true; + } + String passedValue = (String) parameter.getFilter().get(this.idFieldName); + if (passedValue == null) { + return true; + } + + return id == Integer.parseInt(passedValue); + } + } + + /** + * Argument matcher for mock ReviewOpportunitiesDAO to return correct data based on provided in query filter. + * + * @author TCCODER + * @version 1.0 + */ + private static class InQueryMatcher extends ArgumentMatcher { + private final String fieldName; + private final StringBuilder ids = new StringBuilder(); + public InQueryMatcher(String fieldName, long... ids) { super(); - this.fieldName = fieldName; - this.ids.append("in("); - for (int i = 0; i < ids.length; ++i) { - if (i < ids.length - 1) { - this.ids.append(ids[i] + ", "); - } else { - this.ids.append(ids[i]); - } - } - this.ids.append(")"); + this.fieldName = fieldName; + this.ids.append("in("); + for (int i = 0; i < ids.length; ++i) { + if (i < ids.length - 1) { + this.ids.append(ids[i] + ", "); + } else { + this.ids.append(ids[i]); + } + } + this.ids.append(")"); } @Override @@ -921,12 +917,12 @@ public boolean matches(Object argument) { if (parameter == null) { return true; } - String passedValue = (String) parameter.getFilter().get(fieldName); + String passedValue = (String) parameter.getFilter().get(fieldName); if (passedValue == null) { return true; } - return this.ids.toString().equals(passedValue); + return this.ids.toString().equals(passedValue); } } From a46e780f821b0c0e98502c862a479facd8c86b65 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Sat, 23 Apr 2022 23:59:45 +0800 Subject: [PATCH 2/6] ci:deploying --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 79c0208..e6ace89 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,8 +94,7 @@ workflows: branches: only: - dev - - feature/jira-plat-130 - - dev-ecs + - migrate-groups-api - "build-prod": context : org-global filters: From 6c7631d4c14e6f3d00d73a55dc9af6316d0d9585 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Sun, 24 Apr 2022 00:16:25 +0800 Subject: [PATCH 3/6] restore --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e6ace89..79c0208 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,8 @@ workflows: branches: only: - dev - - migrate-groups-api + - feature/jira-plat-130 + - dev-ecs - "build-prod": context : org-global filters: From e95d7ce0a6d257aba38a3eaee054bf705d860f5b Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Sun, 24 Apr 2022 00:18:11 +0800 Subject: [PATCH 4/6] ci:redeploying --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 79c0208..e6ace89 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,8 +94,7 @@ workflows: branches: only: - dev - - feature/jira-plat-130 - - dev-ecs + - migrate-groups-api - "build-prod": context : org-global filters: From 8d5f12d1c2d24a00132400bb2eba6fd01beb986a Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Mon, 25 Apr 2022 18:10:09 +0800 Subject: [PATCH 5/6] adjust group service client --- .../service/review/util/GroupServiceClient.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/service/src/main/java/com/appirio/service/review/util/GroupServiceClient.java b/service/src/main/java/com/appirio/service/review/util/GroupServiceClient.java index 1a739dd..54dd490 100644 --- a/service/src/main/java/com/appirio/service/review/util/GroupServiceClient.java +++ b/service/src/main/java/com/appirio/service/review/util/GroupServiceClient.java @@ -76,18 +76,10 @@ public Set getGroups(long userId) throws Exception { throw new SupplyException("Unable to get groups from the API, the returned status code is: " + response.getStatusInfo().getStatusCode()); } - JsonNode apiResponse = response.readEntity(JsonNode.class); - JsonNode result = apiResponse.path("result"); - if (result.path("status").asInt() != HttpStatus.OK_200) { - LOGGER.error("Unable to get groups: {}", apiResponse); - - throw new SupplyException("Unable to get groups from the API, the error is: " + result.path("content").asText()); - } - - JsonNode groups = result.path("content"); + JsonNode result = response.readEntity(JsonNode.class); Set groupIds = new HashSet(); - for (JsonNode group : groups) { - groupIds.add(group.path("id").asLong()); + for (JsonNode group : result) { + groupIds.add(group.asLong()); } return groupIds; From 2fb053cee81d4ba50b3b81354c1d33e3f3de8ec0 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Mon, 25 Apr 2022 19:14:26 +0800 Subject: [PATCH 6/6] revert ci --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e6ace89..3b565c4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,7 @@ workflows: branches: only: - dev - - migrate-groups-api + - "build-prod": context : org-global filters: