/** * Gets the script arguments from the DelegateExecution, delimited and escaped as a list. * * @param execution the DelegateExecution * * @return script arguments */ protected List<String> getScriptArguments(DelegateExecution execution) { String scriptArgumentsString = activitiHelper.getExpressionVariableAsString(scriptArguments, execution); return daoHelper.splitStringWithDefaultDelimiterEscaped(scriptArgumentsString); }
/** * Gets the script arguments from the DelegateExecution, delimited and escaped as a list. * * @param execution the DelegateExecution * * @return script arguments */ protected List<String> getScriptArguments(DelegateExecution execution) { String scriptArgumentsString = activitiHelper.getExpressionVariableAsString(scriptArguments, execution); return daoHelper.splitStringWithDefaultDelimiterEscaped(scriptArgumentsString); }
@Test public void testSplitStringWithDefaultDelimiterEscapedInputIsNull() { List<String> splitString = herdStringHelper.splitStringWithDefaultDelimiterEscaped(null); assertTrue(splitString.size() == 0); }
@Test public void testSplitStringWithDefaultDelimiterEscapedInputIsEmptyString() { List<String> splitString = herdStringHelper.splitStringWithDefaultDelimiterEscaped(EMPTY_STRING); assertTrue(splitString.size() == 0); }
/** * Validates the given {@code servletRequest} and constructs a new {@link BusinessObjectDataKey}. The {@code servletRequest} validation involves validations * of request parameters which Spring MVC may not implement out-of-the-box. In our case, the request is asserted to no contain duplicate parameters. * * @param namespace the namespace * @param businessObjectDefinitionName the business object definition name * @param businessObjectFormatUsage the business object format usage * @param businessObjectFormatFileType the business object format type * @param businessObjectFormatVersion the business object format version * @param partitionValue the partition value * @param subPartitionValues the sub-partition values * @param businessObjectDataVersion the business object data version * @param servletRequest the servlet request * * @return a new {@link BusinessObjectDataKey} */ private BusinessObjectDataKey validateRequestAndCreateBusinessObjectDataKey(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, String subPartitionValues, Integer businessObjectDataVersion, ServletRequest servletRequest) { // Ensure there are no duplicate query string parameters. validateNoDuplicateQueryStringParams(servletRequest.getParameterMap(), "partitionKey", "partitionValue"); // Invoke the service. return new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, herdStringHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValues), businessObjectDataVersion); } }
/** * Validates the given {@code servletRequest} and constructs a new {@link BusinessObjectDataKey}. The {@code servletRequest} validation involves validations * of request parameters which Spring MVC may not implement out-of-the-box. In our case, the request is asserted to no contain duplicate parameters. * * @param namespace the namespace * @param businessObjectDefinitionName the business object definition name * @param businessObjectFormatUsage the business object format usage * @param businessObjectFormatFileType the business object format type * @param businessObjectFormatVersion the business object format version * @param partitionValue the partition value * @param subPartitionValues the sub-partition values * @param businessObjectDataVersion the business object data version * @param servletRequest the servlet request * * @return a new {@link BusinessObjectDataKey} */ private BusinessObjectDataKey validateRequestAndCreateBusinessObjectDataKey(String namespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String partitionValue, String subPartitionValues, Integer businessObjectDataVersion, ServletRequest servletRequest) { // Ensure there are no duplicate query string parameters. validateNoDuplicateQueryStringParams(servletRequest.getParameterMap(), "partitionKey", "partitionValue"); // Invoke the service. return new BusinessObjectDataKey(namespace, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, partitionValue, herdStringHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValues), businessObjectDataVersion); } }
@Test public void testSplitStringWithDefaultDelimiterEscaped() { String value1 = "arg1"; String value2 = "arg2\\|escaped"; String value2Escaped = "arg2|escaped"; String delimiter = configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER); String delimitedString = value1 + delimiter + value2; List<String> splitString = herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedString); assertTrue(splitString.get(0).equals(value1)); assertTrue(splitString.get(1).equals(value2Escaped)); }
@Test public void testGetBusinessObjectDataStatusMissingOptionalParametersPassedAsNulls() { // Create a business object data status information. BusinessObjectDataStatusInformation businessObjectDataStatusInformation = new BusinessObjectDataStatusInformation(); // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null, PARTITION_VALUE, new ArrayList<>(), null); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(null)).thenReturn(new ArrayList<>()); when(businessObjectDataStatusService.getBusinessObjectDataStatus(businessObjectDataKey, null)).thenReturn(businessObjectDataStatusInformation); // Call the method under test. BusinessObjectDataStatusInformation result = businessObjectDataStatusRestController .getBusinessObjectDataStatus(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null, PARTITION_VALUE, null, null, null); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(null); verify(businessObjectDataStatusService).getBusinessObjectDataStatus(businessObjectDataKey, null); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectDataStatusInformation, result); }
@Test public void testGetBusinessObjectDataStatus() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a business object data status information. BusinessObjectDataStatusInformation businessObjectDataStatusInformation = new BusinessObjectDataStatusInformation(businessObjectDataKey, BDATA_STATUS); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(businessObjectDataStatusService.getBusinessObjectDataStatus(businessObjectDataKey, PARTITION_KEY)).thenReturn(businessObjectDataStatusInformation); // Call the method under test. BusinessObjectDataStatusInformation result = businessObjectDataStatusRestController .getBusinessObjectDataStatus(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, PARTITION_VALUE, delimitedSubPartitionValues, FORMAT_VERSION, DATA_VERSION); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(businessObjectDataStatusService).getBusinessObjectDataStatus(businessObjectDataKey, PARTITION_KEY); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectDataStatusInformation, result); }
@Test public void testRestoreBusinessObjectData() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a business object data. BusinessObjectData businessObjectData = new BusinessObjectData(); businessObjectData.setId(ID); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(businessObjectDataService.restoreBusinessObjectData(businessObjectDataKey, EXPIRATION_IN_DAYS)).thenReturn(businessObjectData); // Call the method under test. BusinessObjectData result = businessObjectDataRestController .restoreBusinessObjectData(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, delimitedSubPartitionValues, EXPIRATION_IN_DAYS); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(businessObjectDataService).restoreBusinessObjectData(businessObjectDataKey, EXPIRATION_IN_DAYS); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectData, result); }
@Test public void testGetBusinessObjectDataVersions() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a list of business object data versions. BusinessObjectDataVersions businessObjectDataVersions = new BusinessObjectDataVersions(Arrays.asList(new BusinessObjectDataVersion())); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(businessObjectDataService.getBusinessObjectDataVersions(businessObjectDataKey)).thenReturn(businessObjectDataVersions); // Call the method under test. BusinessObjectDataVersions result = businessObjectDataRestController .getBusinessObjectDataVersions(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_VALUE, delimitedSubPartitionValues, FORMAT_VERSION, DATA_VERSION); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(businessObjectDataService).getBusinessObjectDataVersions(businessObjectDataKey); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectDataVersions, result); }
@Test public void testGetBusinessObjectData() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a business object data. BusinessObjectData businessObjectData = new BusinessObjectData(); businessObjectData.setId(ID); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(businessObjectDataService.getBusinessObjectData(businessObjectDataKey, PARTITION_KEY, BDATA_STATUS, INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY)).thenReturn(businessObjectData); // Call the method under test. BusinessObjectData result = businessObjectDataRestController .getBusinessObjectData(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, PARTITION_KEY, PARTITION_VALUE, delimitedSubPartitionValues, FORMAT_VERSION, DATA_VERSION, BDATA_STATUS, INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(businessObjectDataService).getBusinessObjectData(businessObjectDataKey, PARTITION_KEY, BDATA_STATUS, INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectData, result); }
@Test public void testDestroyBusinessObjectData() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a business object data. BusinessObjectData businessObjectData = new BusinessObjectData(); businessObjectData.setId(ID); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(businessObjectDataService.destroyBusinessObjectData(businessObjectDataKey)).thenReturn(businessObjectData); // Call the method under test. BusinessObjectData result = businessObjectDataRestController .destroyBusinessObjectData(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, delimitedSubPartitionValues); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(businessObjectDataService).destroyBusinessObjectData(businessObjectDataKey); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectData, result); }
@Test public void testGetBusinessObjectDataUploadCredential() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create an AWS credential. AwsCredential awsCredential = new AwsCredential(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME); // Create a storage unit download credential. StorageUnitUploadCredential storageUnitUploadCredential = new StorageUnitUploadCredential(awsCredential, AWS_KMS_KEY_ID); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(storageUnitService.getStorageUnitUploadCredential(businessObjectDataKey, CREATE_NEW_VERSION, STORAGE_NAME)) .thenReturn(storageUnitUploadCredential); // Call the method under test. BusinessObjectDataUploadCredential result = businessObjectDataRestController .getBusinessObjectDataUploadCredential(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, CREATE_NEW_VERSION, STORAGE_NAME, delimitedSubPartitionValues); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(storageUnitService).getStorageUnitUploadCredential(businessObjectDataKey, CREATE_NEW_VERSION, STORAGE_NAME); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(new BusinessObjectDataUploadCredential(awsCredential, AWS_KMS_KEY_ID), result); }
@Test public void getStorageUnitDownloadCredential() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a storage unit download credential. StorageUnitDownloadCredential storageUnitDownloadCredential = new StorageUnitDownloadCredential( new AwsCredential(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME)); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(storageUnitService.getStorageUnitDownloadCredential(businessObjectDataKey, STORAGE_NAME)).thenReturn(storageUnitDownloadCredential); // Call the method under test. StorageUnitDownloadCredential result = storageUnitRestController .getStorageUnitDownloadCredential(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, STORAGE_NAME, delimitedSubPartitionValues); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(storageUnitService).getStorageUnitDownloadCredential(businessObjectDataKey, STORAGE_NAME); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(storageUnitDownloadCredential, result); }
@Test public void getStorageUnitUploadCredential() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a delimited list of sub-partition values. String delimitedSubPartitionValues = String.join("|", SUBPARTITION_VALUES); // Create a storage unit upload credential. StorageUnitUploadCredential storageUnitUploadCredential = new StorageUnitUploadCredential( new AwsCredential(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME), AWS_KMS_KEY_ID); // Mock the external calls. when(herdStringHelper.splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues)).thenReturn(SUBPARTITION_VALUES); when(storageUnitService.getStorageUnitUploadCredential(businessObjectDataKey, null, STORAGE_NAME)).thenReturn(storageUnitUploadCredential); // Call the method under test. StorageUnitUploadCredential result = storageUnitRestController .getStorageUnitUploadCredential(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, DATA_VERSION, STORAGE_NAME, delimitedSubPartitionValues); // Verify the external calls. verify(herdStringHelper).splitStringWithDefaultDelimiterEscaped(delimitedSubPartitionValues); verify(storageUnitService).getStorageUnitUploadCredential(businessObjectDataKey, null, STORAGE_NAME); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(storageUnitUploadCredential, result); }
String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution); String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution); List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString); Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);
String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution); String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution); List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString); Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);
String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution); String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution); List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString); Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);
String partitionValue = activitiHelper.getExpressionVariableAsString(this.partitionValue, execution); String subPartitionValuesString = activitiHelper.getExpressionVariableAsString(this.subPartitionValues, execution); List<String> subPartitionValues = daoHelper.splitStringWithDefaultDelimiterEscaped(subPartitionValuesString); Integer businessObjectDataVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectDataVersion, execution, "businessObjectDataVersion", false);