@Test public void testGetStorageUnitStorageUnitNoExists() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Mock the external calls. when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(new ArrayList<>()); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { businessObjectDataInitiateRestoreHelperServiceImpl.getStorageUnit(businessObjectDataEntity); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no S3 storage unit. Business object data: {%s}", BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitMultipleStorageUnitsExist() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a list of storage unit entities. List<StorageUnitEntity> storageUnitEntities = Arrays.asList(new StorageUnitEntity(), new StorageUnitEntity()); // Mock the external calls. when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(storageUnitEntities); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { businessObjectDataInitiateRestoreHelperServiceImpl.getStorageUnit(businessObjectDataEntity); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has multiple (%d) S3 storage units. Business object data: {%s}", storageUnitEntities.size(), BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetAndValidateStorageUnitNoS3StorageUnit() { // 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, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setId(ID); // Mock the external calls. when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(new ArrayList<>()); when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { businessObjectDataInitiateDestroyHelperServiceImpl.getAndValidateStorageUnit(businessObjectDataEntity, businessObjectDataKey); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no S3 storage unit. Business object data: {%s}", BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitEntityByBusinessObjectDataAndStorageName() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); // Create a storage entity StorageEntity storageEntity = new StorageEntity(); // Mock the external calls. when(storageDao.getStorageByName(STORAGE_NAME)).thenReturn(storageEntity); when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)).thenReturn(storageUnitEntity); // Call the method under test. StorageUnitEntity result = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Validate the results. assertEquals(storageUnitEntity, result); // Verify the external calls. verify(storageDao).getStorageByName(STORAGE_NAME); verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetAndValidateStorageUnitMultipleS3StorageUnits() { // 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, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setId(ID); // Mock the external calls. when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(Arrays.asList(new StorageUnitEntity(), new StorageUnitEntity())); when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { businessObjectDataInitiateDestroyHelperServiceImpl.getAndValidateStorageUnit(businessObjectDataEntity, businessObjectDataKey); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", 2, StoragePlatformEntity.S3, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitEntityByBusinessObjectDataAndStorageNameStorageUnitNoExists() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage entity StorageEntity storageEntity = new StorageEntity(); // Mock the external calls. when(storageDao.getStorageByName(STORAGE_NAME)).thenReturn(storageEntity); when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)).thenReturn(null); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); fail(); } catch (ObjectNotFoundException e) { assertEquals(String .format("Could not find storage unit in \"%s\" storage for the business object data {%s}.", STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageDao).getStorageByName(STORAGE_NAME); verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitEntityByBusinessObjectDataAndStorage() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage entity. StorageEntity storageEntity = new StorageEntity(); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); // Mock the external calls. when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)).thenReturn(storageUnitEntity); // Call the method under test. StorageUnitEntity result = storageUnitDaoHelper.getStorageUnitEntityByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); // Validate the results. assertEquals(storageUnitEntity, result); // Verify the external calls. verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitStorageUnitNotRestored() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage unit status entity. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStatus(storageUnitStatusEntity); // Mock the external calls. when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { expireRestoredBusinessObjectDataHelperServiceImpl.getStorageUnit(STORAGE_NAME, businessObjectDataEntity); } catch (IllegalArgumentException e) { assertEquals(String .format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", STORAGE_NAME, StorageUnitStatusEntity.RESTORED, STORAGE_UNIT_STATUS, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
Boolean businessObjectDataLatestVersion, BusinessObjectDataStatusEntity businessObjectDataStatusEntity) BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setVersion(businessObjectDataVersion); businessObjectDataEntity.setPartitionValue(businessObjectDataPartitionValue);
List<BusinessObjectDataEntity> businessObjectDataParents) BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setVersion(businessObjectDataVersion); businessObjectDataEntity.setPartitionValue(businessObjectDataPartitionValue);
@Test public void testGetStorageUnitEntityByBusinessObjectDataAndStorageStorageUnitNoExists() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage entity. StorageEntity storageEntity = new StorageEntity(); storageEntity.setName(STORAGE_NAME); // Mock the external calls. when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)).thenReturn(null); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { storageUnitDaoHelper.getStorageUnitEntityByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); fail(); } catch (ObjectNotFoundException e) { assertEquals(String .format("Could not find storage unit in \"%s\" storage for the business object data {%s}.", STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnit() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage unit status entity. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(StorageUnitStatusEntity.ARCHIVED); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStatus(storageUnitStatusEntity); // Mock the external calls. when(storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity)) .thenReturn(Collections.singletonList(storageUnitEntity)); // Call the method under test. StorageUnitEntity result = businessObjectDataInitiateRestoreHelperServiceImpl.getStorageUnit(businessObjectDataEntity); // Verify the external calls. verify(storageUnitDao).getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity); verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(result, storageUnitEntity); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeDeleted() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, NO_ATTRIBUTES); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(0, CollectionUtils.size(businessObjectDataEntity.getAttributes())); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdatedAttributeNamesEqualIgnoreCase() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME.toUpperCase()); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper .updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE_2))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME.toUpperCase(), result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueUpdated() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE_2))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE_2, result.getValue()); }
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
@Test public void testUpdateBusinessObjectDataAttributesAttributeValueNotUpdated() { // Create a business object data attribute entity. BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntity.setName(ATTRIBUTE_NAME); businessObjectDataAttributeEntity.setValue(ATTRIBUTE_VALUE); // Create a business object data entity that contains one attribute entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntity); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE))); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity result = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(ATTRIBUTE_NAME, result.getName()); assertEquals(ATTRIBUTE_VALUE, result.getValue()); }
@Test public void testUpdateBusinessObjectDataAttributesAttributeAdded() { // Create a list of attributes. List<Attribute> attributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE)); // Create a business object data entity without attributes. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setAttributes(new ArrayList<>()); // Call the method under test. attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the results. assertEquals(1, CollectionUtils.size(businessObjectDataEntity.getAttributes())); BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = IterableUtils.get(businessObjectDataEntity.getAttributes(), 0); assertEquals(businessObjectDataEntity, businessObjectDataAttributeEntity.getBusinessObjectData()); assertEquals(ATTRIBUTE_NAME, businessObjectDataAttributeEntity.getName()); assertEquals(ATTRIBUTE_VALUE, businessObjectDataAttributeEntity.getValue()); }
/** * Creates and persists a business object data entity per specified parameters. * * @param businessObjectFormatEntity the business object format entity * @param request the business object data invalidate unregistered request that contains the business object data key * @param businessObjectDataVersion the business object data version * @param latestVersion specifies if this business object data is the latest version * * @return the business object data entity */ private BusinessObjectDataEntity createBusinessObjectDataEntityFromBusinessObjectDataInvalidateUnregisteredRequest( BusinessObjectFormatEntity businessObjectFormatEntity, BusinessObjectDataInvalidateUnregisteredRequest request, int businessObjectDataVersion, boolean latestVersion) { BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity); businessObjectDataEntity.setPartitionValue(request.getPartitionValue()); businessObjectDataEntity.setPartitionValue2(herdCollectionHelper.safeGet(request.getSubPartitionValues(), 0)); businessObjectDataEntity.setPartitionValue3(herdCollectionHelper.safeGet(request.getSubPartitionValues(), 1)); businessObjectDataEntity.setPartitionValue4(herdCollectionHelper.safeGet(request.getSubPartitionValues(), 2)); businessObjectDataEntity.setPartitionValue5(herdCollectionHelper.safeGet(request.getSubPartitionValues(), 3)); businessObjectDataEntity.setVersion(businessObjectDataVersion); businessObjectDataEntity.setLatestVersion(latestVersion); businessObjectDataEntity.setStatus(businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(BusinessObjectDataStatusEntity.VALID)); return businessObjectDataDao.saveAndRefresh(businessObjectDataEntity); } }