Skip to content

Commit

Permalink
Merge pull request #3 from vives/master
Browse files Browse the repository at this point in the history
Fixed to support ESB 5.0.0-BETA
  • Loading branch information
keerthu authored Jul 11, 2016
2 parents cced0cd + 5cb1e6d commit 9b67725
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The TSheets connector allows you to access the TSheets REST API through the WSO2
mvn clean install

### How You Can Contribute
You can create a third party connector and publish in WSO2 Connector Store.
You can create a third party connector and publish in WSO2 Store.

https://docs.wso2.com/display/ESBCONNECTORS/Creating+a+Third+Party+Connector+and+Publishing+in+WSO2+Connector+Store
https://docs.wso2.com/display/ESBCONNECTORS/Creating+a+Third+Party+Connector+and+Publishing+in+WSO2+Store

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<properties>
<connector.name>tsheets</connector.name>
<test.framework.version>4.2.0</test.framework.version>
<esb.version>4.9.0</esb.version>
<esb.version>5.0.0-BETA</esb.version>
<carbon.kernel.version>4.4.1</carbon.kernel.version>
<emma.version>2.1.5320</emma.version>
<synapse.version>2.1.3-wso2v11</synapse.version>
Expand Down Expand Up @@ -317,4 +317,4 @@
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
}
// Prefix the urlQuery with '?' and remove the trailing '&'
if (urlQuery != "") {
urlQuery = '?' + urlQuery.substring(0, urlQuery.length-1);
urlQuery = '?' + urlQuery.toString().substring(0, urlQuery.toString().lastIndexOf("&"));
mc.setProperty('uri.var.urlQuery', urlQuery);
}
]]>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/tsheets-jobCodes/listJobCodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
}
// Prefix the urlQuery with '?' and remove the trailing '&'
if (urlQuery != "") {
urlQuery = '?' + urlQuery.substring(0, urlQuery.length-1);
urlQuery = '?' + urlQuery.toString().substring(0, urlQuery.toString().lastIndexOf("&"));
mc.setProperty('uri.var.urlQuery', urlQuery);
}
]]>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/tsheets-timeSheets/listTimeSheets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
}
// Prefix the urlQuery with '?' and remove the trailing '&'
if (urlQuery != "") {
urlQuery = '?' + urlQuery.substring(0, urlQuery.length-1);
urlQuery = '?' + urlQuery.toString().substring(0, urlQuery.toString().lastIndexOf("&"));
mc.setProperty('uri.var.urlQuery', urlQuery);
}
]]>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/tsheets-users/listUsers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}
// Prefix the urlQuery with '?' and remove the trailing '&'
if (urlQuery != "") {
urlQuery = '?' + urlQuery.substring(0, urlQuery.length-1);
urlQuery = '?' + urlQuery.toString().substring(0, urlQuery.toString().lastIndexOf("&"));
mc.setProperty('uri.var.urlQuery', urlQuery);
}
]]>
Expand Down
10 changes: 5 additions & 5 deletions src/test/INTEGRATION-TEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Pre-requisites:
Tested Platform:

- Microsoft WINDOWS V-7
- UBUNTU 13.04, Mac OSx 10.9
- WSO2 ESB 4.9.0
- UBUNTU 13.04, Mac OSx 10.9, 14.04
- WSO2 ESB 4.9.0, 5.0.0-BETA
- Java 1.7

Note:
Expand All @@ -20,7 +20,7 @@ Note:

Steps to follow in setting integration test.

1. Download ESB 4.9.0 and compress ESB as wso2esb-4.9.0.zip and copy that zip file in to location "{TSHEETS_HOME}/repository/".
1. Download ESB 5.0.0-BETA, add "-XX:-UseSplitVerifier" under $JVM_MEM_OPTS into {ESB_HOME}/bin/wso2server.sh" and compress ESB as wso2esb- 5.0.0-BETA.zip and copy that zip file in to location "{TSHEETS_HOME}/repository/".

2. Follow the below steps to create a TSheets account.

Expand All @@ -39,9 +39,9 @@ Steps to follow in setting integration test.

5. Update the TSheets properties file at location "{TSHEETS_HOME}/src/test/resources/artifacts/ESB/connector/config" as below.

i) apiUrl - Use the API URL as "https://rest.tsheets.com".
i) apiUrl - Use the API URL as "https://rest.tsheets.com".
ii) accessToken - Place the accesstoken obtained in step 3[i].
iii) jobCodeOneName - Name of a job code.
iii) jobCodeOneName - Name of a job code.
iv) jobCodeTwoName - Name of a job code.
v) timeSheetType - Type of the Timesheet.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TSheetsConnectorIntegrationTest extends ConnectorIntegrationTestBas
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

