josehernandezfintecheandomx commented on code in PR #2783:
URL: https://github.com/apache/fineract/pull/2783#discussion_r1041079491


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientExternalIdTest.java:
##########
@@ -0,0 +1,320 @@
+/**
+ * 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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.models.DeleteClientsClientIdResponse;
+import org.apache.fineract.client.models.GetClientTransferProposalDateResponse;
+import org.apache.fineract.client.models.GetClientsClientIdAccountsResponse;
+import org.apache.fineract.client.models.GetClientsClientIdResponse;
+import org.apache.fineract.client.models.GetObligeeData;
+import org.apache.fineract.client.models.PostClientsClientIdResponse;
+import org.apache.fineract.client.models.PostClientsResponse;
+import org.apache.fineract.client.models.PutClientsClientIdResponse;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.portfolio.client.domain.ClientStatus;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+@Slf4j
+public class ClientExternalIdTest {
+
+    private ResponseSpecification responseSpec;
+    private RequestSpecification requestSpec;
+
+    @BeforeEach
+    public void setup() {
+        Utils.initializeRESTAssured();
+        requestSpec = new 
RequestSpecBuilder().setContentType(ContentType.JSON).build();
+        requestSpec.header("Authorization", "Basic " + 
Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+        responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOffCreateClient() {
+        // given
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
false);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                null);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNull(clientResponse.getResourceExternalId());
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOffCreateClientWithValue() {
+        // given
+        final String externalId = Utils.randomStringGenerator("ID_", 7);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                externalId);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNotNull(clientResponse.getResourceExternalId());
+        assertEquals(externalId, clientResponse.getResourceExternalId());
+
+        fetchClientByExternalId(clientResponse.getResourceExternalId());
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOnCreateClient() {
+        // given
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
true);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                null);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNotNull(clientResponse.getResourceExternalId());
+        assertEquals(36, clientResponse.getResourceExternalId().length());
+
+        fetchClientByExternalId(clientResponse.getResourceExternalId());
+
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
false);
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOnCreateClientWithValue() {
+        // given
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
true);
+        final String externalId = Utils.randomStringGenerator("ID_", 7);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                externalId);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNotNull(clientResponse.getResourceExternalId());
+        assertEquals(externalId, clientResponse.getResourceExternalId());
+
+        fetchClientByExternalId(clientResponse.getResourceExternalId());
+
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
false);
+    }
+
+    @Test
+    public void testClientStatusUsingExternalId() {
+        ClientHelper clientHelper = new ClientHelper(requestSpec, 
responseSpec);
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
true);
+        String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON, null);
+        final PostClientsResponse addClientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        final String clientExternalId = 
addClientResponse.getResourceExternalId();
+        final Long clientId = addClientResponse.getClientId();
+        assertNotNull(clientExternalId);
+        log.info("Client data id {} and external Id {}", clientId, 
clientExternalId);
+
+        GetClientsClientIdResponse clientResponse = 
ClientHelper.getClientByExternalId(requestSpec, responseSpec, clientExternalId);
+        ClientStatusChecker.verifyClientStatus(ClientStatus.ACTIVE, 
clientResponse);
+        log.info("Client data id {} and status {}", clientExternalId, 
clientResponse.getStatus().getCode());
+
+        // Close Client action
+        jsonPayload = clientHelper.getCloseClientAsJSON();
+        PostClientsClientIdResponse commandResponse = 
ClientHelper.performClientActionUsingExternalId(requestSpec, responseSpec,
+                clientExternalId, ClientHelper.CLOSE_CLIENT_COMMAND, 
jsonPayload);
+        assertNotNull(commandResponse);
+        assertNotNull(commandResponse.getResourceExternalId());

Review Comment:
   Done



##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientExternalIdTest.java:
##########
@@ -0,0 +1,320 @@
+/**
+ * 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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+import java.util.List;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.models.DeleteClientsClientIdResponse;
+import org.apache.fineract.client.models.GetClientTransferProposalDateResponse;
+import org.apache.fineract.client.models.GetClientsClientIdAccountsResponse;
+import org.apache.fineract.client.models.GetClientsClientIdResponse;
+import org.apache.fineract.client.models.GetObligeeData;
+import org.apache.fineract.client.models.PostClientsClientIdResponse;
+import org.apache.fineract.client.models.PostClientsResponse;
+import org.apache.fineract.client.models.PutClientsClientIdResponse;
+import org.apache.fineract.integrationtests.common.ClientHelper;
+import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
+import org.apache.fineract.integrationtests.common.Utils;
+import org.apache.fineract.portfolio.client.domain.ClientStatus;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+@Slf4j
+public class ClientExternalIdTest {
+
+    private ResponseSpecification responseSpec;
+    private RequestSpecification requestSpec;
+
+    @BeforeEach
+    public void setup() {
+        Utils.initializeRESTAssured();
+        requestSpec = new 
RequestSpecBuilder().setContentType(ContentType.JSON).build();
+        requestSpec.header("Authorization", "Basic " + 
Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
+        responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOffCreateClient() {
+        // given
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
false);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                null);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNull(clientResponse.getResourceExternalId());
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOffCreateClientWithValue() {
+        // given
+        final String externalId = Utils.randomStringGenerator("ID_", 7);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                externalId);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNotNull(clientResponse.getResourceExternalId());
+        assertEquals(externalId, clientResponse.getResourceExternalId());
+
+        fetchClientByExternalId(clientResponse.getResourceExternalId());
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOnCreateClient() {
+        // given
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
true);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                null);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNotNull(clientResponse.getResourceExternalId());
+        assertEquals(36, clientResponse.getResourceExternalId().length());
+
+        fetchClientByExternalId(clientResponse.getResourceExternalId());
+
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
false);
+    }
+
+    @Test
+    public void whenAutoExternalIdConfigIsOnCreateClientWithValue() {
+        // given
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
true);
+        final String externalId = Utils.randomStringGenerator("ID_", 7);
+        final String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON,
+                externalId);
+        // when
+        final PostClientsResponse clientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        // then
+        assertNotNull(clientResponse);
+        assertNotNull(clientResponse.getResourceExternalId());
+        assertEquals(externalId, clientResponse.getResourceExternalId());
+
+        fetchClientByExternalId(clientResponse.getResourceExternalId());
+
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
false);
+    }
+
+    @Test
+    public void testClientStatusUsingExternalId() {
+        ClientHelper clientHelper = new ClientHelper(requestSpec, 
responseSpec);
+        GlobalConfigurationHelper.manageConfigurations(requestSpec, 
responseSpec,
+                GlobalConfigurationHelper.ENABLE_AUTOGENERATED_EXTERNAL_ID, 
true);
+        String jsonPayload = 
ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, 
ClientHelper.LEGALFORM_ID_PERSON, null);
+        final PostClientsResponse addClientResponse = 
ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
+        final String clientExternalId = 
addClientResponse.getResourceExternalId();
+        final Long clientId = addClientResponse.getClientId();
+        assertNotNull(clientExternalId);
+        log.info("Client data id {} and external Id {}", clientId, 
clientExternalId);
+
+        GetClientsClientIdResponse clientResponse = 
ClientHelper.getClientByExternalId(requestSpec, responseSpec, clientExternalId);
+        ClientStatusChecker.verifyClientStatus(ClientStatus.ACTIVE, 
clientResponse);
+        log.info("Client data id {} and status {}", clientExternalId, 
clientResponse.getStatus().getCode());
+
+        // Close Client action
+        jsonPayload = clientHelper.getCloseClientAsJSON();
+        PostClientsClientIdResponse commandResponse = 
ClientHelper.performClientActionUsingExternalId(requestSpec, responseSpec,
+                clientExternalId, ClientHelper.CLOSE_CLIENT_COMMAND, 
jsonPayload);
+        assertNotNull(commandResponse);
+        assertNotNull(commandResponse.getResourceExternalId());
+        log.info("Client data id {} and external Id {}", 
commandResponse.getResourceId(), clientExternalId);
+        assertEquals(clientId.intValue(), commandResponse.getResourceId());
+
+        clientResponse = ClientHelper.getClientByExternalId(requestSpec, 
responseSpec, clientExternalId);
+        ClientStatusChecker.verifyClientStatus(ClientStatus.CLOSED, 
clientResponse);
+        log.info("Client data id {} and status {}", clientExternalId, 
clientResponse.getStatus().getCode());
+
+        // Reactivate Client action
+        jsonPayload = clientHelper.getReactivateClientAsJSON();
+        commandResponse = 
ClientHelper.performClientActionUsingExternalId(requestSpec, responseSpec, 
clientExternalId,
+                ClientHelper.REACTIVATE_CLIENT_COMMAND, jsonPayload);
+        assertNotNull(commandResponse);
+        assertNotNull(commandResponse.getResourceExternalId());

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@fineract.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to