@Test public void test_should_not_throw_exception_when_mandatory_attribute_entries_are_present_in_service_request() { final MandatoryAttributeValidator validator = new MandatoryAttributeValidator(); final ServiceRequest serviceRequest = mock(ServiceRequest.class); when(serviceRequest.getAttributeEntries()) .thenReturn(Arrays.asList( new AttributeEntry("code1", "value1"), new AttributeEntry("code2", "value2"), new AttributeEntry("code2", "value3"), new AttributeEntry("code3", "value4") )); final AuthenticatedUser user = AuthenticatedUser.builder() .roleCodes(Collections.singletonList("CITIZEN")) .build(); when(serviceRequest.getAuthenticatedUser()).thenReturn(user); final AttributeDefinition attributeDefinition1 = AttributeDefinition.builder() .required(true) .code("code1") .roles(Collections.singletonList(new AttributeRolesDefinition("CITIZEN"))) .actions(Collections.singletonList(new AttributeActionsDefinition(ServiceStatus.COMPLAINT_REGISTERED))) .build(); final AttributeDefinition attributeDefinition2 = AttributeDefinition.builder() .required(true) .code("code2") .roles(Collections.singletonList(new AttributeRolesDefinition("CITIZEN"))) .actions(Collections.singletonList(new AttributeActionsDefinition(ServiceStatus.COMPLAINT_REGISTERED))) .build(); final List<AttributeDefinition> attributeDefinitions = Arrays.asList(attributeDefinition1, attributeDefinition2); final ServiceDefinition serviceDefinition = ServiceDefinition.builder() .attributes(attributeDefinitions) .build(); validator.validate(serviceRequest, serviceDefinition, ServiceStatus.COMPLAINT_REGISTERED); }
@Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> mandatoryAttributes = serviceDefinition.getMandatoryAttributes(action, serviceRequest.getAuthenticatedUser().getRoleCodes()); if (CollectionUtils.isEmpty(mandatoryAttributes)) { return; } final Set<String> mandatoryAttributeCodes = getMissingMandatoryAttributeCodes(serviceRequest, mandatoryAttributes); if (isNotEmpty(mandatoryAttributeCodes)) { throw new MandatoryAttributesAbsentException(mandatoryAttributeCodes); } }
MandatoryAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> mandatoryAttributes = serviceDefinition.getMandatoryAttributes(action, serviceRequest.getAuthenticatedUser().getRoleCodes()); if (CollectionUtils.isEmpty(mandatoryAttributes)) { return; } final Set<String> mandatoryAttributeCodes = getMissingMandatoryAttributeCodes(serviceRequest, mandatoryAttributes); if (isNotEmpty(mandatoryAttributeCodes)) { throw new MandatoryAttributesAbsentException(mandatoryAttributeCodes); } } }
MandatoryAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> mandatoryAttributes = serviceDefinition.getMandatoryAttributes(action, serviceRequest.getAuthenticatedUser().getRoleCodes()); if (CollectionUtils.isEmpty(mandatoryAttributes)) { return; } final Set<String> mandatoryAttributeCodes = getMissingMandatoryAttributeCodes(serviceRequest, mandatoryAttributes); if (isNotEmpty(mandatoryAttributeCodes)) { throw new MandatoryAttributesAbsentException(mandatoryAttributeCodes); } }  }
MandatoryAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> mandatoryAttributes = serviceDefinition.getMandatoryAttributes(action, serviceRequest.getAuthenticatedUser().getRoleCodes()); if (CollectionUtils.isEmpty(mandatoryAttributes)) { return; } final Set<String> mandatoryAttributeCodes = getMissingMandatoryAttributeCodes(serviceRequest, mandatoryAttributes); if (isNotEmpty(mandatoryAttributeCodes)) { throw new MandatoryAttributesAbsentException(mandatoryAttributeCodes); } }  @Override void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action); }
MandatoryAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> mandatoryAttributes = serviceDefinition.getMandatoryAttributes(action, serviceRequest.getAuthenticatedUser().getRoleCodes()); if (CollectionUtils.isEmpty(mandatoryAttributes)) { return; } final Set<String> mandatoryAttributeCodes = getMissingMandatoryAttributeCodes(serviceRequest, mandatoryAttributes); if (isNotEmpty(mandatoryAttributeCodes)) { throw new MandatoryAttributesAbsentException(mandatoryAttributeCodes); } }  @Override void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action);  }