@Override public void execute() { // Create the business object data which is invalid. businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); } });
@Test public void testCreateBusinessObjectDataNoAttributes() { // Create business object data with no attribute definitions and no attributes which is valid. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(false); businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); }
@Test public void testCreateBusinessObjectData() { // Create an initial version of the business object data. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); // Verify the results. businessObjectDataServiceTestHelper.validateBusinessObjectData(businessObjectDataCreateRequest, INITIAL_DATA_VERSION, true, resultBusinessObjectData); }
@Test(expected = ObjectNotFoundException.class) public void testCreateBusinessObjectDataParentNoExists() { // This will create a business object data create request with parents. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(true); // Set the partition value to a business object data that doesn't exist. List<BusinessObjectDataKey> businessObjectDataKeys = businessObjectDataCreateRequest.getBusinessObjectDataParents(); businessObjectDataKeys.get(0).setPartitionValue("Invalid_Partition_Value"); // Create the business object data which should fail since required attributes are missing. businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); }
@Test(expected = IllegalArgumentException.class) public void testCreateBusinessObjectDataMissingRequiredAttribute() { // This will create a business object data create request with attributes. It will be associated with a format that has attribute definitions // that require the attribute to be specified. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(true); // Null out the attributes in the create request, even though the format requires them. businessObjectDataCreateRequest.setAttributes(null); // Create the business object data which should fail since required attributes are missing. businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); }
@Override public void executeImpl(DelegateExecution execution) throws Exception { String contentTypeString = activitiHelper.getRequiredExpressionVariableAsString(contentType, execution, "ContentType").trim(); String requestString = activitiHelper.getRequiredExpressionVariableAsString(businessObjectDataCreateRequest, execution, "BusinessObjectDataCreateRequest").trim(); BusinessObjectDataCreateRequest request = getRequestObject(contentTypeString, requestString, BusinessObjectDataCreateRequest.class); // Register the data. BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(request); // Trigger notifications. businessObjectDataDaoHelper.triggerNotificationsForCreateBusinessObjectData(businessObjectData); // Set the JSON response as a workflow variable. setJsonResponseAsWorkflowVariable(businessObjectData, execution); setTaskWorkflowVariable(execution, VARIABLE_ID, businessObjectData.getId()); setTaskWorkflowVariable(execution, VARIABLE_VERSION, businessObjectData.getVersion()); setTaskWorkflowVariable(execution, VARIABLE_LATEST_VERSION, businessObjectData.isLatestVersion()); } }
@Override public void executeImpl(DelegateExecution execution) throws Exception { String contentTypeString = activitiHelper.getRequiredExpressionVariableAsString(contentType, execution, "ContentType").trim(); String requestString = activitiHelper.getRequiredExpressionVariableAsString(businessObjectDataCreateRequest, execution, "BusinessObjectDataCreateRequest").trim(); BusinessObjectDataCreateRequest request = getRequestObject(contentTypeString, requestString, BusinessObjectDataCreateRequest.class); // Register the data. BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(request); // Trigger notifications. businessObjectDataDaoHelper.triggerNotificationsForCreateBusinessObjectData(businessObjectData); // Set the JSON response as a workflow variable. setJsonResponseAsWorkflowVariable(businessObjectData, execution); setTaskWorkflowVariable(execution, VARIABLE_ID, businessObjectData.getId()); setTaskWorkflowVariable(execution, VARIABLE_VERSION, businessObjectData.getVersion()); setTaskWorkflowVariable(execution, VARIABLE_LATEST_VERSION, businessObjectData.isLatestVersion()); } }
@Test public void testCreateBusinessObjectData() { // Create a business object data create request. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = new BusinessObjectDataCreateRequest(); // Create a business object data. BusinessObjectData businessObjectData = new BusinessObjectData(); businessObjectData.setId(ID); // Mock the external calls. when(businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest)).thenReturn(businessObjectData); // Call the method under test. BusinessObjectData result = businessObjectDataRestController.createBusinessObjectData(businessObjectDataCreateRequest); // Verify the external calls. verify(businessObjectDataService).createBusinessObjectData(businessObjectDataCreateRequest); verify(businessObjectDataDaoHelper).triggerNotificationsForCreateBusinessObjectData(businessObjectData); verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(businessObjectData, result); }
@Test public void testCreateBusinessObjectDataDuplicateParents() { // This will create a business object data create request with parents. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(true); // Add a duplicate parent. List<BusinessObjectDataKey> businessObjectDataKeys = businessObjectDataCreateRequest.getBusinessObjectDataParents(); businessObjectDataKeys.add(businessObjectDataKeys.get(0)); // Try to create a business object data with duplicate parents. try { businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); fail("Should throw an IllegalArgumentException when business object data create request contains duplicate parents."); } catch (IllegalArgumentException e) { assertEquals("Business object data keys can not contain duplicates.", e.getMessage()); } }
@Test public void testCreateBusinessObjectDataNoStorageDirectory() { // Create an initial version of the business object data without specifying a storage directory. BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); request.getStorageUnits().get(0).setStorageDirectory(null); BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request); // Verify the results. businessObjectDataServiceTestHelper.validateBusinessObjectData(request, INITIAL_DATA_VERSION, true, resultBusinessObjectData); }
@Test public void testCreateBusinessObjectDataNoStorageFiles() { // Create the initial version of the business object data without specifying storage files. BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); request.getStorageUnits().get(0).setStorageFiles(null); BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request); // Verify the results. businessObjectDataServiceTestHelper.validateBusinessObjectData(request, INITIAL_DATA_VERSION, true, resultBusinessObjectData); }
@Test public void testCreateBusinessObjectDataPreRegistrationAssertCannotCreateNewVersionWhenLatestIsPreRegistrationStatus() { // Create an initial version of the business object data. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); businessObjectDataCreateRequest.setStatus("UPLOADING"); businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); businessObjectDataCreateRequest.setCreateNewVersion(true); businessObjectDataCreateRequest.setStatus("VALID"); try { businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); fail(); } catch (Exception e) { assertEquals(AlreadyExistsException.class, e.getClass()); assertEquals("Unable to create business object data because it already exists and a new version is not allowed" + " since the latest version is still in \"UPLOADING\", which is one of the pre-registration statuses.", e.getMessage()); } } }
@Test public void testCreateBusinessObjectDataDiscoverStorageFilesNoStorageDirectory() { // Try to create an initial version of the business object data when discovery of storage files is enabled and storage directory is not specified. try { businessObjectDataService.createBusinessObjectData( new BusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION)); fail("Should throw an IllegalArgumentException when discovery of storage files is enabled and storage directory is not specified."); } catch (IllegalArgumentException e) { assertEquals("A storage directory must be specified when discovery of storage files is enabled.", e.getMessage()); } }
@Test public void testCreateBusinessObjectDataParentMissingBusinessObjectFormatVersion() { // This will create a business object data create request with parents. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(true); // Remove the business object format version required field. List<BusinessObjectDataKey> businessObjectDataKeys = businessObjectDataCreateRequest.getBusinessObjectDataParents(); businessObjectDataKeys.get(0).setBusinessObjectFormatVersion(null); // Try to create a business object data which should fail since one of the required attributes is missing. try { businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); fail("Should throw an IllegalArgumentException when business object format version is not specified for a business object data parent."); } catch (IllegalArgumentException e) { assertEquals("A business object format version must be specified.", e.getMessage()); } }
@Test public void testCreateBusinessObjectDataParentMissingBusinessObjectDataVersion() { // This will create a business object data create request with parents. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(true); // Remove the business object data version required field. List<BusinessObjectDataKey> businessObjectDataKeys = businessObjectDataCreateRequest.getBusinessObjectDataParents(); businessObjectDataKeys.get(0).setBusinessObjectDataVersion(null); // Try to create a business object data which should fail since one of the required attributes is missing. try { businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); fail("Should throw an IllegalArgumentException when business object data version is not specified for a business object data parent."); } catch (IllegalArgumentException e) { assertEquals("A business object data version must be specified.", e.getMessage()); } }
@Test public void testCreateBusinessObjectDataParentMissingPartitionValue() { // This will create a business object data create request with parents. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(true); // Remove the partition value required field. List<BusinessObjectDataKey> businessObjectDataKeys = businessObjectDataCreateRequest.getBusinessObjectDataParents(); businessObjectDataKeys.get(0).setPartitionValue(null); // Try to create a business object data which should fail since one of the required attributes is missing. try { businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); fail("Should throw an IllegalArgumentException when partition value is not specified for a business object data parent."); } catch (IllegalArgumentException e) { assertEquals("A partition value must be specified.", e.getMessage()); } }
@Test public void testCreateBusinessObjectDataValidateFlagIgnoredForNonS3Storage() throws Exception { // Create an S3 storage entity. List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME)); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_VALIDATE_FILE_EXISTENCE), Boolean.TRUE.toString())); storageDaoTestHelper.createStorageEntity(STORAGE_NAME, "NON_S3_STORAGE", attributes); // Create relative database entities. businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA, true, PARTITION_KEY); businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS); // Build a list of storage files. List<StorageFile> storageFiles = businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES); // Build a new business object data create request. BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper .createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, STORAGE_NAME, testS3KeyPrefix, storageFiles); // Try to create a business object data instance. This should succeed since the bucket is not of type "S3", even though there are no files in S3. businessObjectDataService.createBusinessObjectData(request); }
@Test public void testCreateBusinessObjectDataPreRegistrationAssertDirectoryPathNotRequiredWhenStatusIsPreRegistrationAndDirectoryIsSetInResponse() { StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME); storageEntity.getAttributes().add(storageDaoTestHelper .createStorageAttributeEntity(storageEntity, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), "foo")); // Create an initial version of the business object data. BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest(); businessObjectDataCreateRequest.setSubPartitionValues(null); businessObjectDataCreateRequest.setStatus("UPLOADING"); businessObjectDataCreateRequest.setStorageUnits(Arrays.asList(new StorageUnitCreateRequest(STORAGE_NAME, null, null, null))); BusinessObjectData businessObjectData = businessObjectDataService.createBusinessObjectData(businessObjectDataCreateRequest); assertEquals("foo", businessObjectData.getStorageUnits().get(0).getStorageDirectory().getDirectoryPath()); }
@Test public void testCreateBusinessObjectDataDiscoverStorageFilesStorageFilesSpecified() { // Try to create an initial version of the business object data when discovery of storage files is enabled and storage files are specified. try { businessObjectDataService.createBusinessObjectData( new BusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, NO_SUBPARTITION_VALUES, BusinessObjectDataStatusEntity.VALID, Arrays.asList( new StorageUnitCreateRequest(STORAGE_NAME, new StorageDirectory(STORAGE_DIRECTORY_PATH), Arrays.asList(new StorageFile(LOCAL_FILE, FILE_SIZE_1_KB, ROW_COUNT_1000)), DISCOVER_STORAGE_FILES)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_CREATE_NEW_VERSION)); fail("Should throw an IllegalArgumentException when discovery of storage files is enabled and storage files are specified."); } catch (IllegalArgumentException e) { assertEquals("Storage files cannot be specified when discovery of storage files is enabled.", e.getMessage()); } }
@Test public void testCreateBusinessObjectDataS3ManagedBucketWithZeroByteDirectoryMarkers() throws Exception { // Create relative database entities. BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper .createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, FORMAT_DOCUMENT_SCHEMA, false, PARTITION_KEY); businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(BDATA_STATUS); // Place test files and 0 byte S3 directory markers in the S3 managed storage. businessObjectDataServiceTestHelper.prepareTestS3Files(testS3KeyPrefix, localTempPath, LOCAL_FILES, S3_DIRECTORY_MARKERS); // Build a new business object data create request. BusinessObjectDataCreateRequest request = businessObjectDataServiceTestHelper .createBusinessObjectDataCreateRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, BDATA_STATUS, StorageEntity.MANAGED_STORAGE, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, LOCAL_FILES)); // Create the business object data. BusinessObjectData resultBusinessObjectData = businessObjectDataService.createBusinessObjectData(request); // Verify the results. businessObjectDataServiceTestHelper .validateBusinessObjectData(businessObjectFormatEntity, PARTITION_VALUE, NO_SUBPARTITION_VALUES, INITIAL_DATA_VERSION, true, BDATA_STATUS, StorageEntity.MANAGED_STORAGE, testS3KeyPrefix, businessObjectDataServiceTestHelper.getTestStorageFiles(testS3KeyPrefix, SORTED_LOCAL_FILES), CollectionUtils.isEmpty(request.getAttributes()) ? new ArrayList<Attribute>() : request.getAttributes(), resultBusinessObjectData); }