HerdApiClientOperations { void checkPropertiesFile(PropertiesHelper propertiesHelper, Boolean messageFlag) throws ApiException { List<String> requiredProperties = Arrays.asList(HERD_BASE_URL_PROPERTY, HERD_USERNAME_PROPERTY, HERD_PASSWORD_PROPERTY, AWS_ROLE_ARN_PROPERTY, AWS_REGION_PROPERTY); Boolean missingProperty = false; StringBuilder errorMessage = new StringBuilder(); for (String property : requiredProperties) { if (propertiesHelper.isBlankOrNull(property)) { missingProperty = true; errorMessage.append(property); errorMessage.append('\n'); } } if (messageFlag) { if (propertiesHelper.isBlankOrNull(AWS_SQS_QUEUE_URL_PROPERTY)) { missingProperty = true; errorMessage.append(AWS_SQS_QUEUE_URL_PROPERTY); errorMessage.append('\n'); } } else { requiredProperties = Arrays.asList(NAMESPACE_PROPERTY, BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY, BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY, BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY, PRIMARY_PARTITION_VALUE_PROPERTY); for (String property : requiredProperties) { if (propertiesHelper.isBlankOrNull(property)) { missingProperty = true; errorMessage.append(property); errorMessage.append('\n'); } } } if (missingProperty) { throw new ApiException("The following properties are missing. Please double check case and spelling:\n" + errorMessage.toString()); } }    }
@Test public void testMissingProperties() throws Exception { String errorMessage = ""; List<String> requiredProperties = Arrays .asList(HERD_BASE_URL_PROPERTY, HERD_USERNAME_PROPERTY, HERD_PASSWORD_PROPERTY, AWS_ROLE_ARN_PROPERTY, AWS_REGION_PROPERTY, NAMESPACE_PROPERTY, BUSINESS_OBJECT_DEFINITION_NAME_PROPERTY, BUSINESS_OBJECT_FORMAT_USAGE_PROPERTY, BUSINESS_OBJECT_FORMAT_FILE_TYPE_PROPERTY, PRIMARY_PARTITION_VALUE_PROPERTY); for (String property : requiredProperties) { when(propertiesHelper.isBlankOrNull(property)).thenReturn(true); } try { herdApiClientOperations.checkPropertiesFile(propertiesHelper, false); } catch (ApiException e) { errorMessage = e.getMessage(); } System.out.println(errorMessage); for (String property : requiredProperties) { Assert.assertTrue("Could not find error for " + property, StringUtils.contains(errorMessage, property)); } for (String property : requiredProperties) { verify(propertiesHelper).isBlankOrNull(property); } verifyNoMoreInteractionsHelper(); }
@Test public void testMissingPropertiesSqs() throws Exception { String errorMessage = ""; List<String> requiredProperties = Arrays.asList(HERD_BASE_URL_PROPERTY, HERD_USERNAME_PROPERTY, HERD_PASSWORD_PROPERTY, AWS_ROLE_ARN_PROPERTY, AWS_REGION_PROPERTY); for (String property : requiredProperties) { when(propertiesHelper.isBlankOrNull(property)).thenReturn(false); } try { when(propertiesHelper.isBlankOrNull(AWS_SQS_QUEUE_URL_PROPERTY)).thenReturn(true); herdApiClientOperations.checkPropertiesFile(propertiesHelper, true); } catch (ApiException e) { errorMessage = e.getMessage(); } System.out.println(errorMessage); for (String property : requiredProperties) { Assert.assertFalse("Unexpected error for " + property, StringUtils.contains(errorMessage, property)); } Assert.assertTrue("Could not find error for " + AWS_SQS_QUEUE_URL_PROPERTY, StringUtils.contains(errorMessage, AWS_SQS_QUEUE_URL_PROPERTY)); for (String property : requiredProperties) { verify(propertiesHelper).isBlankOrNull(property); } verify(propertiesHelper).isBlankOrNull(AWS_SQS_QUEUE_URL_PROPERTY); verifyNoMoreInteractionsHelper(); }