You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by my...@apache.org on 2018/01/22 15:47:36 UTC
[fineract-cn-customer] 35/46: Implementing document descriptions
for customers.
This is an automated email from the ASF dual-hosted git repository.
myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-customer.git
commit 2a84c2a2ba0f3c101b15aba9036f655d9259a4a6
Author: Myrle Krantz <my...@apache.org>
AuthorDate: Fri Oct 20 11:13:27 2017 +0200
Implementing document descriptions for customers.
---
api/build.gradle | 4 ++
.../customer/api/v1/domain/CustomerDocument.java | 18 +++++-
.../api/v1/domain/CustomerDocumentTest.java | 70 ++++++++++++++++++++++
.../io/mifos/customer/AbstractCustomerTest.java | 18 ++++++
.../main/java/io/mifos/customer/TestDocuments.java | 36 +++++------
.../customer/util/CustomerDocumentGenerator.java | 1 +
.../service/internal/mapper/DocumentMapper.java | 2 +
.../internal/repository/DocumentEntity.java | 14 ++++-
.../mariadb/V8__documents_description.sql | 17 ++++++
9 files changed, 159 insertions(+), 21 deletions(-)
diff --git a/api/build.gradle b/api/build.gradle
index 7bce588..1e1726e 100644
--- a/api/build.gradle
+++ b/api/build.gradle
@@ -22,6 +22,10 @@ dependencies {
[group: 'io.github.openfeign.form', name: 'feign-form', version: '2.1.0'],
[group: 'io.github.openfeign.form', name: 'feign-form-spring', version: '2.1.0']
)
+
+ testCompile(
+ [group: 'io.mifos.core', name: 'test', version: versions.frameworktest],
+ )
}
publishing {
diff --git a/api/src/main/java/io/mifos/customer/api/v1/domain/CustomerDocument.java b/api/src/main/java/io/mifos/customer/api/v1/domain/CustomerDocument.java
index e6d5857..529ad76 100644
--- a/api/src/main/java/io/mifos/customer/api/v1/domain/CustomerDocument.java
+++ b/api/src/main/java/io/mifos/customer/api/v1/domain/CustomerDocument.java
@@ -16,6 +16,7 @@
package io.mifos.customer.api.v1.domain;
import io.mifos.core.lang.validation.constraints.ValidIdentifier;
+import org.hibernate.validator.constraints.Length;
import java.util.Objects;
@@ -26,6 +27,9 @@ public class CustomerDocument {
@ValidIdentifier
private String identifier;
+ @Length(max = 4096)
+ private String description;
+
private boolean completed;
private String createdBy;
private String createdOn;
@@ -41,6 +45,14 @@ public class CustomerDocument {
this.identifier = identifier;
}
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
public boolean isCompleted() {
return completed;
}
@@ -71,18 +83,20 @@ public class CustomerDocument {
if (o == null || getClass() != o.getClass()) return false;
CustomerDocument that = (CustomerDocument) o;
return completed == that.completed &&
- Objects.equals(identifier, that.identifier);
+ Objects.equals(identifier, that.identifier) &&
+ Objects.equals(description, that.description);
}
@Override
public int hashCode() {
- return Objects.hash(identifier, completed);
+ return Objects.hash(identifier, description, completed);
}
@Override
public String toString() {
return "CustomerDocument{" +
"identifier='" + identifier + '\'' +
+ ", description='" + description + '\'' +
", completed=" + completed +
", createdBy='" + createdBy + '\'' +
", createdOn='" + createdOn + '\'' +
diff --git a/api/src/test/java/io/mifos/customer/api/v1/domain/CustomerDocumentTest.java b/api/src/test/java/io/mifos/customer/api/v1/domain/CustomerDocumentTest.java
new file mode 100644
index 0000000..41007bc
--- /dev/null
+++ b/api/src/test/java/io/mifos/customer/api/v1/domain/CustomerDocumentTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.customer.api.v1.domain;
+
+import io.mifos.core.test.domain.ValidationTest;
+import io.mifos.core.test.domain.ValidationTestCase;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author Myrle Krantz
+ */
+@RunWith(Parameterized.class)
+public class CustomerDocumentTest extends ValidationTest<CustomerDocument> {
+
+ public CustomerDocumentTest(final ValidationTestCase<CustomerDocument> testCase)
+ {
+ super(testCase);
+ }
+
+ @Override
+ protected CustomerDocument createValidTestSubject() {
+ final CustomerDocument ret = new CustomerDocument();
+ ret.setIdentifier(RandomStringUtils.randomAlphanumeric(8));
+ ret.setCompleted(false);
+ ret.setCreatedOn(null);
+ ret.setCreatedBy(null);
+ ret.setDescription(RandomStringUtils.random(5));
+ return ret;
+ }
+
+ @Parameterized.Parameters
+ public static Collection testCases() {
+ final Collection<ValidationTestCase> ret = new ArrayList<>();
+
+ ret.add(new ValidationTestCase<CustomerDocument>("valid"));
+ ret.add(new ValidationTestCase<CustomerDocument>("null description")
+ .adjustment(x -> x.setDescription(null))
+ .valid(true));
+ ret.add(new ValidationTestCase<CustomerDocument>("minimum length description")
+ .adjustment(x -> x.setDescription(RandomStringUtils.random(0)))
+ .valid(true));
+ ret.add(new ValidationTestCase<CustomerDocument>("maximum length description")
+ .adjustment(x -> x.setDescription(RandomStringUtils.random(4096)))
+ .valid(true));
+ ret.add(new ValidationTestCase<CustomerDocument>("too long description")
+ .adjustment(x -> x.setDescription(RandomStringUtils.random(4097)))
+ .valid(false));
+
+ return ret;
+ }
+
+}
diff --git a/component-test/src/main/java/io/mifos/customer/AbstractCustomerTest.java b/component-test/src/main/java/io/mifos/customer/AbstractCustomerTest.java
index 2649c13..1435366 100644
--- a/component-test/src/main/java/io/mifos/customer/AbstractCustomerTest.java
+++ b/component-test/src/main/java/io/mifos/customer/AbstractCustomerTest.java
@@ -29,10 +29,14 @@ import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -46,6 +50,7 @@ import org.springframework.test.context.junit4.SpringRunner;
classes = {AbstractCustomerTest.TestConfiguration.class})
public class AbstractCustomerTest extends SuiteTestEnvironment {
static final String TEST_USER = "maatkare";
+ private static final String LOGGER_NAME = "test-logger";
@Configuration
@EnableEventRecording
@@ -61,6 +66,11 @@ public class AbstractCustomerTest extends SuiteTestEnvironment {
public TestConfiguration() {
super();
}
+
+ @Bean(name = LOGGER_NAME)
+ public Logger logger() {
+ return LoggerFactory.getLogger(LOGGER_NAME);
+ }
}
@ClassRule
@@ -70,15 +80,23 @@ public class AbstractCustomerTest extends SuiteTestEnvironment {
public final TenantApplicationSecurityEnvironmentTestRule tenantApplicationSecurityEnvironment
= new TenantApplicationSecurityEnvironmentTestRule(testEnvironment, this::waitForInitialize);
+ @SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Autowired
CustomerManager customerManager;
+ @SuppressWarnings("SpringAutowiredFieldsWarningInspection")
@Autowired
CustomerDocumentsManager customerDocumentsManager;
+ @SuppressWarnings({"SpringAutowiredFieldsWarningInspection", "SpringJavaAutowiringInspection"})
@Autowired
EventRecorder eventRecorder;
+ @SuppressWarnings("SpringAutowiredFieldsWarningInspection")
+ @Autowired
+ @Qualifier(LOGGER_NAME)
+ Logger logger;
+
private AutoUserContext userContext;
public AbstractCustomerTest() {
diff --git a/component-test/src/main/java/io/mifos/customer/TestDocuments.java b/component-test/src/main/java/io/mifos/customer/TestDocuments.java
index 7c5f4d2..fa44409 100644
--- a/component-test/src/main/java/io/mifos/customer/TestDocuments.java
+++ b/component-test/src/main/java/io/mifos/customer/TestDocuments.java
@@ -45,24 +45,24 @@ public class TestDocuments extends AbstractCustomerTest {
@Test
public void shouldUploadEditThenCompleteDocument() throws InterruptedException, IOException {
- //Prepare test.
+ logger.info("Prepare test");
final Customer customer = CustomerGenerator.createRandomCustomer();
customerManager.createCustomer(customer);
- eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, customer.getIdentifier());
+ Assert.assertTrue(eventRecorder.wait(CustomerEventConstants.POST_CUSTOMER, customer.getIdentifier()));
- //Check that document "stub" can be created.
+ logger.info("Check that document \"stub\" can be created");
final CustomerDocument customerDocument = CustomerDocumentGenerator.createRandomCustomerDocument();
customerDocumentsManager.createDocument(customer.getIdentifier(), customerDocument.getIdentifier(), customerDocument);
- eventRecorder.wait(CustomerEventConstants.POST_DOCUMENT,
- new DocumentEvent(customer.getIdentifier(), customerDocument.getIdentifier()));
+ Assert.assertTrue(eventRecorder.wait(CustomerEventConstants.POST_DOCUMENT,
+ new DocumentEvent(customer.getIdentifier(), customerDocument.getIdentifier())));
final CustomerDocument createdCustomerDocument = customerDocumentsManager.getDocument(
customer.getIdentifier(), customerDocument.getIdentifier());
Assert.assertEquals(customerDocument, createdCustomerDocument);
- //Check that pages can be created.
+ logger.info("Check that pages can be created");
for (int i = 0; i < 10; i++) {
createDocumentPage(customer.getIdentifier(), customerDocument.getIdentifier(), i);
}
@@ -73,10 +73,10 @@ public class TestDocuments extends AbstractCustomerTest {
Assert.assertEquals(expectedPageNumbers, pageNumbers);
- //Check that a page can be deleted.
+ logger.info("Check that a page can be deleted");
customerDocumentsManager.deleteDocumentPage(customer.getIdentifier(), customerDocument.getIdentifier(), 9);
- eventRecorder.wait(CustomerEventConstants.DELETE_DOCUMENT_PAGE,
- new DocumentPageEvent(customer.getIdentifier(), customerDocument.getIdentifier(), 9));
+ Assert.assertTrue(eventRecorder.wait(CustomerEventConstants.DELETE_DOCUMENT_PAGE,
+ new DocumentPageEvent(customer.getIdentifier(), customerDocument.getIdentifier(), 9)));
final List<Integer> changedPageNumbers = customerDocumentsManager.getDocumentPageNumbers(
customer.getIdentifier(), customerDocument.getIdentifier());
@@ -90,10 +90,10 @@ public class TestDocuments extends AbstractCustomerTest {
catch (final NotFoundException ignored) {}
- //Check that a document which is missing pages cannot be completed
+ logger.info("Check that a document which is missing pages cannot be completed");
customerDocumentsManager.deleteDocumentPage(customer.getIdentifier(), customerDocument.getIdentifier(), 2);
- eventRecorder.wait(CustomerEventConstants.DELETE_DOCUMENT_PAGE,
- new DocumentPageEvent(customer.getIdentifier(), customerDocument.getIdentifier(), 2));
+ Assert.assertTrue(eventRecorder.wait(CustomerEventConstants.DELETE_DOCUMENT_PAGE,
+ new DocumentPageEvent(customer.getIdentifier(), customerDocument.getIdentifier(), 2)));
try {
customerDocumentsManager.completeDocument(customer.getIdentifier(), customerDocument.getIdentifier(), true);
@@ -104,11 +104,11 @@ public class TestDocuments extends AbstractCustomerTest {
createDocumentPage(customer.getIdentifier(), customerDocument.getIdentifier(), 2);
- //Check that a valid document can be completed.
+ logger.info("Check that a valid document can be completed");
final TimeStampChecker timeStampChecker = TimeStampChecker.roughlyNow();
customerDocumentsManager.completeDocument(customer.getIdentifier(), customerDocument.getIdentifier(), true);
- eventRecorder.wait(CustomerEventConstants.POST_DOCUMENT_COMPLETE,
- new DocumentPageEvent(customer.getIdentifier(), customerDocument.getIdentifier(), 9));
+ Assert.assertTrue(eventRecorder.wait(CustomerEventConstants.POST_DOCUMENT_COMPLETE,
+ new DocumentEvent(customer.getIdentifier(), customerDocument.getIdentifier())));
final CustomerDocument completedDocument = customerDocumentsManager.getDocument(
customer.getIdentifier(), customerDocument.getIdentifier());
@@ -116,7 +116,7 @@ public class TestDocuments extends AbstractCustomerTest {
timeStampChecker.assertCorrect(completedDocument.getCreatedOn());
- //Check that document can't be changed after completion
+ logger.info("Check that document can't be changed after completion");
try {
createDocumentPage(customer.getIdentifier(), customerDocument.getIdentifier(), 9);
Assert.fail("Adding another page after the document is completed shouldn't be possible.");
@@ -129,7 +129,7 @@ public class TestDocuments extends AbstractCustomerTest {
catch (final CompletedDocumentCannotBeChangedException ignored) {}
- //Check that document can't be uncompleted.
+ logger.info("Check that document can't be uncompleted");
try {
customerDocumentsManager.completeDocument(customer.getIdentifier(), customerDocument.getIdentifier(), false);
Assert.fail("It shouldn't be possible to change a document from completed to uncompleted.");
@@ -137,7 +137,7 @@ public class TestDocuments extends AbstractCustomerTest {
catch (final CompletedDocumentCannotBeChangedException ignored) {}
- //Check that document is in the list.
+ logger.info("Check that document is in the list");
final List<CustomerDocument> documents = customerDocumentsManager.getDocuments(customer.getIdentifier());
final boolean documentIsInList = documents.stream().anyMatch(x ->
(x.getIdentifier().equals(customerDocument.getIdentifier())) &&
diff --git a/component-test/src/main/java/io/mifos/customer/util/CustomerDocumentGenerator.java b/component-test/src/main/java/io/mifos/customer/util/CustomerDocumentGenerator.java
index 4a7ee13..f82fb07 100644
--- a/component-test/src/main/java/io/mifos/customer/util/CustomerDocumentGenerator.java
+++ b/component-test/src/main/java/io/mifos/customer/util/CustomerDocumentGenerator.java
@@ -27,6 +27,7 @@ public final class CustomerDocumentGenerator {
public static CustomerDocument createRandomCustomerDocument() {
final CustomerDocument ret = new CustomerDocument();
ret.setIdentifier(RandomStringUtils.randomAlphanumeric(8));
+ ret.setDescription(RandomStringUtils.randomAlphanumeric(4096));
return ret;
}
}
diff --git a/service/src/main/java/io/mifos/customer/service/internal/mapper/DocumentMapper.java b/service/src/main/java/io/mifos/customer/service/internal/mapper/DocumentMapper.java
index 6ea88e9..5bcf41e 100644
--- a/service/src/main/java/io/mifos/customer/service/internal/mapper/DocumentMapper.java
+++ b/service/src/main/java/io/mifos/customer/service/internal/mapper/DocumentMapper.java
@@ -55,6 +55,7 @@ public class DocumentMapper {
ret.setCreatedBy(documentEntity.getCreatedBy());
ret.setCreatedOn(DateConverter.toIsoString(documentEntity.getCreatedOn()));
ret.setIdentifier(documentEntity.getIdentifier());
+ ret.setDescription(documentEntity.getDescription());
return ret;
}
@@ -65,6 +66,7 @@ public class DocumentMapper {
ret.setCreatedBy(UserContextHolder.checkedGetUser());
ret.setCreatedOn(LocalDateTime.now(Clock.systemUTC()));
ret.setIdentifier(customerDocument.getIdentifier());
+ ret.setDescription(customerDocument.getDescription());
return ret;
}
}
diff --git a/service/src/main/java/io/mifos/customer/service/internal/repository/DocumentEntity.java b/service/src/main/java/io/mifos/customer/service/internal/repository/DocumentEntity.java
index ae2513f..60dbd26 100644
--- a/service/src/main/java/io/mifos/customer/service/internal/repository/DocumentEntity.java
+++ b/service/src/main/java/io/mifos/customer/service/internal/repository/DocumentEntity.java
@@ -37,9 +37,13 @@ public class DocumentEntity {
@JoinColumn(name = "customer_id")
private CustomerEntity customer;
- @Column(name = "identifier")
+ @Column(name = "identifier", nullable = false)
private String identifier;
+ @SuppressWarnings("DefaultAnnotationParam")
+ @Column(name = "description", nullable = true)
+ private String description;
+
@Column(name = "is_completed", nullable = false)
private Boolean completed;
@@ -77,6 +81,14 @@ public class DocumentEntity {
this.identifier = identifier;
}
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
public Boolean getCompleted() {
return completed;
}
diff --git a/service/src/main/resources/db/migrations/mariadb/V8__documents_description.sql b/service/src/main/resources/db/migrations/mariadb/V8__documents_description.sql
new file mode 100644
index 0000000..a9cd216
--- /dev/null
+++ b/service/src/main/resources/db/migrations/mariadb/V8__documents_description.sql
@@ -0,0 +1,17 @@
+--
+-- Copyright 2017 The Mifos Initiative.
+--
+-- Licensed 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.
+--
+
+ALTER TABLE maat_documents ADD description VARCHAR(4096) NULL;
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
myrle@apache.org.