http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SystemCodeTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SystemCodeTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SystemCodeTest.java new file mode 100644 index 0000000..99fe2e9 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/SystemCodeTest.java @@ -0,0 +1,283 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.fineract.integrationtests.common.CommonConstants; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.system.CodeHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * Test for creating, updating, deleting codes and code values + * + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class SystemCodeTest { + + private ResponseSpecification responseSpec; + private ResponseSpecification generalResponseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + + this.generalResponseSpec = new ResponseSpecBuilder().build(); + + } + + // @Ignore() + @Test + // scenario 57, 58, 59, 60 + public void testCreateCode() { + final String codeName = "Client Marital Status"; + + final Integer createResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + + // verify code created + + final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.responseSpec, createResponseId, ""); + + Assert.assertNotNull(newCodeAttributes); + assertEquals("Verify value of codeId", createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify code name", codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertEquals("Verify system defined is false", false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + + // update code + final HashMap updateChangeResponse = (HashMap) CodeHelper.updateCode(this.requestSpec, this.responseSpec, createResponseId, + codeName + "(CHANGE)", "changes"); + + assertEquals("Verify code name updated", codeName + "(CHANGE)", updateChangeResponse.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + + // delete code + final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + assertEquals("Verify code deleted", createResponseId, deleteResponseId); + + // verify code deleted + final HashMap deletedCodeValues = (HashMap) CodeHelper + .getCodeById(this.requestSpec, this.generalResponseSpec, deleteResponseId, ""); + + Assert.assertNotNull(deletedCodeValues); + assertNull("Verify value of codeId", deletedCodeValues.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify code name", deletedCodeValues.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertNull("Verify system defined is false", deletedCodeValues.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + } + + // @Ignore() + @Test + // scenario 57, 60 + public void testPreventCreateDuplicateCode() { + final String codeName = "Client Marital Status"; + + // create code + final Integer createResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + + // verify code created + final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.responseSpec, createResponseId, ""); + + Assert.assertNotNull(newCodeAttributes); + assertEquals("Verify value of codeId", createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify code name", codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertEquals("Verify system defined is false", false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + + // try to create duplicate-- should fail + final List<HashMap> error = (List) CodeHelper.createCode(this.requestSpec, this.generalResponseSpec, codeName, + CommonConstants.RESPONSE_ERROR); + + assertEquals("Verify duplication error", "error.msg.code.duplicate.name", error.get(0).get("userMessageGlobalisationCode")); + + // delete code that was just created + + final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + assertEquals("Verify code deleted", createResponseId, deleteResponseId); + + // verify code deleted + final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.generalResponseSpec, + deleteResponseId, ""); + + Assert.assertNotNull(deletedCodeAttributes); + assertNull("Verify value of codeId", deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME)); + + assertNull("Verify code name", deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME)); + assertNull("Verify system defined is false", deletedCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME)); + + } + + // @Ignore + @Test + public void testUpdateDeleteSystemDefinedCode() { + + // get any systemDefined code + final HashMap systemDefinedCode = (HashMap) CodeHelper.getSystemDefinedCodes(this.requestSpec, this.responseSpec); + + // delete system-defined code should fail + final List<HashMap> error = (List) CodeHelper.deleteCodeById(this.requestSpec, this.generalResponseSpec, + (Integer) systemDefinedCode.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), CommonConstants.RESPONSE_ERROR); + + assertEquals("Cannot delete system-defined code", "error.msg.code.systemdefined", error.get(0).get("userMessageGlobalisationCode")); + + // update system-defined code should fail + + final List<HashMap> updateError = (List) CodeHelper.updateCode(this.requestSpec, this.generalResponseSpec, + (Integer) systemDefinedCode.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), + systemDefinedCode.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME) + "CHANGE", CommonConstants.RESPONSE_ERROR); + + assertEquals("Cannot update system-defined code", "error.msg.code.systemdefined", + updateError.get(0).get("userMessageGlobalisationCode")); + + } + + // @Ignore + @Test + public void testCodeValuesNotAssignedToTable() { + + final String codeName = Utils.randomNameGenerator("Marital Status1", 10); + + final String codeValue1 = "Married1"; + final String codeValue2 = "Unmarried1"; + + final int codeValue1Position = 1; + final int codeValue2Position = 1; + + final String codeDescription1 = "Description11"; + final String codeDescription2 = "Description22"; + + // create code + final Integer createCodeResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName, + CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME); + + // create first code value + final Integer createCodeValueResponseId1 = (Integer) CodeHelper.createCodeValue(this.requestSpec, this.responseSpec, + createCodeResponseId, codeValue1, codeDescription1, codeValue1Position, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); + + // create second code value + final Integer createCodeValueResponseId2 = (Integer) CodeHelper.createCodeValue(this.requestSpec, this.responseSpec, + createCodeResponseId, codeValue2, codeDescription2, codeValue1Position, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); + + // verify two code values created + + final List<HashMap> codeValuesList = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec, + createCodeResponseId, ""); + + assertEquals("Number of code values returned matches number created", 2, codeValuesList.size()); + + // verify values of first code value + final HashMap codeValuesAttributes1 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec, + createCodeResponseId, createCodeValueResponseId1, ""); + + Assert.assertNotNull(codeValuesAttributes1); + assertEquals("Verify value of codeValueId", createCodeValueResponseId1, + codeValuesAttributes1.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify value of code name", codeValue1, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + + assertEquals("Verify value of code description", codeDescription1, + codeValuesAttributes1.get(CodeHelper.CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME)); + + assertEquals("Verify position of code value", codeValue1Position, + codeValuesAttributes1.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); + + // verify values of second code value + final HashMap codeValuesAttributes2 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec, + createCodeResponseId, createCodeValueResponseId2, ""); + + Assert.assertNotNull(codeValuesAttributes2); + assertEquals("Verify value of codeValueId", createCodeValueResponseId2, + codeValuesAttributes2.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME)); + + assertEquals("Verify value of code name", codeValue2, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME)); + + assertEquals("Verify value of code description", codeDescription2, + codeValuesAttributes2.get(CodeHelper.CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME)); + + assertEquals("Verify position of code value", codeValue2Position, + codeValuesAttributes2.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME)); + + // update code value 1 + final HashMap codeValueChanges = (HashMap) CodeHelper.updateCodeValue(this.requestSpec, this.responseSpec, createCodeResponseId, + createCodeValueResponseId1, codeValue1 + "CHANGE", codeDescription1 + "CHANGE", 4, "changes"); + + assertEquals("Verify changed code value name", codeValueChanges.get("name"), codeValue1 + "CHANGE"); + + assertEquals("Verify changed code value description", codeValueChanges.get("description"), codeDescription1 + "CHANGE"); + + // delete code value + Integer deletedCodeValueResponseId1 = (Integer) CodeHelper.deleteCodeValueById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, createCodeValueResponseId1, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); + + // Verify code value deleted + + final ArrayList<HashMap> deletedCodeValueAttributes1 = (ArrayList<HashMap>) CodeHelper.getCodeValueById(this.requestSpec, + this.generalResponseSpec, createCodeResponseId, deletedCodeValueResponseId1, CommonConstants.RESPONSE_ERROR); + + assertEquals("error.msg.codevalue.id.invalid", deletedCodeValueAttributes1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + final List<HashMap> deletedCodeValuesList = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec, + createCodeResponseId, ""); + + assertEquals("Number of code values is 1", 1, deletedCodeValuesList.size()); + + final Integer deletedCodeValueResponseId2 = (Integer) CodeHelper.deleteCodeValueById(this.requestSpec, this.generalResponseSpec, + createCodeResponseId, createCodeValueResponseId2, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME); + + final ArrayList<HashMap> deletedCodeValueAttributes2 = (ArrayList<HashMap>) CodeHelper.getCodeValueById(this.requestSpec, + this.generalResponseSpec, createCodeResponseId, deletedCodeValueResponseId2, CommonConstants.RESPONSE_ERROR); + + assertEquals("error.msg.codevalue.id.invalid", deletedCodeValueAttributes2.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + final List<HashMap> deletedCodeValuesList1 = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec, + createCodeResponseId, ""); + + assertEquals("Number of code values is 0", 0, deletedCodeValuesList1.size()); + + } + + @Ignore + @Test + public void testCodeValuesAssignedToTable() { + + } + +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/TemplateIntegrationTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/TemplateIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/TemplateIntegrationTest.java new file mode 100644 index 0000000..a176c97 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/TemplateIntegrationTest.java @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.google.gson.Gson; +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class TemplateIntegrationTest { + + private final String GET_TEMPLATES_URL = "/fineract-provider/api/v1/templates?tenantIdentifier=default"; + private final String GET_TEMPLATE_ID_URL = "/fineract-provider/api/v1/templates/%s?tenantIdentifier=default"; + private final String RESPONSE_ATTRIBUTE_NAME = "name"; + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Ignore + @Test + public void test() { + + final HashMap<String, String> metadata = new HashMap<>(); + metadata.put("user", "resource_url"); + final HashMap<String, Object> map = new HashMap<>(); + map.put("name", "foo"); + map.put("text", "Hello {{template}}"); + map.put("mappers", metadata); + + ArrayList<?> get = Utils.performServerGet(this.requestSpec, this.responseSpec, this.GET_TEMPLATES_URL, ""); + final int entriesBeforeTest = get.size(); + + final Integer id = Utils.performServerPost(this.requestSpec, this.responseSpec, this.GET_TEMPLATES_URL, new Gson().toJson(map), "resourceId"); + + final String templateUrlForId = String.format(this.GET_TEMPLATE_ID_URL, id); + + final String getrequest2 = Utils.performServerGet(this.requestSpec, this.responseSpec, templateUrlForId, this.RESPONSE_ATTRIBUTE_NAME); + + Assert.assertTrue(getrequest2.equals("foo")); + + Utils.performServerDelete(this.requestSpec, this.responseSpec, templateUrlForId, ""); + + get = Utils.performServerGet(this.requestSpec, this.responseSpec, this.GET_TEMPLATES_URL, ""); + final int entriesAfterTest = get.size(); + + Assert.assertEquals(entriesBeforeTest, entriesAfterTest); + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/WorkingDaysTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/WorkingDaysTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/WorkingDaysTest.java new file mode 100755 index 0000000..92e3d09 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/WorkingDaysTest.java @@ -0,0 +1,70 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.List; + +import org.apache.fineract.integrationtests.common.CommonConstants; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.WorkingDaysHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class WorkingDaysTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private ResponseSpecification generalResponseSpec; + + @Before + public void setUp() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.generalResponseSpec = new ResponseSpecBuilder().build(); + + } + + @Test + public void updateWorkingDays() { + HashMap response = (HashMap) WorkingDaysHelper.updateWorkingDays(requestSpec, responseSpec); + Assert.assertNotNull(response.get("resourceId")); + } + + @Test + public void updateWorkingDaysWithWrongRecurrencePattern() { + final List<HashMap> error = (List) WorkingDaysHelper.updateWorkingDaysWithWrongRecurrence(requestSpec, generalResponseSpec, + CommonConstants.RESPONSE_ERROR); + assertEquals("Verify wrong recurrence pattern error", "error.msg.recurring.rule.parsing.error", + error.get(0).get("userMessageGlobalisationCode")); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/XBRLIntegrationTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/XBRLIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/XBRLIntegrationTest.java new file mode 100644 index 0000000..71041b6 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/XBRLIntegrationTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.xbrl.XBRLIntegrationTestHelper; +import org.junit.Before; +import org.junit.Test; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class XBRLIntegrationTest { + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + + private XBRLIntegrationTestHelper xbrlHelper; + + @Before + public void setUp() throws Exception { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void shouldRetrieveTaxonomyList() { + this.xbrlHelper = new XBRLIntegrationTestHelper(this.requestSpec, this.responseSpec); + + final ArrayList<HashMap> taxonomyList = this.xbrlHelper.getTaxonomyList(); + verifyTaxonomyList(taxonomyList); + } + + private void verifyTaxonomyList(final ArrayList<HashMap> taxonomyList) { + System.out.println("--------------------VERIFYING TAXONOMY LIST--------------------------"); + assertEquals("Checking for the 1st taxonomy", "AdministrativeExpense", taxonomyList.get(0).get("name")); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java new file mode 100644 index 0000000..c99ebea --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java @@ -0,0 +1,366 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.fineract.batch.domain.BatchRequest; +import org.apache.fineract.batch.domain.BatchResponse; +import org.junit.Assert; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * Helper class for {@link org.apache.fineract.integrationtests.BatchApiTest}. It + * takes care of creation of {@code BatchRequest} list and posting this list to + * the server. + * + * @author Rishabh Shukla + * + * @see org.apache.fineract.integrationtests.BatchApiTest + */ +public class BatchHelper { + + private static final String BATCH_API_URL = "/fineract-provider/api/v1/batches?" + Utils.TENANT_IDENTIFIER; + private static final String BATCH_API_URL_EXT = BATCH_API_URL + "&enclosingTransaction=true"; + + private BatchHelper() { + super(); + } + + /** + * Returns a JSON String for a list of {@code BatchRequest}s + * + * @param batchRequests + * @return JSON String of BatchRequest + */ + public static String toJsonString(final List<BatchRequest> batchRequests) { + return new Gson().toJson(batchRequests); + } + + /** + * Returns the converted string response into JSON. + * + * @param json + * @return List<BatchResponse> + */ + private static List<BatchResponse> fromJsonString(final String json) { + return new Gson().fromJson(json, new TypeToken<List<BatchResponse>>() {}.getType()); + } + + /** + * Returns a list of BatchResponse with query parameter enclosing + * transaction set to false by posting the jsonified BatchRequest to the + * server. + * + * @param requestSpec + * @param responseSpec + * @param jsonifiedBatchRequests + * @return a list of BatchResponse + */ + public static List<BatchResponse> postBatchRequestsWithoutEnclosingTransaction(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String jsonifiedBatchRequests) { + final String response = Utils.performServerPost(requestSpec, responseSpec, BATCH_API_URL, jsonifiedBatchRequests, null); + return BatchHelper.fromJsonString(response); + } + + /** + * Returns a list of BatchResponse with query parameter enclosing + * transaction set to true by posting the jsonified BatchRequest to the + * server. + * + * @param requestSpec + * @param responseSpec + * @param jsonifiedBatchRequests + * @return a list of BatchResponse + */ + public static List<BatchResponse> postBatchRequestsWithEnclosingTransaction(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String jsonifiedBatchRequests) { + final String response = Utils.performServerPost(requestSpec, responseSpec, BATCH_API_URL_EXT, jsonifiedBatchRequests, null); + return BatchHelper.fromJsonString(response); + } + + /** + * Returns a BatchResponse based on the given BatchRequest, by posting the + * request to the server. + * + * @param BatchRequest + * @return List<BatchResponse> + */ + public static List<BatchResponse> postWithSingleRequest(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final BatchRequest br) { + + final List<BatchRequest> batchRequests = new ArrayList<>(); + batchRequests.add(br); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(requestSpec, responseSpec, + jsonifiedRequest); + + // Verifies that the response result is there + Assert.assertNotNull(response); + Assert.assertTrue(response.size() > 0); + + return response; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.CreateClientCommandStrategy} + * Request as one of the request in Batch. + * + * @param reqId + * @param externalId + * @return BatchRequest + */ + public static BatchRequest createClientRequest(final Long requestId, final String externalId) { + + final BatchRequest br = new BatchRequest(); + br.setRequestId(requestId); + br.setRelativeUrl("clients"); + br.setMethod("POST"); + + final String extId; + if (externalId.equals("")) { + extId = "ext" + String.valueOf((10000 * Math.random())) + String.valueOf((10000 * Math.random())); + } else { + extId = externalId; + } + + final String body = "{ \"officeId\": 1, \"firstname\": \"Petra\", \"lastname\": \"Yton\"," + "\"externalId\": " + extId + + ", \"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en\"," + "\"active\": false, \"submittedOnDate\": \"04 March 2009\"}"; + + br.setBody(body); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.UpdateClientCommandStrategy} + * Request with given requestId and reference. + * + * @param reqId + * @param clientId + * @return BatchRequest + */ + public static BatchRequest updateClientRequest(final Long requestId, final Long reference) { + + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("clients/$.clientId"); + br.setMethod("PUT"); + br.setReference(reference); + br.setBody("{\"firstname\": \"TestFirstName\", \"lastname\": \"TestLastName\"}"); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy} + * Request with given requestId and reference. + * + * @param requestId + * @param reference + * @param productId + * @return BatchRequest + */ + public static BatchRequest applyLoanRequest(final Long requestId, final Long reference, final Integer productId) { + + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("loans"); + br.setMethod("POST"); + br.setReference(reference); + + final String body = "{\"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en_GB\", \"clientId\": \"$.clientId\"," + "\"productId\": " + + productId + ", \"principal\": \"10,000.00\", \"loanTermFrequency\": 12," + + "\"loanTermFrequencyType\": 2, \"loanType\": \"individual\", \"numberOfRepayments\": 10," + + "\"repaymentEvery\": 1, \"repaymentFrequencyType\": 2, \"interestRatePerPeriod\": 10," + + "\"amortizationType\": 1, \"interestType\": 0, \"interestCalculationPeriodType\": 1," + + "\"transactionProcessingStrategyId\": 1, \"expectedDisbursementDate\": \"10 Jun 2013\"," + + "\"submittedOnDate\": \"10 Jun 2013\"}"; + br.setBody(body); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.ApplySavingsCommandStrategy} + * Request with given requestId and reference. + * + * @param requestId + * @param reference + * @param productId + * @return BatchRequest + */ + public static BatchRequest applySavingsRequest(final Long requestId, final Long reference, final Integer productId) { + + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("savingsaccounts"); + br.setMethod("POST"); + br.setReference(reference); + + final String body = "{\"clientId\": \"$.clientId\", \"productId\": " + productId + "," + + "\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"submittedOnDate\": \"01 March 2011\"}"; + br.setBody(body); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy} + * Request with given requestId and reference + * + * @param requestId + * @param reference + * @return BatchRequest + */ + public static BatchRequest createChargeRequest(final Long requestId, final Long reference) { + + final BatchRequest br = new BatchRequest(); + br.setRequestId(requestId); + br.setRelativeUrl("loans/$.loanId/charges"); + br.setMethod("POST"); + br.setReference(reference); + + final String body = "{\"chargeId\": \"2\", \"locale\": \"en\", \"amount\": \"100\", " + + "\"dateFormat\": \"dd MMMM yyyy\", \"dueDate\": \"29 April 2013\"}"; + br.setBody(body); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy} + * Request with given requestId and reference. + * + * @param requestId + * @param reference + * @return BatchRequest + */ + public static BatchRequest collectChargesRequest(final Long requestId, final Long reference) { + + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("loans/$.loanId/charges"); + br.setReference(reference); + br.setMethod("GET"); + br.setBody("{ }"); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.ActivateClientCommandStrategy} + * Request with given requestId and reference. + * + * + * @param requestId + * @param reference + * @return BatchRequest + */ + public static BatchRequest activateClientRequest(final Long requestId, final Long reference) { + + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("clients/$.clientId?command=activate"); + br.setReference(reference); + br.setMethod("POST"); + br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"activationDate\": \"01 March 2011\"}"); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy} + * Request with given requestId and reference. + * + * + * @param requestId + * @param reference + * @return BatchRequest + */ + public static BatchRequest approveLoanRequest(final Long requestId, final Long reference) { + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("loans/$.loanId?command=approve"); + br.setReference(reference); + br.setMethod("POST"); + br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"approvedOnDate\": \"12 September 2013\"," + + "\"note\": \"Loan approval note\"}"); + + return br; + } + + /** + * Creates and returns a + * {@link org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy} + * Request with given requestId and reference. + * + * + * @param requestId + * @param reference + * @return BatchRequest + */ + public static BatchRequest disburseLoanRequest(final Long requestId, final Long reference) { + final BatchRequest br = new BatchRequest(); + + br.setRequestId(requestId); + br.setRelativeUrl("loans/$.loanId?command=disburse"); + br.setReference(reference); + br.setMethod("POST"); + br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"actualDisbursementDate\": \"15 September 2013\"}"); + + return br; + } + + /** + * Checks that the client with given externalId is not created on the + * server. + * + * @param requestSpec + * @param responseSpec + * @param externalId + */ + public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String externalId) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + final String CLIENT_URL = "/fineract-provider/api/v1/clients?externalId=" + externalId + "&" + Utils.TENANT_IDENTIFIER; + final Integer responseRecords = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "totalFilteredRecords"); + Assert.assertEquals("No records found with given externalId", (long) responseRecords, (long) 0); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CalendarHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CalendarHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CalendarHelper.java new file mode 100644 index 0000000..0e9423b --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CalendarHelper.java @@ -0,0 +1,89 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import static com.jayway.restassured.path.json.JsonPath.from; +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class CalendarHelper { + + private static final String BASE_URL = "/fineract-provider/api/v1/"; + private static final String PARENT_ENTITY_NAME = "groups/"; + private static final String ENITY_NAME = "/calendars"; + + public static Integer createMeetingCalendarForGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer groupId, final String startDate, final String frequency, final String interval, final String repeatsOnDay) { + + System.out.println("---------------------------------CREATING A MEETING CALENDAR FOR THE GROUP------------------------------"); + + final String CALENDAR_RESOURCE_URL = BASE_URL + PARENT_ENTITY_NAME + groupId + ENITY_NAME + "?" + Utils.TENANT_IDENTIFIER; + + System.out.println(CALENDAR_RESOURCE_URL); + + return Utils.performServerPost(requestSpec, responseSpec, CALENDAR_RESOURCE_URL, + getTestCalendarAsJSON(frequency, interval, repeatsOnDay, startDate), "resourceId"); + } + + public static Integer updateMeetingCalendarForGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer groupId, String calendarID, final String startDate, final String frequency, final String interval, + final String repeatsOnDay) { + + System.out.println("---------------------------------UPDATING A MEETING CALENDAR FOR THE GROUP------------------------------"); + + final String CALENDAR_RESOURCE_URL = BASE_URL + PARENT_ENTITY_NAME + groupId + ENITY_NAME + "/" + calendarID; + + System.out.println(CALENDAR_RESOURCE_URL); + // TODO: check that resource id indeed exists in calendar update put. + return Utils.performServerPut(requestSpec, responseSpec, CALENDAR_RESOURCE_URL, + getTestCalendarAsJSON(frequency, interval, repeatsOnDay, startDate), "resourceId"); + } + + public static String getTestCalendarAsJSON(final String frequency, final String interval, final String repeatsOnDay, + final String startDate) { + + final HashMap<String, String> map = new HashMap<>(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("frequency", frequency); + map.put("interval", interval); + map.put("repeating", "true"); + map.put("repeatsOnDay", repeatsOnDay); + map.put("title", Utils.randomNameGenerator("groups_CollectionMeeting", 4)); + map.put("typeId", "1"); + map.put("startDate", startDate); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static void verifyCalendarCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupId, final Integer generatedCalendarId) { + System.out.println("------------------------------CHECK CALENDAR DETAILS------------------------------------\n"); + final String CLIENT_URL = "/fineract-provider/api/v1/groups/" + generatedGroupId + "?associations=all&" + Utils.TENANT_IDENTIFIER; + final String responseCalendarDetailsinJSON = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, + "collectionMeetingCalendar"); + final Integer responseCalendarId = from(responseCalendarDetailsinJSON).get("id"); + assertEquals("ERROR IN CREATING THE CALENDAR", generatedCalendarId, responseCalendarId); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterDomain.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterDomain.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterDomain.java new file mode 100644 index 0000000..c6ff955 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterDomain.java @@ -0,0 +1,248 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.fineract.infrastructure.core.service.DateUtils; + +import com.google.gson.Gson; + +public class CenterDomain implements Comparable<CenterDomain> { + + public static class Builder { + + private Integer id; + private String accountNo; + private HashMap status; + private boolean active; + private String name; + private String externalId; + private Integer staffId; + private Integer officeId; + private String officeName; + private String hierarchy; + private ArrayList<HashMap> groupMembers; + + private Builder(final Integer id, final Integer statusid, final String statuscode, final String statusvalue, final boolean active, + final String name, final String externalId, final Integer staffId, final int officeID, final String officeName, + final String hierarchy, final ArrayList<HashMap> groupMembers) { + this.id = id; + this.accountNo = accountNo; + this.status = new HashMap(); + this.status.put("id", statusid); + this.status.put("code", statuscode); + this.status.put("value", statusvalue); + this.active = active; + this.name = name; + this.externalId = externalId; + this.staffId = staffId; + this.officeId = officeID; + this.officeName = officeName; + this.hierarchy = hierarchy; + this.groupMembers = groupMembers; + } + + public CenterDomain build() { + return new CenterDomain(this.id, this.accountNo, (int) this.status.get("id"), (String) this.status.get("code"), + (String) this.status.get("value"), this.active, this.name, this.externalId, this.staffId, this.officeId, + this.officeName, this.hierarchy, groupMembers); + } + + } + + private Integer id; + private String accountNo; + private HashMap status; + private boolean active; + private String name; + private String externalId; + private Integer staffId; + private Integer officeId; + private String officeName; + private String hierarchy; + private ArrayList<HashMap> groupMembers; + + CenterDomain() { + /* super(); */ + } + + private CenterDomain(final Integer id, final String accountNo, final Integer statusid, final String statuscode, final String statusvalue, final boolean active, + final String name, final String externalId, final Integer staffId, final Integer officeID, final String officeName, + final String hierarchy, final ArrayList<HashMap> groupMembers) { + this.id = id; + this.accountNo = accountNo; + this.status = new HashMap(); + this.status.put("id", statusid); + this.status.put("code", statuscode); + this.status.put("value", statusvalue); + this.active = active; + this.name = name; + this.externalId = externalId; + this.staffId = staffId; + this.officeId = officeID; + this.officeName = officeName; + this.hierarchy = hierarchy; + this.groupMembers = groupMembers; + } + + public String toJSON() { + return new Gson().toJson(this); + } + + public static CurrencyDomain fromJSON(final String jsonData) { + return new Gson().fromJson(jsonData, CurrencyDomain.class); + } + + public static Builder create(final Integer id, final Integer statusid, final String statuscode, final String statusvalue, + final boolean active, final String name, final String externalId, final Integer staffId, final Integer officeID, + final String officeName, final String hierarchy, final ArrayList<HashMap> groupMembers) { + return new Builder(id, statusid, statuscode, statusvalue, active, name, externalId, staffId, officeID, officeName, hierarchy, + groupMembers); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static String jsonRequestToCreateCenter(Integer id, Integer statusId, String statusCode, String statusValue, Boolean active, + String activationDate, String submittedDate, String name, String externalId, Integer staffId, Integer officeID, + String officeName, String hierarchy, final int[] groupMembers) { + // String ids = String.valueOf(id); + final HashMap map = new HashMap<>(); + if (id != null) map.put("id", id); + if (statusId != null) map.put("statusId", statusId); + if (statusCode != null) map.put("statusCode", statusCode); + if (statusValue != null) map.put("statusValue", statusValue); + map.put("officeId", "1"); + map.put("name", randomNameGenerator("Center_Name_", 5)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + if (staffId != null) { + map.put("staffId", String.valueOf(staffId)); + } + if (active) { + map.put("active", "true"); + map.put("locale", "en"); + map.put("dateFormat", "dd MMM yyyy"); + map.put("activationDate", activationDate); + } else { + map.put("active", "false"); + if (submittedDate == null) + map.put("submittedOnDate", DateUtils.getDateOfTenant()); + else + map.put("submittedOnDate", submittedDate); + } + if (externalId != null) map.put("externalId", externalId); + if (groupMembers != null) map.put("groupMembers", groupMembers); + System.out.println(map); + return new Gson().toJson(map); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix); + } + + private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + public String getExternalId() { + return this.externalId; + } + + public Integer getStaffId() { + return this.staffId; + } + + public Integer getId() { + return this.id; + } + + public HashMap getStatus() { + return this.status; + } + + public boolean isActive() { + return this.active; + } + + public String getName() { + return this.name; + } + + public Integer getOfficeId() { + return this.officeId; + } + + public String getOfficeName() { + return this.officeName; + } + + public String getHierarchy() { + return this.hierarchy; + } + + public String getAccountNo(){ + return this.accountNo; + } + + public int[] getGroupMembers() { + int[] groupMemberList = new int[this.groupMembers.size()]; + for (int i = 0; i < groupMemberList.length; i++) { + groupMemberList[i] = ((Double) this.groupMembers.get(i).get("id")).intValue(); + } + return groupMemberList; + } + + @Override + public int hashCode() { + int hash = 1; + + if (this.id >= 0) hash += this.id; + if (this.status != null) { + if ((Double) this.status.get("id") >= 0) hash += (Double) this.status.get("id"); + if ((String) this.status.get("code") != null) hash += this.status.get("code").hashCode(); + if ((String) this.status.get("value") != null) hash += this.status.get("value").hashCode(); + } + if (this.name != null) hash += this.name.hashCode(); + if (this.officeId >= 0) hash += this.officeId; + if (this.officeName != null) hash += this.officeName.hashCode(); + if (this.hierarchy != null) hash += this.hierarchy.hashCode(); + if (this.groupMembers != null) hash += this.groupMembers.hashCode(); + + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { return true; } + + if (!(obj instanceof CenterDomain)) return false; + + CenterDomain cd = (CenterDomain) obj; + + if (this.hashCode() == cd.hashCode()) return true; + return false; + } + + @Override + public int compareTo(CenterDomain cd) { + return ((Integer) this.id).compareTo(cd.getId()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java new file mode 100644 index 0000000..f81c64a --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CenterHelper.java @@ -0,0 +1,268 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import static org.junit.Assert.assertEquals; +import java.util.HashMap; +import org.apache.commons.lang3.StringUtils; +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class CenterHelper { + + private static final String CENTERS_URL = "/fineract-provider/api/v1/centers"; + + public static final String CREATED_DATE = "29 December 2014"; + private static final String CREATE_CENTER_URL = "/fineract-provider/api/v1/centers?" + Utils.TENANT_IDENTIFIER; + + public static CenterDomain retrieveByID(int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String GET_CENTER_BY_ID_URL = CENTERS_URL + "/" + id + "?associations=groupMembers&" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING CENTER AT " + id + "-------------------------"); + final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER_BY_ID_URL, "")); + return new Gson().fromJson(jsonData, new TypeToken<CenterDomain>() {}.getType()); + } + + public static ArrayList<CenterDomain> paginatedListCenters(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String GET_CENTER = CENTERS_URL + "?paged=true&limit=-1&" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING CENTERS-------------------------"); + final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, "pageItems")); + return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CenterDomain>>() {}.getType()); + } + + public static ArrayList<CenterDomain> listCenters(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String GET_CENTER = CENTERS_URL + "?limit=-1&" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING CENTERS-------------------------"); + final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, "")); + return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CenterDomain>>() {}.getType()); + } + + public static int createCenter(final String name, final int officeId, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + return createCenter(name, officeId, null, -1, null, null, requestSpec, responseSpec); + } + + public static int createCenter(final String name, final int officeId, final String activationDate, + final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return createCenter(name, officeId, null, -1, null, activationDate, requestSpec, responseSpec); + } + + public static int createCenter(final String name, final int officeId, final String externalId, final int staffId, + final int[] groupMembers, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return createCenter(name, officeId, externalId, staffId, groupMembers, null, requestSpec, responseSpec); + } + + public static int createCenter(final String name, final int officeId, final String externalId, final int staffId, + final int[] groupMembers, final String activationDate, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String CREATE_CENTER_URL = CENTERS_URL + "?" + Utils.TENANT_IDENTIFIER; + HashMap hm = new HashMap(); + hm.put("name", name); + hm.put("officeId", officeId); + hm.put("active", false); + + if (externalId != null) hm.put("externalId", externalId); + if (staffId != -1) hm.put("staffId", staffId); + if (groupMembers != null) hm.put("groupMembers", groupMembers); + if (activationDate != null) { + hm.put("active", true); + hm.put("locale", "en"); + hm.put("dateFormat", "dd MMM yyyy"); + hm.put("activationDate", activationDate); + } + + System.out.println("------------------------CREATING CENTER-------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, new Gson().toJson(hm), "resourceId"); + } + + public static HashMap<String, String> updateCenter(final int id, HashMap request, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String UPDATE_CENTER_URL = CENTERS_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE CENTER AT " + id + "---------------------------------------------"); + HashMap<String, String> hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_CENTER_URL, new Gson().toJson(request), + "changes"); + return hash; + } + + public static int[] associateGroups(final int id, final int[] groupMembers, final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String ASSOCIATE_GROUP_CENTER_URL = CENTERS_URL + "/" + id + "?command=associateGroups&" + Utils.TENANT_IDENTIFIER; + HashMap groupMemberHashMap = new HashMap(); + groupMemberHashMap.put("groupMembers", groupMembers); + System.out.println("---------------------------------ASSOCIATING GROUPS AT " + id + "--------------------------------------------"); + HashMap hash = Utils.performServerPost(requestSpec, responseSpec, ASSOCIATE_GROUP_CENTER_URL, + new Gson().toJson(groupMemberHashMap), "changes"); + System.out.println(hash); + ArrayList<String> arr = (ArrayList<String>) hash.get("groupMembers"); + int[] ret = new int[arr.size()]; + for (int i = 0; i < ret.length; i++) { + ret[i] = Integer.parseInt(arr.get(i)); + } + return ret; + } + + public static void deleteCenter(final int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String DELETE_CENTER_URL = CENTERS_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------DELETING CENTER AT " + id + "--------------------------------------------"); + Utils.performServerDelete(requestSpec, responseSpec, DELETE_CENTER_URL, ""); + } + + public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + @SuppressWarnings("unused") final boolean active) { + System.out.println("---------------------------------CREATING A CENTER---------------------------------------------"); + return createCenter(requestSpec, responseSpec, "CREATED_DATE"); + } + + public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate) { + System.out.println("---------------------------------CREATING A CENTER---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, getTestCenterAsJSON(true, activationDate), "groupId"); + } + + public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + System.out.println("---------------------------------CREATING A CENTER---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, getTestCenterAsJSON(true, CenterHelper.CREATED_DATE), + "groupId"); + } + + public static int createCenterWithStaffId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer staffId) { + System.out.println("---------------------------------CREATING A CENTER---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, + getTestCenterWithStaffAsJSON(true, CenterHelper.CREATED_DATE, staffId), "groupId"); + } + + public static void verifyCenterCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedCenterID) { + System.out.println("------------------------------CHECK CENTER DETAILS------------------------------------\n"); + final String CENTER_URL = "/fineract-provider/api/v1/centers/" + generatedCenterID + "?" + Utils.TENANT_IDENTIFIER; + final Integer responseCenterID = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "id"); + assertEquals("ERROR IN CREATING THE CENTER", generatedCenterID, responseCenterID); + } + + public static void verifyCenterActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedCenterID, final boolean generatedCenterStatus) { + System.out.println("------------------------------CHECK CENTER STATUS------------------------------------\n"); + final String CENTER_URL = "/fineract-provider/api/v1/centers/" + generatedCenterID + "?" + Utils.TENANT_IDENTIFIER; + final Boolean responseCenterStatus = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "active"); + assertEquals("ERROR IN ACTIVATING THE CENTER", generatedCenterStatus, responseCenterStatus); + } + + public static Integer activateCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String centerId) { + final String CENTER_ASSOCIATE_URL = "/fineract-provider/api/v1/centers/" + centerId + "?command=activate&" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------ACTIVATE A CENTER---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CENTER_ASSOCIATE_URL, activateCenterAsJSON(""), "groupId"); + } + + public static String getTestCenterWithStaffAsJSON(final boolean active, final String activationDate, final Integer staffId) { + + Integer id = null; + Integer statusid = null; + String statuscode = null; + String statusvalue = null; + String name = null; + String externalId = null; + Integer officeID = null; + String officeName = null; + String hierarchy = null; + int[] groupMembers = null; + String submittedDate = null; + + return CenterDomain.jsonRequestToCreateCenter(id, statusid, statuscode, statusvalue, active, activationDate,submittedDate,name, + externalId, staffId, officeID, officeName, hierarchy, groupMembers); + } + + public static String getTestCenterAsJSON(final boolean active, final String activationDate) { + + Integer id = null; + Integer statusid = null; + String statuscode = null; + String statusvalue = null; + String name = null; + String externalId = null; + Integer officeID = null; + String officeName = null; + Integer staffId = null; + String hierarchy = null; + final int[] groupMembers = null; + String submittedDate = null; + + return CenterDomain.jsonRequestToCreateCenter(id, statusid, statuscode, statusvalue, active, activationDate,submittedDate,name, + externalId, staffId, officeID, officeName, hierarchy, groupMembers); + + } + + public static String assignStaffAsJSON(final Long staffId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("staffId", staffId); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String unassignStaffAsJSON(final Long staffId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("staffId", staffId); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String activateCenterAsJSON(final String activationDate) { + final HashMap<String, String> map = new HashMap<>(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + if (StringUtils.isNotEmpty(activationDate)) { + map.put("activationDate", activationDate); + } else { + map.put("activationDate", "CREATED_DATE"); + System.out.println("defaulting to fixed date: CREATED_DATE"); + } + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix); + } + + private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + public static Object assignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String groupId, final Long staffId) { + final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + + "&command=assignStaff"; + System.out.println("---------------------------------Assign Staff---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, assignStaffAsJSON(staffId), "changes"); + } + + public static Object unassignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String groupId, final Long staffId) { + final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + + "&command=unassignStaff"; + System.out.println("---------------------------------Unassign Staff---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, unassignStaffAsJSON(staffId), "changes"); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientChargesTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientChargesTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientChargesTest.java new file mode 100644 index 0000000..f9b01c6 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientChargesTest.java @@ -0,0 +1,175 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import org.apache.fineract.integrationtests.common.charges.ChargesHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * + * IntegrationTest for ClientCharges. + * + */ +/** + * @author lenovo + * + */ +public class ClientChargesTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void clientChargeTest() { + + // Creates clientCharge + final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getChargeSpecifiedDueDateJSON()); + Assert.assertNotNull(chargeId); + + // creates client with activation date + final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 November 2012"); + Assert.assertNotNull(clientId); + + /** + * create a charge for loan and try to associate to client created in + * the above lines.it will be an invalid scenario the reason is client + * is not allowed to have only client charge. + * + */ + final Integer loanChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getLoanSpecifiedDueDateJSON()); + Assert.assertNotNull(loanChargeId); + ResponseSpecification responseLoanChargeFailure = new ResponseSpecBuilder().expectStatusCode(403).build(); + final Integer clientLoanChargeId = ClientHelper.addChargesForClient(this.requestSpec, responseLoanChargeFailure, clientId, + ClientHelper.getSpecifiedDueDateChargesClientAsJSON(loanChargeId.toString(), "29 October 2011")); + Assert.assertNull(clientLoanChargeId); + + /** + * associates a clientCharge to a client and pay client charge for 10 + * USD--success scenario + **/ + final Integer clientChargeId = ClientHelper.addChargesForClient(this.requestSpec, this.responseSpec, clientId, + ClientHelper.getSpecifiedDueDateChargesClientAsJSON(chargeId.toString(), "29 October 2011")); + Assert.assertNotNull(clientChargeId); + final String clientChargePaidTransactionId = ClientHelper.payChargesForClients(this.requestSpec, this.responseSpec, clientId, + clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "10")); + Assert.assertNotNull(clientChargePaidTransactionId); + isValidOutstandingAmount(ClientHelper.getClientCharge(requestSpec, responseSpec, clientId.toString(), clientChargeId.toString()), + (float) 190.0); + + /** + * Revert the paid client charge transaction by passing the + * clientChargePaidTransactionId and ensure the same is reverted. + */ + final Integer undoTrxnId = ClientHelper.revertClientChargeTransaction(this.requestSpec, this.responseSpec, + clientId.toString(), clientChargePaidTransactionId); + Assert.assertNotNull(undoTrxnId); + isReversedTransaction(clientId.toString(), undoTrxnId.toString()); + /** + * Now pay client charge for 20 USD and ensure the outstanding amount is + * updated properly + */ + ResponseSpecification responseSpecFailure = new ResponseSpecBuilder().expectStatusCode(400).build(); + final String responseId_futureDate_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId, + clientChargeId, ClientHelper.getPayChargeJSON("28 AUGUST 2016", "20")); + Assert.assertNull(responseId_futureDate_failure); + + // waived off the outstanding client charge + final String waiveOffClientChargeTransactionId = ClientHelper.waiveChargesForClients(this.requestSpec, this.responseSpec, clientId, + clientChargeId, ClientHelper.getWaiveChargeJSON("100", clientChargeId.toString())); + Assert.assertNotNull(waiveOffClientChargeTransactionId); + + /** + * Revert the waived off client charge transaction by passing the + * waiveOffClientChargeTransactionId and ensured the transaction is + * reversed. + */ + final Integer undoWaiveTrxnId = ClientHelper.revertClientChargeTransaction(this.requestSpec, this.responseSpec, clientId.toString(), + waiveOffClientChargeTransactionId); + Assert.assertNotNull(undoWaiveTrxnId); + isReversedTransaction(clientId.toString(), undoWaiveTrxnId.toString()); + /** + * pay client charge before client activation date and ensured its a + * failure test case + */ + + final String responseId_activationDate_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId, + clientChargeId, ClientHelper.getPayChargeJSON("30 October 2011", "20")); + Assert.assertNull(responseId_activationDate_failure); + /** + * pay client charge more than outstanding amount amount and ensured its + * a failure test case + */ + final String responseId_moreAmount_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId, + clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "300")); + Assert.assertNull(responseId_moreAmount_failure); + /** + * pay client charge for 10 USD and ensure outstanding amount is updated + * properly + */ + final String chargePaid_responseId = ClientHelper.payChargesForClients(this.requestSpec, this.responseSpec, clientId, + clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "100")); + Assert.assertNotNull(chargePaid_responseId); + + isValidOutstandingAmount(ClientHelper.getClientCharge(requestSpec, responseSpec, clientId.toString(), clientChargeId.toString()), + (float) 100.0); + + } + + /** + * It checks whether the client charge transaction is reversed or not. + * + * @param clientId + * @param transactionId + */ + private void isReversedTransaction(String clientId, String transactionId) { + final Boolean isReversed = ClientHelper.getClientTransactions(this.requestSpec, this.responseSpec, clientId.toString(), + transactionId); + Assert.assertTrue(isReversed); + } + + /** + * Check whether the outStandingAmount is equal to expected Amount or not + * after paying or after waiving off the client charge. + * + * @param outStandingAmount + * @param expectedAmount + */ + private void isValidOutstandingAmount(Object outStandingAmount, Object expectedAmount) { + Assert.assertEquals((float) outStandingAmount, expectedAmount); + } + +}