init("tsheets-connector-1.0.1-SNAPSHOT");
init("tsheets-connector-1.0.1");

esbRequestHeadersMap.put("Accept-Charset", "UTF-8");
esbRequestHeadersMap.put("Content-Type", "application/json");
Expand All @@ -55,19 +55,24 @@ public void setEnvironment() throws Exception {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = new Date();
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(sdf.format(date));
SimpleDateFormat sdf01 = new SimpleDateFormat("yyyy-MM-dd");

date.setDate(date.getDate() - 1);
String timeSheetTwoEnd = sdf.format(date) + "-07:00";
date.setMinutes(date.getMinutes() - 1);
String timeSheetTwoStart = sdf.format(date) + "-07:00";
date.setDate(date.getDate() - 1);
String timeSheetOneEnd = sdf.format(date) + "-07:00";
String listTimeSheetOneEnd = sdf01.format(date);
date.setMinutes(date.getMinutes() - 1);
String timeSheetOneStart = sdf.format(date) + "-07:00";
String listTimeSheetOneStart = sdf01.format(date);
connectorProperties.setProperty("timeSheetOneStart", timeSheetOneStart);
connectorProperties.setProperty("timeSheetOneEnd", timeSheetOneEnd);
connectorProperties.setProperty("timeSheetTwoStart", timeSheetTwoStart);
connectorProperties.setProperty("timeSheetTwoEnd", timeSheetTwoEnd);
connectorProperties.setProperty("listTimeSheetOneStart", listTimeSheetOneStart);
connectorProperties.setProperty("listTimeSheetOneEnd", listTimeSheetOneEnd);
}

