BusinessObjectDataSearchHelper { void validateBusinessObjectDataSearchKey(BusinessObjectDataSearchKey businessObjectDataSearchKey) { Assert.notNull(businessObjectDataSearchKey, "A business object data search key must be specified."); businessObjectDataSearchKey.setNamespace(alternateKeyHelper.validateStringParameter("namespace", businessObjectDataSearchKey.getNamespace())); businessObjectDataSearchKey.setBusinessObjectDefinitionName( alternateKeyHelper.validateStringParameter("business object definition name", businessObjectDataSearchKey.getBusinessObjectDefinitionName())); if (businessObjectDataSearchKey.getBusinessObjectFormatUsage() != null) { businessObjectDataSearchKey.setBusinessObjectFormatUsage(businessObjectDataSearchKey.getBusinessObjectFormatUsage().trim()); } if (businessObjectDataSearchKey.getBusinessObjectFormatFileType() != null) { businessObjectDataSearchKey.setBusinessObjectFormatFileType(businessObjectDataSearchKey.getBusinessObjectFormatFileType().trim()); } if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getPartitionValueFilters())) { businessObjectDataHelper.validatePartitionValueFilters(businessObjectDataSearchKey.getPartitionValueFilters(), null, false); for (PartitionValueFilter partitionValueFilter : businessObjectDataSearchKey.getPartitionValueFilters()) { List<String> partitionValues = partitionValueFilter.getPartitionValues(); PartitionValueRange partitionValueRange = partitionValueFilter.getPartitionValueRange(); if (CollectionUtils.isEmpty(partitionValues) && partitionValueRange == null) { throw new IllegalArgumentException("Only partition values or partition range are supported in partition value filter."); } } } if (businessObjectDataSearchKey.getRegistrationDateRangeFilter() != null) { businessObjectDataHelper.validateRegistrationDateRangeFilter(businessObjectDataSearchKey.getRegistrationDateRangeFilter()); } if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getAttributeValueFilters())) { for (AttributeValueFilter attributeValueFilter : businessObjectDataSearchKey.getAttributeValueFilters()) { if (attributeValueFilter.getAttributeName() != null) { attributeValueFilter.setAttributeName(attributeValueFilter.getAttributeName().trim()); } if (StringUtils.isBlank(attributeValueFilter.getAttributeName()) && StringUtils.isEmpty(attributeValueFilter.getAttributeValue())) { throw new IllegalArgumentException("Either attribute name or attribute value filter must be specified."); } } } }  void validateBusinessObjectDataSearchRequest(BusinessObjectDataSearchRequest businessObjectDataSearchRequest); Integer validatePagingParameter(String parameterName, Integer parameterValue, Integer defaultParameterValue, Integer maxParameterValue);  }
@Test public void testValidateBusinessObjectDataSearchKey() throws Exception { XMLGregorianCalendar startRegistrationDate = DatatypeFactory.newInstance().newXMLGregorianCalendar("2018-04-01"); XMLGregorianCalendar endRegistrationDate = DatatypeFactory.newInstance().newXMLGregorianCalendar("2018-04-02"); RegistrationDateRangeFilter registrationDateRangeFilter = new RegistrationDateRangeFilter(startRegistrationDate, endRegistrationDate); List<AttributeValueFilter> attributeValueFilters = Arrays.asList(new AttributeValueFilter(ATTRIBUTE_NAME, ATTRIBUTE_VALUE), new AttributeValueFilter(ATTRIBUTE_NAME_2, ATTRIBUTE_VALUE_2)); BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, registrationDateRangeFilter, attributeValueFilters, FILTER_ON_LATEST_VALID_VERSION, FILTER_ON_RETENTION_EXPIRATION); BusinessObjectDataSearchKey originalBusinessObjectDataSearchKey = (BusinessObjectDataSearchKey) businessObjectDataSearchKey.clone(); businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey(businessObjectDataSearchKey); assertEquals(originalBusinessObjectDataSearchKey, businessObjectDataSearchKey); }
@Test public void testValidateBusinessObjectDataSearchKeyMissingOptionalParametersPassedAsNulls() { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, NO_FORMAT_USAGE_CODE, NO_FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, null, null)); businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, Arrays.asList(new AttributeValueFilter(ATTRIBUTE_NAME, null), new AttributeValueFilter(null, ATTRIBUTE_VALUE_2)), null, null)); }
@Test public void testValidateBusinessObjectDataSearchKeyMissingOptionalParametersPassedAsWhitespace() { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, BLANK_TEXT, BLANK_TEXT, NO_FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, null, null)); businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, Arrays.asList(new AttributeValueFilter(ATTRIBUTE_NAME, BLANK_TEXT), new AttributeValueFilter(BLANK_TEXT, ATTRIBUTE_VALUE_2)), null, null)); }
@Test public void testValidateBusinessObjectDataSearchKeyMissingRequiredParameters() { try { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey(null); fail(); } catch (IllegalArgumentException e) { assertEquals("A business object data search key must be specified.", e.getMessage()); } try { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BLANK_TEXT, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, NO_FILTER_ON_RETENTION_EXPIRATION)); fail(); } catch (IllegalArgumentException e) { assertEquals("A namespace must be specified.", e.getMessage()); } try { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BLANK_TEXT, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, NO_FILTER_ON_RETENTION_EXPIRATION)); fail(); } catch (IllegalArgumentException e) { assertEquals("A business object definition name must be specified.", e.getMessage()); } try { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Collections.singletonList( new PartitionValueFilter(PARTITION_KEY, NO_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, new LatestBeforePartitionValue(PARTITION_VALUE), NO_LATEST_AFTER_PARTITION_VALUE)), NO_REGISTRATION_DATE_RANGE_FILTER, NO_ATTRIBUTE_VALUE_FILTERS, NO_FILTER_ON_LATEST_VALID_VERSION, NO_FILTER_ON_RETENTION_EXPIRATION)); fail(); } catch (IllegalArgumentException e) { assertEquals("Only partition values or partition range are supported in partition value filter.", e.getMessage()); } try { businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, Collections.singletonList(new AttributeValueFilter(BLANK_TEXT, EMPTY_STRING)), NO_FILTER_ON_LATEST_VALID_VERSION, NO_FILTER_ON_RETENTION_EXPIRATION)); fail(); } catch (IllegalArgumentException e) { assertEquals("Either attribute name or attribute value filter must be specified.", e.getMessage()); } }
@Test public void testValidateBusinessObjectDataSearchKeyTrimParameters() throws Exception { List<AttributeValueFilter> attributeValueFilters = Arrays .asList(new AttributeValueFilter(addWhitespace(ATTRIBUTE_NAME), addWhitespace(ATTRIBUTE_VALUE)), new AttributeValueFilter(addWhitespace(ATTRIBUTE_NAME_2), addWhitespace(ATTRIBUTE_VALUE_2))); BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey(addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME), addWhitespace(FORMAT_USAGE_CODE), addWhitespace(FORMAT_FILE_TYPE_CODE), FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, attributeValueFilters, FILTER_ON_LATEST_VALID_VERSION, FILTER_ON_RETENTION_EXPIRATION); businessObjectDataSearchHelper.validateBusinessObjectDataSearchKey(businessObjectDataSearchKey); assertEquals( new BusinessObjectDataSearchKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NO_PARTITION_VALUE_FILTERS, NO_REGISTRATION_DATE_RANGE_FILTER, Arrays.asList(new AttributeValueFilter(ATTRIBUTE_NAME, addWhitespace(ATTRIBUTE_VALUE)), new AttributeValueFilter(ATTRIBUTE_NAME_2, addWhitespace(ATTRIBUTE_VALUE_2))), FILTER_ON_LATEST_VALID_VERSION, FILTER_ON_RETENTION_EXPIRATION), businessObjectDataSearchKey); }