Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIAC-542 adding document tags and updating functional tests #2293

Merged
merged 15 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void scenarios_should_behave_as_specified() throws IOException {

if (!((Boolean) scenarioEnabled) || ((Boolean) scenarioDisabled)) {
log.info((char) 27 + "\033[31m" + "SCENARIO: " + description + " **disabled**");
continue;
break;
}

log.info((char) 27 + "\033[33m" + "SCENARIO: " + description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "hearingNotice"
"tag": "hearingNoticeRelisted"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "hearingNotice"
"tag": "hearingNoticeRelisted"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
},
"description": "",
"dateUploaded": "{$TODAY}",
"tag": "hearingNotice"
"tag": "hearingNoticeRelisted"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public enum DocumentTag {
ADDITIONAL_EVIDENCE("additionalEvidence"),
REHEARD_HEARING_NOTICE("reheardHearingNotice"),
HEARING_NOTICE("hearingNotice"),
REHEARD_HEARING_NOTICE_LISTED("reheardHearingNoticeRelisted"),
HEARING_NOTICE_LISTED("hearingNoticeRelisted"),
HEARING_REQUIREMENTS("hearingRequirements"),
CASE_SUMMARY("caseSummary"),
HEARING_BUNDLE("hearingBundle"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static java.util.Objects.requireNonNull;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.Document;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.HasDocument;
Expand All @@ -12,11 +14,17 @@
public class DocumentWithMetadata implements HasDocument {

private Document document;
@Getter
private String description;
private String dateUploaded;
private DocumentTag tag;
@Getter
private String suppliedBy;
@Getter
private String uploadedBy;
@Setter
@Getter
private String dateTimeUploaded;

private DocumentWithMetadata() {
// noop -- for deserializer
Expand All @@ -38,7 +46,18 @@ public DocumentWithMetadata(
DocumentTag tag,
String suppliedBy
) {
this(document, description, dateUploaded, tag, suppliedBy, null);
this(document, description, dateUploaded, tag, suppliedBy, null, null);
}

public DocumentWithMetadata(
Document document,
String description,
String dateUploaded,
DocumentTag tag,
String suppliedBy,
String uploadedBy
) {
this(document, description, dateUploaded, tag, suppliedBy, uploadedBy, null);
}

public DocumentWithMetadata(
Expand All @@ -47,14 +66,16 @@ public DocumentWithMetadata(
String dateUploaded,
DocumentTag tag,
String suppliedBy,
String uploadedBy
String uploadedBy,
String dateTimeUploaded
) {
this.document = document;
this.description = description;
this.dateUploaded = dateUploaded;
this.tag = tag;
this.suppliedBy = suppliedBy;
this.uploadedBy = uploadedBy;
this.dateTimeUploaded = dateTimeUploaded;
}

@Override
Expand All @@ -63,10 +84,6 @@ public Document getDocument() {
return document;
}

public String getDescription() {
return description;
}

public String getDateUploaded() {
requireNonNull(dateUploaded);
return dateUploaded;
Expand All @@ -76,12 +93,4 @@ public DocumentTag getTag() {
requireNonNull(tag);
return tag;
}

public String getSuppliedBy() {
return suppliedBy;
}

public String getUploadedBy() {
return uploadedBy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ void has_correct_values() {
assertEquals("additionalEvidence", DocumentTag.ADDITIONAL_EVIDENCE.toString());
assertEquals("reheardHearingNotice", DocumentTag.REHEARD_HEARING_NOTICE.toString());
assertEquals("hearingNotice", DocumentTag.HEARING_NOTICE.toString());
assertEquals("reheardHearingNoticeRelisted", DocumentTag.REHEARD_HEARING_NOTICE_LISTED.toString());
assertEquals("hearingNoticeRelisted", DocumentTag.HEARING_NOTICE_LISTED.toString());
assertEquals("hearingRequirements", DocumentTag.HEARING_REQUIREMENTS.toString());
assertEquals("caseSummary", DocumentTag.CASE_SUMMARY.toString());
assertEquals("hearingBundle", DocumentTag.HEARING_BUNDLE.toString());
Expand Down Expand Up @@ -50,6 +52,6 @@ void has_correct_values() {

@Test
void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
assertEquals(40, DocumentTag.values().length);
assertEquals(42, DocumentTag.values().length);
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,133 @@
package uk.gov.hmcts.reform.iacaseapi.domain.entities;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.Document;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

class DocumentWithMetadataTest {

private final Document document = mock(Document.class);
private final String description = "Some evidence";
private final String dateUploaded = "2018-12-25";
private final DocumentTag tag = DocumentTag.CASE_ARGUMENT;

private DocumentWithMetadata documentWithMetadata =
new DocumentWithMetadata(
document,
description,
dateUploaded,
tag
private Document document;
private String description;
private String dateUploaded;
private DocumentTag tag;
private String suppliedBy;
private String uploadedBy;
private String timeUploaded;

@BeforeEach
void setUp() {
document = mock(Document.class);
description = "Test Description";
dateUploaded = "2024-08-20";
tag = DocumentTag.CASE_SUMMARY;
suppliedBy = "Test Supplier";
uploadedBy = "Test Uploader";
timeUploaded = "10:00 AM";
}

@Test
void should_create_document_with_metadata_full_constructor() {
DocumentWithMetadata documentWithMetadata = new DocumentWithMetadata(
document, description, dateUploaded, tag, suppliedBy, uploadedBy, timeUploaded
);

assertEquals(document, documentWithMetadata.getDocument());
assertEquals(description, documentWithMetadata.getDescription());
assertEquals(dateUploaded, documentWithMetadata.getDateUploaded());
assertEquals(tag, documentWithMetadata.getTag());
assertEquals(suppliedBy, documentWithMetadata.getSuppliedBy());
assertEquals(uploadedBy, documentWithMetadata.getUploadedBy());
assertEquals(timeUploaded, documentWithMetadata.getDateTimeUploaded());
}

@Test
void should_hold_onto_values() {
void should_create_document_with_metadata_without_suppliedBy_and_uploadedBy() {
DocumentWithMetadata documentWithMetadata = new DocumentWithMetadata(
document, description, dateUploaded, tag
);

assertEquals(document, documentWithMetadata.getDocument());
assertEquals(description, documentWithMetadata.getDescription());
assertEquals(dateUploaded, documentWithMetadata.getDateUploaded());
assertEquals(tag, documentWithMetadata.getTag());
assertNull(documentWithMetadata.getSuppliedBy());
assertNull(documentWithMetadata.getUploadedBy());
assertNull(documentWithMetadata.getDateTimeUploaded());
}

@Test
void should_throw_exception_when_document_is_null() {
DocumentWithMetadata nullDocument = new DocumentWithMetadata(null, description, dateUploaded, tag);
assertThrows(NullPointerException.class, nullDocument::getDocument);
}

@Test
void should_throw_exception_when_dateUploaded_is_null() {
DocumentWithMetadata nullDate = new DocumentWithMetadata(document, description, null, tag);
assertThrows(NullPointerException.class, nullDate::getDateUploaded);
}

@Test
void should_throw_exception_when_tag_is_null() {
DocumentWithMetadata nullTag = new DocumentWithMetadata(document, description, dateUploaded, null);
assertThrows(NullPointerException.class, nullTag::getTag);
}

@Test
void should_return_correct_getters() {
DocumentWithMetadata documentWithMetadata = new DocumentWithMetadata(
document, description, dateUploaded, tag, suppliedBy, uploadedBy, timeUploaded
);

assertNotNull(documentWithMetadata.getDocument());
assertEquals(description, documentWithMetadata.getDescription());
assertEquals(dateUploaded, documentWithMetadata.getDateUploaded());
assertEquals(tag, documentWithMetadata.getTag());
assertEquals(suppliedBy, documentWithMetadata.getSuppliedBy());
assertEquals(uploadedBy, documentWithMetadata.getUploadedBy());
assertEquals(timeUploaded, documentWithMetadata.getDateTimeUploaded());
}

@Test
void should_handle_null_values_correctly() {
DocumentWithMetadata documentWithMetadata = new DocumentWithMetadata(
document, description, dateUploaded, tag, null, null, null
);

assertNull(documentWithMetadata.getSuppliedBy());
assertNull(documentWithMetadata.getUploadedBy());
assertNull(documentWithMetadata.getDateTimeUploaded());
}

@Test
void should_provide_string_representation() {
DocumentWithMetadata documentWithMetadata = new DocumentWithMetadata(
document, description, dateUploaded, tag, suppliedBy, uploadedBy, timeUploaded
);

String stringRepresentation = documentWithMetadata.toString();
assertTrue(stringRepresentation.contains("document="));
assertTrue(stringRepresentation.contains("description="));
assertTrue(stringRepresentation.contains("dateUploaded="));
assertTrue(stringRepresentation.contains("tag="));
assertTrue(stringRepresentation.contains("suppliedBy="));
assertTrue(stringRepresentation.contains("uploadedBy="));
}

@Test
void should_return_correct_equals_and_hashcode() {
DocumentWithMetadata documentWithMetadata1 = new DocumentWithMetadata(
document, description, dateUploaded, tag, suppliedBy, uploadedBy, timeUploaded
);

DocumentWithMetadata documentWithMetadata2 = new DocumentWithMetadata(
document, description, dateUploaded, tag, suppliedBy, uploadedBy, timeUploaded
);

assertEquals(documentWithMetadata1, documentWithMetadata2);
assertEquals(documentWithMetadata1.hashCode(), documentWithMetadata2.hashCode());
}
}
Loading