/**
Expand Down Expand Up @@ -231,7 +236,8 @@ public void testAddJobCodesWithNegativeCase() throws IOException, JSONException
/**
* Positive test case for listJobCodes method with mandatory parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodesWithMandatoryParameters"}, description = "tsheets {listJobCodes} integration test with mandatory parameters.")
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodesWithMandatoryParameters"},
description = "tsheets {listJobCodes} integration test with mandatory parameters.")
public void testListJobCodesWithMandatoryParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:listJobCodes");
Expand Down Expand Up @@ -269,7 +275,8 @@ public void testListJobCodesWithMandatoryParameters() throws IOException, JSONEx
/**
* Positive test case for listJobCodes method with optional parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodesWithMandatoryParameters"}, description = "tsheets {listJobCodes} integration test with optional parameters.")
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodesWithMandatoryParameters"},
description = "tsheets {listJobCodes} integration test with optional parameters.")
public void testListJobCodesWithOptionalParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:listJobCodes");
Expand Down Expand Up @@ -329,7 +336,8 @@ public void testListJobCodesWithNegativeCase() throws IOException, JSONException
* Positive test case for addTimeSheets method with mandatory parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testListUsersWithMandatoryParameters",
"testAddJobCodesWithMandatoryParameters"}, description = "tsheets {addTimeSheets} integration test with mandatory parameters.")
"testAddJobCodesWithMandatoryParameters"},
description = "tsheets {addTimeSheets} integration test with mandatory parameters.")
public void testAddTimeSheetsWithMandatoryParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:addTimeSheets");
Expand Down Expand Up @@ -372,13 +380,15 @@ public void testAddTimeSheetsWithNegativeCase() throws IOException, JSONExceptio
RestResponse<JSONObject> esbRestResponse =
sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_addTimeSheets_negative.json");

JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("results").getJSONObject("timesheets").getJSONObject("1");
JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("results").getJSONObject("timesheets").
getJSONObject("1");

String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/timesheets";
RestResponse<JSONObject> apiRestResponse =
sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap, "api_addTimeSheets_negative.json");

JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("results").getJSONObject("timesheets").getJSONObject("1");
JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("results").getJSONObject("timesheets").
getJSONObject("1");
Assert.assertEquals(apiRestResponse.getHttpStatusCode(), esbRestResponse.getHttpStatusCode());
Assert.assertEquals(apiResponseObject.getString("_status_code"), esbResponseObject.getString("_status_code"));
Assert.assertEquals(apiResponseObject.getString("_status_message"), esbResponseObject.getString("_status_message"));
Expand All @@ -387,19 +397,22 @@ public void testAddTimeSheetsWithNegativeCase() throws IOException, JSONExceptio
/**
* Positive test case for listTimeSheets method with mandatory parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddTimeSheetsWithMandatoryParameters"}, description = "tsheets {listTimeSheets} integration test with mandatory parameters.")
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddTimeSheetsWithMandatoryParameters"},
description = "tsheets {listTimeSheets} integration test with mandatory parameters.")
public void testListTimeSheetsWithMandatoryParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:listTimeSheets");

RestResponse<JSONObject> esbRestResponse =
sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listTimeSheets_mandatory.json");

JSONObject esbTimeSheets = esbRestResponse.getBody().getJSONObject("results").getJSONObject("timesheets");

String apiEndPoint =
connectorProperties.getProperty("apiUrl") + "/api/v1/timesheets?start_date="
+ connectorProperties.getProperty("timeSheetOneStart") + "&end_date="
+ connectorProperties.getProperty("timeSheetOneEnd");
+ connectorProperties.getProperty("listTimeSheetOneStart") + "&end_date="
+ connectorProperties.getProperty("listTimeSheetOneEnd");

RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

JSONObject apiTimeSheets = apiRestResponse.getBody().getJSONObject("results").getJSONObject("timesheets");
Expand Down Expand Up @@ -430,7 +443,8 @@ public void testListTimeSheetsWithMandatoryParameters() throws IOException, JSON
* Positive test case for listTimeSheets method with optional parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testListUsersWithMandatoryParameters",
"testAddTimeSheetsWithMandatoryParameters"}, description = "tsheets {listTimeSheets} integration test with optional parameters.")
"testAddTimeSheetsWithMandatoryParameters"},
description = "tsheets {listTimeSheets} integration test with optional parameters.")
public void testListTimeSheetsWithOptionalParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:listTimeSheets");
Expand All @@ -441,8 +455,8 @@ public void testListTimeSheetsWithOptionalParameters() throws IOException, JSONE

String apiEndPoint =
connectorProperties.getProperty("apiUrl") + "/api/v1/timesheets?start_date="
+ connectorProperties.getProperty("timeSheetOneStart") + "&end_date="
+ connectorProperties.getProperty("timeSheetOneEnd") + "&user_ids="
+ connectorProperties.getProperty("listTimeSheetOneStart") + "&end_date="
+ connectorProperties.getProperty("listTimeSheetOneEnd") + "&user_ids="
+ connectorProperties.getProperty("userId");
RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

Expand Down Expand Up @@ -496,7 +510,8 @@ public void testListTimeSheetsWithNegativeCase() throws IOException, JSONExcepti
* Positive test case for addJobCodeAssignments method with mandatory parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testListUsersWithMandatoryParameters",
"testAddJobCodesWithMandatoryParameters"}, description = "tsheets {addJobCodeAssignments} integration test with mandatory parameters.")
"testAddJobCodesWithMandatoryParameters"},
description = "tsheets {addJobCodeAssignments} integration test with mandatory parameters.")
public void testAddJobCodeAssignmentsWithMandatoryParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:addJobCodeAssignments");
Expand All @@ -509,7 +524,8 @@ public void testAddJobCodeAssignmentsWithMandatoryParameters() throws IOExceptio
String jobCodeAssignmentUserId = esbJobCodeAssignment.getString("user_id");

String apiEndPoint =
connectorProperties.getProperty("apiUrl") + "/api/v1/jobcode_assignments?user_ids=" + jobCodeAssignmentUserId;
connectorProperties.getProperty("apiUrl") + "/api/v1/jobcode_assignments?user_ids="
+ jobCodeAssignmentUserId;
RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

JSONObject apiJobCodeAssignment =
Expand All @@ -530,13 +546,15 @@ public void testAddJobCodeAssignmentsWithNegativeCase() throws IOException, JSON
RestResponse<JSONObject> esbRestResponse =
sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_addJobCodeAssignments_negative.json");

JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("results").getJSONObject("jobcode_assignments").getJSONObject("1");
JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("results").
getJSONObject("jobcode_assignments").getJSONObject("1");

String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/api/v1/jobcode_assignments";
RestResponse<JSONObject> apiRestResponse =
sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap, "api_addJobCodeAssignments_negative.json");

JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("results").getJSONObject("jobcode_assignments").getJSONObject("1");
JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("results").
getJSONObject("jobcode_assignments").getJSONObject("1");

Assert.assertEquals(apiRestResponse.getHttpStatusCode(), esbRestResponse.getHttpStatusCode());
Assert.assertEquals(apiResponseObject.getString("_status_code"), esbResponseObject.getString("_status_code"));
Expand All @@ -547,20 +565,23 @@ public void testAddJobCodeAssignmentsWithNegativeCase() throws IOException, JSON
/**
* Positive test case for listJobCodeAssignments method with mandatory parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodeAssignmentsWithMandatoryParameters"}, description = "tsheets {listJobCodeAssignments} integration test with mandatory parameters.")
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodeAssignmentsWithMandatoryParameters"},
description = "tsheets {listJobCodeAssignments} integration test with mandatory parameters.")
public void testListJobCodeAssignmentsWithMandatoryParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:listJobCodeAssignments");
RestResponse<JSONObject> esbRestResponse =
sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listJobCodeAssignments_mandatory.json");

JSONObject esbJobAssignments = esbRestResponse.getBody().getJSONObject("results").getJSONObject("jobcode_assignments");
JSONObject esbJobAssignments = esbRestResponse.getBody().getJSONObject("results").
getJSONObject("jobcode_assignments");

String apiEndPoint =
connectorProperties.getProperty("apiUrl") + "/api/v1/jobcode_assignments";
RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

JSONObject apiJobAssignments = apiRestResponse.getBody().getJSONObject("results").getJSONObject("jobcode_assignments");
JSONObject apiJobAssignments = apiRestResponse.getBody().getJSONObject("results").
getJSONObject("jobcode_assignments");

Iterator<String> esbTimeSheetKeySet = esbJobAssignments.keys();
int count = 0;
Expand All @@ -587,20 +608,23 @@ public void testListJobCodeAssignmentsWithMandatoryParameters() throws IOExcepti
/**
* Positive test case for listJobCodeAssignments method with optional parameters.
*/
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodeAssignmentsWithMandatoryParameters"}, description = "tsheets {listJobCodeAssignments} integration test with optional parameters.")
@Test(groups = {"wso2.esb"}, dependsOnMethods = {"testAddJobCodeAssignmentsWithMandatoryParameters"},
description = "tsheets {listJobCodeAssignments} integration test with optional parameters.")
public void testListJobCodeAssignmentsWithOptionalParameters() throws IOException, JSONException {

esbRequestHeadersMap.put("Action", "urn:listJobCodeAssignments");
RestResponse<JSONObject> esbRestResponse =
sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listJobCodeAssignments_optional.json");

JSONObject esbJobAssignments = esbRestResponse.getBody().getJSONObject("results").getJSONObject("jobcode_assignments");
JSONObject esbJobAssignments = esbRestResponse.getBody().getJSONObject("results").
getJSONObject("jobcode_assignments");

String apiEndPoint =
connectorProperties.getProperty("apiUrl") + "/api/v1/jobcode_assignments?page=2&per_page=1";
RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

JSONObject apiJobAssignments = apiRestResponse.getBody().getJSONObject("results").getJSONObject("jobcode_assignments");
JSONObject apiJobAssignments = apiRestResponse.getBody().getJSONObject("results").
getJSONObject("jobcode_assignments");

Iterator<String> esbTimeSheetKeySet = esbJobAssignments.keys();
int count = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"apiUrl": "%s(apiUrl)",
"accessToken": "%s(accessToken)",
"timeSheetStartDate": "%s(timeSheetOneStart)",
"timeSheetEndDate": "%s(timeSheetOneEnd)"
"timeSheetStartDate": "%s(listTimeSheetOneStart)",
"timeSheetEndDate": "%s(listTimeSheetOneEnd)"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"apiUrl": "%s(apiUrl)",
"accessToken": "%s(accessToken)",
"timeSheetStartDate": "%s(timeSheetOneStart)",
"timeSheetEndDate": "%s(timeSheetOneEnd)",
"timeSheetStartDate": "%s(listTimeSheetOneStart)",
"timeSheetEndDate": "%s(listTimeSheetOneEnd)",
"userIds": "%s(userId)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ proxyDirectoryRelativePath=/../src/test/resources/artifacts/ESB/config/proxies/t
requestDirectoryRelativePath=/../src/test/resources/artifacts/ESB/config/restRequests/tsheets/

apiUrl=https://rest.tsheets.com
accessToken=S.1__730ab728db5db2f5a797363ce677ab3305f398da
accessToken=xxxxxxxxxxxxxxxxxxx

#Job Codes
jobCodeOneName=Job Code Name14
Expand Down

0 comments on commit 9b67725

Please sign in to comment.