src/test/java/za/co/grindrodbank/dokuti/document/DocumentServiceUnitTests.java
@Test(expected = InvalidRequestException.class)
	public void givenDocumentAttributeWithIncorrectContractExpiryDateValue_thenInvalidRequestExceptionThrown() {
		UUID documentVersionId = UUID.randomUUID();
		UUID userId = UUID.randomUUID();

		DocumentVersionEntity documentVersionMock = new DocumentVersionEntity();
		documentVersionMock.setId(documentVersionId);

		AttributeEntity attributeEntityMock = new AttributeEntity();
		attributeEntityMock.setId((short) 1);
		attributeEntityMock.setName("Test Attribute Name");
		attributeEntityMock.setValidationRegex(
				"(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)");
		attributeEntityMock.setUpdatedBy(userId);

		Mockito.when(documentVersionRepository.save(any(DocumentVersionEntity.class))).thenReturn(documentVersionMock);

		PowerMockito.mockStatic(SecurityContextUtility.class);
		Mockito.when(SecurityContextUtility.getUserIdFromJwt()).thenReturn(userId.toString());

		String documentAttributeValue = "test attribute value";

		documentVersionServiceImpl.addDocumentAttribute(documentVersionMock,
				attributeEntityMock, documentAttributeValue);
	}
/**
	 * Tests sending through invalid values for an attribute that has a 'Contract
	 * Expiry' validation regex, when creating a document attribute. Tests that the
	 * anticipated exception is thrown.
	 */
Tests sending through invalid values for an attribute that has a 'Contract
Expiry' validation regex, when creating a document attribute. Tests that the
anticipated exception is thrown.
Tests sending through invalid values for an attribute that has a ' Contract Expiry ' validation regex when creating a document attribute . Tests that the anticipated exception is thrown .
@Test(expected = InvalidRequestException.class)
	public void givenDocumentAttributeWithIncorrectContractExpiryDateValue_thenInvalidRequestExceptionThrown() {
		UUID documentVersionId = UUID.randomUUID();
		UUID userId = UUID.randomUUID();
		DocumentVersionEntity documentVersionMock = new DocumentVersionEntity();
		documentVersionMock.setId(documentVersionId);
		AttributeEntity attributeEntityMock = new AttributeEntity();
		attributeEntityMock.setId((short) 1);
		attributeEntityMock.setName("Test Attribute Name");
		attributeEntityMock.setValidationRegex(
				"(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)");
		attributeEntityMock.setUpdatedBy(userId);
		Mockito.when(documentVersionRepository.save(any(DocumentVersionEntity.class))).thenReturn(documentVersionMock);
		PowerMockito.mockStatic(SecurityContextUtility.class);
		Mockito.when(SecurityContextUtility.getUserIdFromJwt()).thenReturn(userId.toString());
		String documentAttributeValue = "test attribute value";
		documentVersionServiceImpl.addDocumentAttribute(documentVersionMock,
				attributeEntityMock, documentAttributeValue);
	}
@ Test ( expected = InvalidRequestException . class ) public void givenDocumentAttributeWithIncorrectContractExpiryDateValue_thenInvalidRequestExceptionThrown ( ) { UUID documentVersionId = UUID . randomUUID ( ) ; UUID userId = UUID . randomUUID ( ) ; DocumentVersionEntity documentVersionMock = new DocumentVersionEntity ( ) ; documentVersionMock . setId ( documentVersionId ) ; AttributeEntity attributeEntityMock = new AttributeEntity ( ) ; attributeEntityMock . setId ( ( short ) 1 ) ; attributeEntityMock . setName ( "Test Attribute Name" ) ; attributeEntityMock . setValidationRegex ( "(^(((0[1-9]|1[0-9]|2[0-8])[\\/](0[1-9]|1[012]))|((29|30|31)[\\/](0[13578]|1[02]))|((29|30)[\\/](0[4,6,9]|11)))[\\/](19|[2-9][0-9])\\d\\d$)|(^29[\\/]02[\\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)" ) ; attributeEntityMock . setUpdatedBy ( userId ) ; Mockito . when ( documentVersionRepository . save ( any ( DocumentVersionEntity . class ) ) ) . thenReturn ( documentVersionMock ) ; PowerMockito . mockStatic ( SecurityContextUtility . class ) ; Mockito . when ( SecurityContextUtility . getUserIdFromJwt ( ) ) . thenReturn ( userId . toString ( ) ) ; String documentAttributeValue = "test attribute value" ; documentVersionServiceImpl . addDocumentAttribute ( documentVersionMock , attributeEntityMock , documentAttributeValue ) ; }
Tests sending through invalid values for an attribute that has a 'Contract
 Expiry' validation regex, when creating a document attribute.
Tests sending through invalid values for an attribute that has a ' Contract Expiry ' validation regex when creating a document attribute .