diff --git a/api.tests/.gitignore b/api.tests/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/api.tests/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/api.tests/pom.xml b/api.tests/pom.xml
new file mode 100644
index 0000000..c64243d
--- /dev/null
+++ b/api.tests/pom.xml
@@ -0,0 +1,179 @@
+
+ 4.0.0
+ com.appirio.api.review.tests
+ automation.api.review.tests
+ 0.0.1-SNAPSHOT
+ jar
+
+ automation.api.review.tests
+ http://maven.apache.org
+
+ UTF-8
+
+
+
+
+ com.appirio.automation.api
+
+ automation-api
+ 0.0.1
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.4.1
+
+
+ commons-configuration
+ commons-configuration
+ 1.9
+
+
+ org.json
+ json
+ 20140107
+
+
+
+
+ org.testng
+ testng
+ 6.8.21
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.2.3
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.7.4.201502262128
+
+ ${basedir}/target/jacoco.exec
+
+
+
+
+ jacoco-initialize
+
+ prepare-agent
+
+
+
+ jacoco-site
+ test
+
+ report
+
+
+
+
+
+
+ org.testng.xslt
+ testng-xslt-plugin
+ 1.1
+
+ true
+ true
+ FAIL,PASS,SKIP,CONF
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.7
+
+
+ true
+
+ UTF-8
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.7
+ 1.7
+
+
+
+
+ com.google.code.maven-replacer-plugin
+ replacer
+ 1.5.3
+
+
+ generate-test-sources
+
+ replace
+
+
+
+
+
+ ${basedir}/target/**/*.properties
+
+ ${basedir}/token.properties
+
+
+
+
+
+ maven-surefire-plugin
+ 2.18.1
+
+
+ src/test/resources/testng.xml
+
+
+
+
+
+
+
+
+
+ org.eclipse.m2e
+ lifecycle-mapping
+ 1.0.0
+
+
+
+
+
+ org.jacoco
+
+ jacoco-maven-plugin
+
+
+ [0.7.4.201502262128,)
+
+
+ prepare-agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/api.tests/src/main/java/com/appirio/api/review/config/ReviewConfiguration.java b/api.tests/src/main/java/com/appirio/api/review/config/ReviewConfiguration.java
new file mode 100644
index 0000000..a3e3b20
--- /dev/null
+++ b/api.tests/src/main/java/com/appirio/api/review/config/ReviewConfiguration.java
@@ -0,0 +1,47 @@
+package com.appirio.api.review.config;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+
+import com.appirio.automation.api.config.Configuration;
+
+
+
+public class ReviewConfiguration extends Configuration{
+ private static final String REVIEW_RETRIEVEREVIEWITEMS = "retrieveReviewItems";
+ private static final String REVIEW_ASSIGNNEXTREVIEW = "assignNextReview";
+ private static final String REVIEW_CREATEREVIEWITEMS = "createReviewItems";
+ private static final String REVIEW_UPDATEREVIEWITEMS = "updateReviewItems";
+ private static final String PROPS_REVIEW = "review.properties";
+
+ private static PropertiesConfiguration reviewPropertyConfig = null;
+
+ private static ReviewConfiguration reviewConfiguration = null;
+
+ private ReviewConfiguration() {
+ }
+
+ public static ReviewConfiguration initialize() {
+ if(reviewConfiguration == null) {
+ reviewConfiguration = new ReviewConfiguration();
+ reviewPropertyConfig = reviewConfiguration.loadConfiguration(PROPS_REVIEW);
+ }
+ return reviewConfiguration;
+ }
+
+ public static String getRetrieveReviewItemsEndPoint() {
+ return getValue(reviewPropertyConfig, REVIEW_RETRIEVEREVIEWITEMS);
+ }
+
+ public static String getAssignNextReviewEndPoint() {
+ return getValue(reviewPropertyConfig, REVIEW_ASSIGNNEXTREVIEW);
+ }
+
+ public static String getCreateReviewItemsEndPoint() {
+ return getValue(reviewPropertyConfig, REVIEW_CREATEREVIEWITEMS);
+ }
+
+ public static String getUpdateReviewItemsEndPoint() {
+ return getValue(reviewPropertyConfig, REVIEW_UPDATEREVIEWITEMS);
+ }
+
+}
diff --git a/api.tests/src/main/java/com/appirio/api/review/model/User.java b/api.tests/src/main/java/com/appirio/api/review/model/User.java
new file mode 100644
index 0000000..18d9ad0
--- /dev/null
+++ b/api.tests/src/main/java/com/appirio/api/review/model/User.java
@@ -0,0 +1,57 @@
+package com.appirio.api.review.model;
+
+public class User {
+
+ private String userId ;
+ private String username;
+ private String password;
+
+ public User(String userId, String userName, String pass) {
+ this.userId = userId;
+ this.username = userName;
+ this.password = pass;
+ }
+
+ /**
+ * @return the userId
+ */
+ public String getUserId() {
+ return userId;
+ }
+
+ /**
+ * @param userId the userId to set
+ */
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ /**
+ * @return the username
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * @param username the username to set
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ /**
+ * @return the password
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * @param password the password to set
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+}
diff --git a/api.tests/src/main/java/com/appirio/api/review/util/ReviewUtil.java b/api.tests/src/main/java/com/appirio/api/review/util/ReviewUtil.java
new file mode 100644
index 0000000..33e9025
--- /dev/null
+++ b/api.tests/src/main/java/com/appirio/api/review/util/ReviewUtil.java
@@ -0,0 +1,221 @@
+package com.appirio.api.review.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.http.NameValuePair;
+import org.apache.http.message.BasicNameValuePair;
+import org.testng.Assert;
+
+import com.appirio.api.review.config.ReviewConfiguration;
+import com.appirio.api.review.model.User;
+import com.appirio.automation.api.DefaultRequestProcessor;
+import com.appirio.automation.api.DefaultResponse;
+import com.appirio.automation.api.config.EnvironmentConfiguration;
+import com.appirio.automation.api.exception.AutomationException;
+import com.appirio.automation.api.service.AuthenticationService;
+import com.appirio.automation.api.util.ApiUtil;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class ReviewUtil {
+
+ /**
+ * Reads the contents of the json file containing the test data
+ * @param fileName
+ * name of json file.
+ * @return jsonContents
+ * json string containing the test data
+ */
+ public String getFile(String fileName) {
+ String jsonContents = "";
+ ClassLoader classLoader = getClass().getClassLoader();
+ try {
+ jsonContents = IOUtils.toString(classLoader.getResourceAsStream(fileName));
+ } catch (IOException e) {
+ throw new AutomationException("Some error occurred while reading review.json "
+ + e.getLocalizedMessage());
+ }
+ return jsonContents;
+ }
+
+
+ /**
+ * Generate jwt token(v2) of specific user
+ * @param username
+ * @param password
+ * @return headers
+ */
+ public List getHeaderV2(String username,String password)
+ {
+ AuthenticationService authService;
+ authService = new AuthenticationService();
+ //Get v2 token
+ String jwtToken=authService.getAuth0JWTToken(username,password);
+ List headers = new ArrayList();
+ headers.add(new BasicNameValuePair("Content-Type", "application/json"));
+ headers.add(new BasicNameValuePair("Authorization", "Bearer "+ jwtToken));
+ return headers;
+ }
+
+ /**
+ * Generate jwt token(v3) of specific user
+ * @param username
+ * @param password
+ * @return headers
+ */
+ public List getHeader(String username,String password){
+ //Generate jwt token
+ AuthenticationService authService = new AuthenticationService();
+ String jwtToken=authService.getV3JWTToken(username,password);
+ List headers = new ArrayList();
+ headers.add(new BasicNameValuePair("Content-Type", "application/json"));
+ headers.add(new BasicNameValuePair("Authorization", "Bearer "+ jwtToken));
+ return headers;
+ }
+
+ /**
+ * Generate jwt token(v3) of default user(admin)
+ * @return headers
+ */
+ public List getHeader(){
+ //Generate jwt token
+ AuthenticationService authService = new AuthenticationService();
+ String jwtToken=authService.getV3JWTToken();
+ List headers = new ArrayList();
+ headers.add(new BasicNameValuePair("Content-Type", "application/json"));
+ headers.add(new BasicNameValuePair("Authorization", "Bearer "+ jwtToken));
+ return headers;
+ }
+
+ /**
+ * Generate jwt token(v2)
+ * @return headers
+ */
+ public List getHeaderV2()
+ {
+ AuthenticationService authService;
+ authService = new AuthenticationService();
+ //Get v2 token
+ String jwtToken=authService.getAuth0JWTToken();
+ List headers = new ArrayList();
+ headers.add(new BasicNameValuePair("Content-Type", "application/json"));
+ headers.add(new BasicNameValuePair("Authorization", "Bearer "+ jwtToken));
+ return headers;
+ }
+
+ /**
+ * Verifies that the new review items are added successfully
+ * @param responseContents
+ * @param newReviewItemsCreated
+ * @return compareReviewItems
+ */
+ public boolean verifyNewReviewItemsAddedToTheReview(List responseContents,List newReviewItemsCreated){
+ Iterator elements = newReviewItemsCreated.iterator();
+ JsonNode newReviewItem;
+ boolean compareReviewItems = false;
+ while(elements.hasNext()){
+ newReviewItem = elements.next();
+ for (JsonNode reviewItemAdded : responseContents) {
+ if(reviewItemAdded.path("id").asText().equalsIgnoreCase(newReviewItem.asText()))
+ compareReviewItems = true;
+ else{
+ compareReviewItems = false;
+ }
+ }
+ }
+ return compareReviewItems;
+ }
+
+ /**
+ * Verifies the updations done in the review items. Check is performed only on the 'answer' field, as it is the only field that gets updated.
+ * @param responseContents
+ * @param newReviewItemsCreated
+ * @return compareReviewItems
+ */
+ public boolean verifyUpdatesInReviewItems(List responseContents,JsonNode newReviewItemsCreated){
+ Iterator elements = newReviewItemsCreated.elements();
+ JsonNode newReviewItem;
+ boolean compareReviewItems = false;
+ while(elements.hasNext()){
+ newReviewItem = elements.next();
+ for (JsonNode reviewItemAdded : responseContents) {
+ if(reviewItemAdded.path("scorecardQuestionId").asText().equalsIgnoreCase(newReviewItem.path("scorecardQuestionId").asText())){
+ if(reviewItemAdded.path("answer").asText().equalsIgnoreCase(newReviewItem.path("answer").asText())){
+ compareReviewItems = true;
+ break;
+ }
+ else{
+ compareReviewItems = false;
+ break;
+ }
+ }
+
+ }
+ }
+ return compareReviewItems;
+ }
+
+ /**
+ * Stores all the user details in a map
+ * @param users
+ * @return
+ */
+ public static Map getUsers(JsonNode users) {
+ Map usersMap = new HashMap();
+ JsonNode existingUserNode = null;
+ Iterator elements = users.elements();
+ while(elements.hasNext()) {
+ existingUserNode = elements.next();
+ JsonNode paramNode = existingUserNode.path("param");
+ User u = new User(paramNode.path("userId").textValue(),paramNode.path("username").textValue(),
+ paramNode.path("password").textValue());
+ usersMap.put(u.getUsername(),u);
+ }
+ return usersMap;
+ }
+
+
+ /**
+ * Adds values to the fields 'reviewId' and 'handle' in the json node used as parameter to get review items.
+ * @param getReviewItem
+ * @param reviewId
+ * @param u
+ * @return getReviewItem
+ */
+ public JsonNode addValuesToGetReviewItemTestNode(JsonNode getReviewItem ,String reviewId,User u) {
+ ((ObjectNode)getReviewItem.path("param")).put("handle",u.getUsername());
+ ((ObjectNode)getReviewItem.path("param").path("filter")).put("reviewId",reviewId);
+ return getReviewItem;
+
+ }
+
+ /**
+ * This methods executes the api to get review items as per the parameters specified.
+ * @param reviewObject - json object containing filter parameters.
+ * @param u
+ * @return response
+ */
+ public DefaultResponse getReviewItems(JsonNode reviewObject, User u){
+ String retrieveReviewItemsUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getRetrieveReviewItemsEndPoint();
+ List urlParameters=new ArrayList();
+ List headers = null;
+ if(u!=null)
+ //headers = getHeaderV2(u.getUsername(),u.getPassword());
+ headers =getHeader(u.getUsername(),u.getPassword());
+ else
+ //headers = getHeaderV2();
+ headers =getHeader();
+ if(reviewObject.path("param").has("filter"))
+ urlParameters=ApiUtil.constructParameters(reviewObject.path("param"));
+ DefaultResponse response = DefaultRequestProcessor.getRequest(retrieveReviewItemsUrl, urlParameters, headers);
+ return response;
+ }
+
+}
diff --git a/api.tests/src/main/resources/environment.properties b/api.tests/src/main/resources/environment.properties
new file mode 100644
index 0000000..54f34fd
--- /dev/null
+++ b/api.tests/src/main/resources/environment.properties
@@ -0,0 +1,9 @@
+auth0URL=https://@application.auth.domain@.auth0.com/oauth/ro
+baseURL=http://api.@application.auth.domain@.com/v3
+baseV2Url=http://api.@application.auth.domain@.com/v2
+client_id=@client_id@
+username=@username@
+password=@password@
+connection=@connection@
+grant_type=@grant_type@
+scope=@scope@
\ No newline at end of file
diff --git a/api.tests/src/main/resources/log4j.xml b/api.tests/src/main/resources/log4j.xml
new file mode 100644
index 0000000..c52cf95
--- /dev/null
+++ b/api.tests/src/main/resources/log4j.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/api.tests/src/main/resources/review.properties b/api.tests/src/main/resources/review.properties
new file mode 100644
index 0000000..e559560
--- /dev/null
+++ b/api.tests/src/main/resources/review.properties
@@ -0,0 +1,4 @@
+assignNextReview=/reviews/@challengeId/assignNextReview
+retrieveReviewItems=/reviewItems/
+createReviewItems=/reviewItems/
+updateReviewItems=/reviewItems/
\ No newline at end of file
diff --git a/api.tests/src/test/java/com/appirio/api/review/tests/ReviewTest.java b/api.tests/src/test/java/com/appirio/api/review/tests/ReviewTest.java
new file mode 100644
index 0000000..97b6862
--- /dev/null
+++ b/api.tests/src/test/java/com/appirio/api/review/tests/ReviewTest.java
@@ -0,0 +1,415 @@
+package com.appirio.api.review.tests;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.NameValuePair;
+import org.apache.log4j.Logger;
+import org.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.appirio.api.review.model.User;
+import com.appirio.api.review.util.ReviewUtil;
+import com.appirio.api.review.config.ReviewConfiguration;
+import com.appirio.automation.api.DefaultRequestProcessor;
+import com.appirio.automation.api.DefaultResponse;
+import com.appirio.automation.api.config.AuthenticationConfiguration;
+import com.appirio.automation.api.config.EnvironmentConfiguration;
+import com.appirio.automation.api.exception.DefaultRequestProcessorException;
+import com.appirio.automation.api.model.AuthenticationInfo;
+import com.appirio.automation.api.util.ApiUtil;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+
+/**
+ * Test class containing tests for review microservice api endpoints.
+ * Author : Munmun Mathur
+ * Created Date : 2015/10/08
+ * Updated Date : 2015/10/14
+ */
+public class ReviewTest {
+ final static Logger logger = Logger.getLogger(ReviewTest.class);
+
+ JSONObject jsonObjMain = null;
+ JsonNode rootNode = null;
+ JsonNode usersJson = null;
+ AuthenticationInfo authInfo;
+ Map usersMap = null;
+ ReviewUtil util = new ReviewUtil();
+
+ /**
+ * Initialise the configurations
+ * @throws Exception
+ */
+ @BeforeClass
+ public void setUp() throws Exception {
+ logger.info("ReviewTest:setUp:Entering set up phase to initialise the configurations.");
+ EnvironmentConfiguration.initialize();
+ AuthenticationConfiguration.initialize();
+ ReviewConfiguration.initialize();
+ String jsonFile = util.getFile("review.json");
+ rootNode = ApiUtil.readJsonFromFile(jsonFile);
+ usersJson = rootNode.get("userCredentials");
+ usersMap = ReviewUtil.getUsers(usersJson);
+ }
+
+ /**
+ * This tests the api to get review items as per the parameters specified. It uses review id as the filter parameter.
+ * The logged in user owns the review specified in the filter parameter.
+ */
+ @Test(priority = 1, testName = "Get review items", description = "Gets the review items")
+ public void testRetrieveReviewItems() {
+ logger.info("ReviewTest:testRetrieveReviewItems:Testing 'Get review items' api endpoint.");
+ JsonNode reviewNode = rootNode.get("getReviewItems");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ JsonNode reviewItemsList = null;
+ int noOfReviewItems=0;
+ String userHandle;
+ int reviewTotalCount=0;
+ User u = null;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ response = util.getReviewItems(reviewObject, u);
+ Assert.assertEquals(response.getCode(), 200);
+ reviewItemsList = response.getResponseData();
+ Assert.assertEquals(reviewItemsList.path("result").path("content").isArray(), true);
+ noOfReviewItems = reviewItemsList.path("result").path("content").size();
+ reviewTotalCount =Integer.parseInt(reviewItemsList.path("result").path("metadata").get("totalCount").asText());
+ Assert.assertNotNull(noOfReviewItems);
+ Assert.assertEquals(noOfReviewItems>=0,true);
+ Assert.assertEquals(reviewTotalCount>=0,true);
+ if(reviewObject.path("param").has("filter"))
+ Assert.assertTrue(noOfReviewItems>0);
+ else
+ Assert.assertTrue(noOfReviewItems==0);
+ if(noOfReviewItems>0){
+ ((ObjectNode)reviewObject.path("param")).put("createdBy", u.getUserId());
+ ((ObjectNode)reviewObject.path("param")).put("updatedBy", u.getUserId());
+ boolean result = ApiUtil.assertQueryResponse(response,reviewObject.get("param").path("filter"));
+ Assert.assertTrue(result);
+ result = ApiUtil.assertQueryResponse(response,reviewObject.get("param"));
+ Assert.assertTrue(result);
+ }
+ }
+ }
+
+ /**
+ * This tests the api with scenarios when no user is logged in, and when the logged in user does not owns
+ * the review specified in the filter parameter.
+ */
+ @Test(priority = 2, testName = "Get review items using other user's credentials", description = "Gets the review items")
+ public void testRetrieveReviewItemsOtherUser() {
+ logger.info("ReviewTest:testRetrieveReviewItemsOtherUser:Testing 'Get review items' api endpoint.");
+ JsonNode reviewNode = rootNode.get("getReviewItemsOtherUser");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ JsonNode reviewItemsList = null;
+ int noOfReviewItems=0;
+ String userHandle;
+ int reviewTotalCount=0;
+ User u = null;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ if(reviewObject.path("param").has("handle")){
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ response = util.getReviewItems(reviewObject, u);
+ }
+ else
+ response = util.getReviewItems(reviewObject, null);
+ Assert.assertEquals(response.getCode(), 200);
+ reviewItemsList = response.getResponseData();
+ Assert.assertEquals(reviewItemsList.path("result").path("content").isArray(), true);
+ noOfReviewItems = reviewItemsList.path("result").path("content").size();
+ reviewTotalCount =Integer.parseInt(reviewItemsList.path("result").path("metadata").get("totalCount").asText());
+ Assert.assertNotNull(noOfReviewItems);
+ Assert.assertTrue(noOfReviewItems==0);
+ Assert.assertEquals(reviewTotalCount>=0,true);
+ }
+ }
+
+ /**
+ * This tests the api to create new review items for the logged in user. Here, the new review itens are created using post call, and then
+ * a get call is done to check if the newly created review items appear in the list of review items for the review
+ */
+ @Test(priority = 3, testName = "Create review items", description = "Creates new review items")
+ public void testCreateReviewItems() {
+ logger.info("ReviewTest:testCreateReviewItems:Testing 'Create review items' api endpoint.");
+ List headers = null;
+ String newReviewItems;
+ JsonNode reviewNode = rootNode.get("createReviewItems");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ JsonNode reviewItemsList = null;
+ int noOfReviewItemsCreated=0;
+ String createReviewItemsUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getCreateReviewItemsEndPoint();
+ String userHandle;
+ int newReviewItemsCount;
+ int totalReviewItemsForAReviewBefore;
+ int totalReviewItemsForAReviewAfter;
+ User u = null;
+ JsonNode getReviewItem = null;
+ String reviewId;
+ List newReviewItemsCreated = null;
+ int responseContentSize = 0;
+ int offset = 0;
+
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ getReviewItem=rootNode.get("getReviewItemsTestData");
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ headers = util.getHeader(userHandle,u.getPassword());
+ reviewId=reviewObject.path("param").path("reviewItems").get(0).path("reviewId").asText();
+ getReviewItem=util.addValuesToGetReviewItemTestNode(getReviewItem, reviewId, u);
+ response = util.getReviewItems(getReviewItem, u);
+ reviewItemsList = response.getResponseData();
+ //Get the count of review items before adding new ones
+ totalReviewItemsForAReviewBefore = Integer.parseInt(reviewItemsList.path("result").path("metadata").get("totalCount").asText());
+ newReviewItemsCount=reviewObject.path("param").path("reviewItems").size();
+ newReviewItems = reviewObject.path("param").get("reviewItems").toString();
+
+ //POST request to add new review items
+ response = DefaultRequestProcessor.postRequest(createReviewItemsUrl, null, headers,newReviewItems);
+ Assert.assertEquals(response.getCode(), 200);
+ reviewItemsList = response.getResponseData();
+ newReviewItemsCreated = response.getResponseContents();
+ Assert.assertEquals(reviewItemsList.path("result").path("content").isArray(), true);
+ noOfReviewItemsCreated = reviewItemsList.path("result").path("content").size();
+ Assert.assertEquals(noOfReviewItemsCreated, newReviewItemsCount);
+
+ //Get all the review items for the review to check that new review items are created successfully.
+ getReviewItem=rootNode.get("getReviewItemsTestData");
+ reviewId=reviewObject.path("param").path("reviewItems").get(0).path("reviewId").asText();
+ getReviewItem=util.addValuesToGetReviewItemTestNode(getReviewItem, reviewId, u);
+ ((ObjectNode)getReviewItem.path("param")).put("offset", "0");
+ ((ObjectNode)getReviewItem.path("param")).put("limit", "50");
+ response = util.getReviewItems(getReviewItem, u);
+ reviewItemsList = response.getResponseData();
+ //Get the count of review items after adding new ones
+ totalReviewItemsForAReviewAfter = Integer.parseInt(reviewItemsList.path("result").path("metadata").get("totalCount").asText());
+
+ //Assert the count of review items before and after adding new items
+ Assert.assertEquals(totalReviewItemsForAReviewAfter-totalReviewItemsForAReviewBefore, newReviewItemsCount);
+ responseContentSize=response.getResponseContents().size();
+ //Check that the newly created review items appear in the list of review items for the review
+ boolean success = util.verifyNewReviewItemsAddedToTheReview(response.getResponseContents(),newReviewItemsCreated);
+ while(!success && responseContentSize==50){
+ //Get next items list after every 50 records
+ offset=offset+responseContentSize;
+ ((ObjectNode)getReviewItem.path("param")).remove("offset");
+ ((ObjectNode)getReviewItem.path("param")).remove("limit");
+ ((ObjectNode)getReviewItem.path("param")).put("offset", offset);
+ ((ObjectNode)getReviewItem.path("param")).put("limit", "50");
+ response = util.getReviewItems(getReviewItem, u);
+ reviewItemsList = response.getResponseData();
+ responseContentSize=response.getResponseContents().size();
+ success = util.verifyNewReviewItemsAddedToTheReview(response.getResponseContents(),newReviewItemsCreated);
+ }
+ ((ObjectNode)getReviewItem.path("param")).remove("offset");
+ ((ObjectNode)getReviewItem.path("param")).remove("limit");
+ Assert.assertTrue(success);
+ }
+ }
+
+ /**
+ * This tests the api to create new review items when the logged in user is not authorised to create new review items.
+ */
+ @Test(priority = 4, testName = "Create review items", description = "Creates the review items",
+ expectedExceptions=DefaultRequestProcessorException.class)
+ public void testCreateReviewItemsUnAuthUser() {
+ logger.info("ReviewTest:testCreateReviewItemsUnAuthUser:Testing 'Create review items' api endpoint.");
+ List headers = null;
+ String newReviewItems;
+ JsonNode reviewNode = rootNode.get("createReviewItemsUnAuthUser");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ String createReviewItemsUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getCreateReviewItemsEndPoint();
+ String userHandle;
+ User u = null;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ headers = util.getHeader(userHandle,u.getPassword());
+ newReviewItems = reviewObject.path("param").get("reviewItems").toString();
+ response = DefaultRequestProcessor.postRequest(createReviewItemsUrl, null, headers,newReviewItems);
+ }
+ }
+
+ /**
+ * This tests the api to update review items for the logged in user. Only the 'answer' field is checked for updates, as it is the only field
+ * that gets updated.
+ */
+ @Test(priority = 5, testName = "Update review items", description = "Updates the review items")
+ public void testUpdateReviewItems() {
+ logger.info("ReviewTest:testUpdateReviewItems:Testing 'Update review items' api endpoint.");
+ List headers = null;
+ String updateReviewItems;
+ JsonNode reviewNode = rootNode.get("updateReviewItems");
+ JsonNode reviewObject = null;
+ JsonNode getReviewItem = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ String updateReviewItemsUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getUpdateReviewItemsEndPoint();
+ String userHandle;
+ User u = null;
+ String reviewId;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ headers = util.getHeader(userHandle,u.getPassword());
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ updateReviewItems = reviewObject.path("param").get("reviewItems").toString();
+ response = DefaultRequestProcessor.putRequest(updateReviewItemsUrl, null, headers,updateReviewItems);
+ Assert.assertEquals(response.getCode(), 200);
+
+ getReviewItem=rootNode.get("getReviewItemsTestData");
+ reviewId=reviewObject.path("param").path("reviewItems").get(0).path("reviewId").asText();
+ getReviewItem=util.addValuesToGetReviewItemTestNode(getReviewItem, reviewId, u);
+ response = util.getReviewItems(getReviewItem, u);
+ Assert.assertTrue(util.verifyUpdatesInReviewItems(response.getResponseContents(), reviewObject.path("param").path("reviewItems")));
+
+ }
+ }
+
+ /**
+ * This tests the api to update review items when the logged in user is not authorised to update review items.
+ */
+ @Test(priority = 6, testName = "Update review items by an unauthorised user", description = "Update the review items by an unauthorised user"
+ ,expectedExceptions=DefaultRequestProcessorException.class)
+ public void testUpdateReviewItemsUnAuthUser() {
+ logger.info("ReviewTest:testUpdateReviewItemsUnAuthUser:Testing 'Update review items' api endpoint by an unauthorised user.");
+ List headers = null;
+ String updateReviewItems;
+ JsonNode reviewNode = rootNode.get("updateReviewItemsUnAuthUser");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ String updateReviewItemsUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getUpdateReviewItemsEndPoint();
+ String userHandle;
+ User u = null;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ headers = util.getHeader(userHandle,u.getPassword());
+ updateReviewItems = reviewObject.path("param").get("reviewItems").toString();
+ response = DefaultRequestProcessor.putRequest(updateReviewItemsUrl, null, headers,updateReviewItems);
+
+ }
+ }
+
+ /**
+ * This tests the api to assign next review on a challenge to a user.
+ */
+
+ @Test(priority = 7, testName = "Assign next review", description = "Assign next review")
+ public void testAssignNextReview() {
+ logger.info("ReviewTest:testAssignNextReview:Testing 'Assign next review' api endpoint.");
+ List headers = null;
+ JsonNode reviewNode = rootNode.get("assignNextReview");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ String assignNextReviewUrl;
+ String userHandle;
+ User u = null;
+ int reviewId;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ assignNextReviewUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getAssignNextReviewEndPoint();
+ assignNextReviewUrl = ApiUtil.replaceToken(assignNextReviewUrl, "@challengeId", reviewObject.path("param").get("challengeId").asText());
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ headers = util.getHeader(userHandle,u.getPassword());
+ response = DefaultRequestProcessor.putRequest(assignNextReviewUrl, null, headers,null);
+ Assert.assertEquals(response.getCode(), 200);
+ JsonNode reviewItemsList = response.getResponseData();
+ reviewId=Integer.parseInt(reviewItemsList.path("result").path("content").asText());
+ Assert.assertNotNull(reviewId);
+ Assert.assertTrue(reviewId>0);
+ }
+ }
+
+ /**
+ * This tests the api to assign next review on a challenge to a user who is not authorised for this operation.
+ */
+ @Test(priority = 8, testName = "Assign next review by an unauthorised user", description = "Assign next review by an unauthorised user",
+ expectedExceptions=DefaultRequestProcessorException.class)
+ public void testAssignNextReviewUnAuthUser() {
+
+ logger.info("ReviewTest:testAssignNextReviewUnAuthUser:Testing 'Assign next review' api endpoint by an unauthorised user.");
+ List headers = null;
+ JsonNode reviewNode = rootNode.get("assignNextReviewUnAuthUser");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ String assignNextReviewUrl;
+ String userHandle;
+ User u = null;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ assignNextReviewUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getAssignNextReviewEndPoint();
+ assignNextReviewUrl = ApiUtil.replaceToken(assignNextReviewUrl, "@challengeId", reviewObject.path("param").get("challengeId").asText());
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ headers = util.getHeader(userHandle,u.getPassword());
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ response = DefaultRequestProcessor.putRequest(assignNextReviewUrl, null, headers,null);
+ }
+ }
+
+ /**
+ * This tests the api to assign next review on a challenge to a user who already has 5 open reviews.
+ */
+
+ @Test(priority = 9, testName = "Assign next review by a user who already has 5 open reviews", description = "Assign next review by a user who already has 5 open reviews",
+ expectedExceptions=DefaultRequestProcessorException.class)
+ public void testAssignNextReviewUserWithOpenReview() {
+ logger.info("ReviewTest:testAssignNextReviewUserWithOpenReview:Testing 'Assign next review' api endpoint by a user who already has 5 open reviews.");
+ List headers = null;
+ JsonNode reviewNode = rootNode.get("assignNextReviewUserWithOpenReviews");
+ JsonNode reviewObject = null;
+ Iterator elements = reviewNode.elements();
+ DefaultResponse response = null;
+ String assignNextReviewUrl;
+ String userHandle;
+ User u = null;
+ //Iterate over set of review parameters one by one
+ while(elements.hasNext()) {
+ reviewObject = elements.next();
+ assignNextReviewUrl = EnvironmentConfiguration.getBaseUrl()+ReviewConfiguration.getAssignNextReviewEndPoint();
+ assignNextReviewUrl = ApiUtil.replaceToken(assignNextReviewUrl, "@challengeId", reviewObject.path("param").get("challengeId").asText());
+ userHandle = reviewObject.path("param").path("handle").textValue();
+ u = usersMap.get(userHandle);
+ headers = util.getHeader(userHandle,u.getPassword());
+ //headers = util.getHeaderV2(userHandle,u.getPassword());
+ response = DefaultRequestProcessor.putRequest(assignNextReviewUrl, null, headers,null);
+ }
+ }
+}
diff --git a/api.tests/src/test/resources/review.json b/api.tests/src/test/resources/review.json
new file mode 100644
index 0000000..31d9348
--- /dev/null
+++ b/api.tests/src/test/resources/review.json
@@ -0,0 +1,161 @@
+{
+ "userCredentials" : [
+ {
+ "param" : {
+ "userId" : "8547899",
+ "username" : "TonyJ",
+ "password" : "appirio123"
+ }
+ },
+ {
+ "param" : {
+ "userId" : "1800119",
+ "username" : "Satine",
+ "password" : "appirio123"
+ }
+ },
+ {
+ "param" : {
+ "userId" : "1800089",
+ "username" : "thseagle",
+ "password" : "appirio123"
+ }
+ }],
+ "getReviewItemsTestData" :
+ {
+ "param" : {
+ "handle" : "",
+ "filter" : {
+ "reviewId" : ""
+ }
+ }
+ },
+ "getReviewItems" :[
+
+ {
+ "param" : {
+ "handle" : "Satine"
+ }
+ },
+ {
+ "param" : {
+ "handle" : "Satine",
+ "filter" : {
+ "reviewId" : "388902"
+ },
+ "offset" : "0",
+ "limit" : "50"
+ }
+ }
+ ],
+ "getReviewItemsOtherUser" :[
+
+ {
+ "param" : {
+ "filter" : {
+ "reviewId" : "388902"
+ }
+ }
+ },
+ {
+ "param" : {
+ "handle" : "TonyJ",
+ "filter" : {
+ "reviewId" : "388902"
+ }
+ }
+ }
+ ],
+ "assignNextReview" : [
+ {
+ "param" : {
+ "handle" : "Satine",
+ "challengeId" : "30049290"
+ }
+ }],
+ "assignNextReviewUserWithOpenReviews" : [
+ {
+ "param" : {
+ "handle" : "Satine",
+ "challengeId" : "30049301"
+ }
+ }],
+ "assignNextReviewUnAuthUser" : [
+ {
+ "param" : {
+ "handle" : "thseagle",
+ "challengeId" : "30049301"
+ }
+ }],
+ "createReviewItems" :[
+
+ {
+ "param" : {
+ "handle" : "Satine",
+ "reviewItems" :
+ [{"reviewId":388902,"scorecardQuestionId":30005883,"uploadId":506602,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]},
+ {"reviewId":388902,"scorecardQuestionId":30005884,"uploadId":506602,"answer":"2",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]},
+ {"reviewId":388902,"scorecardQuestionId":30005885,"uploadId":506602,"answer":"3",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]},
+ {"reviewId":388902,"scorecardQuestionId":30005886,"uploadId":506602,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]},
+ {"reviewId":388902,"scorecardQuestionId":30005887,"uploadId":506602,"answer":"2",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]}]
+ }
+ }
+ ],
+ "updateReviewItems" :[
+
+ {
+ "param" : {
+ "handle" : "thseagle",
+ "reviewItems" :
+ [{"reviewId":321919,"scorecardQuestionId":30005883,"uploadId":506612,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113820},
+ {"reviewId":321919,"scorecardQuestionId":30005884,"uploadId":506612,"answer":"3",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113821},
+ {"reviewId":321919,"scorecardQuestionId":30005885,"uploadId":506612,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113822},
+ {"reviewId":321919,"scorecardQuestionId":30005886,"uploadId":506612,"answer":"2",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113823},
+ {"reviewId":321919,"scorecardQuestionId":30005887,"uploadId":506612,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113824}]
+ }
+ }
+ ],
+ "updateReviewItemsUnAuthUser" :[
+
+ {
+ "param" : {
+ "handle" : "TonyJ",
+ "reviewItems" :
+ [{"reviewId":321919,"scorecardQuestionId":30005883,"uploadId":506612,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113820},
+ {"reviewId":321919,"scorecardQuestionId":30005884,"uploadId":506612,"answer":"3",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113821},
+ {"reviewId":321919,"scorecardQuestionId":30005885,"uploadId":506612,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113822},
+ {"reviewId":321919,"scorecardQuestionId":30005886,"uploadId":506612,"answer":"2",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113823},
+ {"reviewId":321919,"scorecardQuestionId":30005887,"uploadId":506612,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031061,"commentTypeId":1}],"id":8113824}]
+ }
+ }
+ ],
+ "createReviewItemsUnAuthUser" :[
+ {
+ "param" : {
+ "handle" : "TonyJ",
+ "reviewItems" :
+ [{"reviewId":388902,"scorecardQuestionId":30005883,"uploadId":506602,"answer":"1",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]},
+ {"reviewId":388902,"scorecardQuestionId":30005884,"uploadId":506602,"answer":"2",
+ "comments":[{"content":"test","resourceId":1031290,"commentTypeId":1}]}]
+ }
+
+ }
+ ]
+
+}
\ No newline at end of file
diff --git a/api.tests/src/test/resources/testng.xml b/api.tests/src/test/resources/testng.xml
new file mode 100644
index 0000000..cb47b18
--- /dev/null
+++ b/api.tests/src/test/resources/testng.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/api.tests/token.properties b/api.tests/token.properties
new file mode 100644
index 0000000..a97b46b
--- /dev/null
+++ b/api.tests/token.properties
@@ -0,0 +1,7 @@
+@application.auth.domain@=topcoder-dev
+@client_id@=JFDo7HMkf0q2CkVFHojy3zHWafziprhT
+@username@=kohatatest40
+@password@=appirio123[
+@connection@=LDAP
+@grant_type@=password
+@scope@=openid profile
\ No newline at end of file
diff --git a/service/run-config/dev/src/main/resources/supply-server.yaml b/service/run-config/dev/src/main/resources/supply-server.yaml
index 218404a..9339089 100644
--- a/service/run-config/dev/src/main/resources/supply-server.yaml
+++ b/service/run-config/dev/src/main/resources/supply-server.yaml
@@ -146,10 +146,10 @@ logging:
timeZone: UTC
logFormat: "%-5level [%d{yyyy-dd-mm HH:mm:ss.SSS}] [%thread] %logger - %msg%n"
-authScheme: v2
+authScheme: v3
# File service domain
fileServiceDomain: api.topcoder-dev.com
# Api version
-apiVersion: v3
\ No newline at end of file
+apiVersion: v3
diff --git a/service/run-config/prod/src/main/resources/supply-server.yaml b/service/run-config/prod/src/main/resources/supply-server.yaml
index 948d5cf..622cd8b 100644
--- a/service/run-config/prod/src/main/resources/supply-server.yaml
+++ b/service/run-config/prod/src/main/resources/supply-server.yaml
@@ -151,4 +151,4 @@ authScheme: v3
fileServiceDomain: api.topcoder.com
# Api version
-apiVersion: v3.0.0-BETA
\ No newline at end of file
+apiVersion: v3
\ No newline at end of file
diff --git a/service/run-config/qa/src/main/resources/supply-server.yaml b/service/run-config/qa/src/main/resources/supply-server.yaml
index d4c1480..0fb2bbe 100644
--- a/service/run-config/qa/src/main/resources/supply-server.yaml
+++ b/service/run-config/qa/src/main/resources/supply-server.yaml
@@ -151,4 +151,4 @@ authScheme: v3
fileServiceDomain: api.topcoder-qa.com
# Api version
-apiVersion: v3.0.0
\ No newline at end of file
+apiVersion: v3
\ No newline at end of file