/** * Validates the storage unit. * * @param storageUnitEntity the storage unit entity, not null * @param storageName the storage name * @param businessObjectDataKey the business object data key */ private void validateStorageUnit(StorageUnitEntity storageUnitEntity, String storageName, BusinessObjectDataKey businessObjectDataKey) { Assert.isTrue(StorageUnitStatusEntity.ENABLED.equals(storageUnitEntity.getStatus().getCode()) || StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String.format( "Storage unit status is \"%s\", but must be \"%s\" or \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.ARCHIVING, storageName, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); }
public Void answer(InvocationOnMock invocation) { // Get the new storage unit status. String storageUnitStatus = (String) invocation.getArguments()[1]; // Create a storage unit status entity for the new storage unit status. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(storageUnitStatus); // Update the storage unit with the new status. StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0]; storageUnitEntity.setStatus(storageUnitStatusEntity); return null; } }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, StorageUnitStatusEntity.ARCHIVED);
/** * Creates and persists a new storage unit status entity. * * @param statusCode the code of the storage unit status * @param description the description of the status code * @param available specifies if the business object data stored in the relative storage unit is available or not for consumption * * @return the newly created storage unit status entity */ public StorageUnitStatusEntity createStorageUnitStatusEntity(String statusCode, String description, Boolean available) { StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(statusCode); storageUnitStatusEntity.setDescription(description); storageUnitStatusEntity.setAvailable(available); return storageUnitStatusDao.saveAndRefresh(storageUnitStatusEntity); } }
StorageUnitStatusEntity oldStorageUnitStatusEntity = new StorageUnitStatusEntity(); oldStorageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS); StorageUnitStatusEntity newStorageUnitStatusEntity = new StorageUnitStatusEntity(); newStorageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS_2); assertEquals(STORAGE_UNIT_STATUS_2, storageUnitEntity.getStatus().getCode());
/** * Creates a business object data status instance from the storage unit entity. * * @param storageUnitEntity the storage unit entity * * @return the business object data status instance */ private BusinessObjectDataStatus createNotAvailableBusinessObjectDataStatus(StorageUnitEntity storageUnitEntity) { // Get the business object entity. BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData(); // Create and populate the business object data status instance. BusinessObjectDataStatus businessObjectDataStatus = new BusinessObjectDataStatus(); businessObjectDataStatus.setBusinessObjectFormatVersion(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion()); businessObjectDataStatus.setPartitionValue(businessObjectDataEntity.getPartitionValue()); businessObjectDataStatus.setSubPartitionValues(businessObjectDataHelper.getSubPartitionValues(businessObjectDataEntity)); businessObjectDataStatus.setBusinessObjectDataVersion(businessObjectDataEntity.getVersion()); // If storage unit is "available", the business object data is selected as "non-available" due to its business object data status. if (storageUnitEntity.getStatus().getAvailable()) { businessObjectDataStatus.setReason(businessObjectDataEntity.getStatus().getCode()); } // Otherwise, report the storage unit status as a reason for the business object data not being available. else { businessObjectDataStatus.setReason(storageUnitEntity.getStatus().getCode()); } return businessObjectDataStatus; }
StorageUnitStatusEntity oldStorageUnitStatusEntity = new StorageUnitStatusEntity(); oldStorageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS); StorageUnitStatusEntity newStorageUnitStatusEntity = new StorageUnitStatusEntity(); newStorageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS_2); assertEquals(STORAGE_UNIT_STATUS_2, storageUnitEntity.getStatus().getCode());
/** * Creates a business object data status instance from the storage unit entity. * * @param storageUnitEntity the storage unit entity * * @return the business object data status instance */ private BusinessObjectDataStatus createNotAvailableBusinessObjectDataStatus(StorageUnitEntity storageUnitEntity) { // Get the business object entity. BusinessObjectDataEntity businessObjectDataEntity = storageUnitEntity.getBusinessObjectData(); // Create and populate the business object data status instance. BusinessObjectDataStatus businessObjectDataStatus = new BusinessObjectDataStatus(); businessObjectDataStatus.setBusinessObjectFormatVersion(businessObjectDataEntity.getBusinessObjectFormat().getBusinessObjectFormatVersion()); businessObjectDataStatus.setPartitionValue(businessObjectDataEntity.getPartitionValue()); businessObjectDataStatus.setSubPartitionValues(businessObjectDataHelper.getSubPartitionValues(businessObjectDataEntity)); businessObjectDataStatus.setBusinessObjectDataVersion(businessObjectDataEntity.getVersion()); // If storage unit is "available", the business object data is selected as "non-available" due to its business object data status. if (storageUnitEntity.getStatus().getAvailable()) { businessObjectDataStatus.setReason(businessObjectDataEntity.getStatus().getCode()); } // Otherwise, report the storage unit status as a reason for the business object data not being available. else { businessObjectDataStatus.setReason(storageUnitEntity.getStatus().getCode()); } return businessObjectDataStatus; }
/** * Validates the storage unit. * * @param storageUnitEntity the storage unit entity, not null * @param storageName the storage name * @param businessObjectDataKey the business object data key */ private void validateStorageUnit(StorageUnitEntity storageUnitEntity, String storageName, BusinessObjectDataKey businessObjectDataKey) { Assert.isTrue(StorageUnitStatusEntity.ENABLED.equals(storageUnitEntity.getStatus().getCode()) || StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String.format( "Storage unit status is \"%s\", but must be \"%s\" or \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ENABLED, StorageUnitStatusEntity.ARCHIVING, storageName, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); }
public Void answer(InvocationOnMock invocation) { // Get the new storage unit status. String storageUnitStatus = (String) invocation.getArguments()[1]; // Create a storage unit status entity for the new storage unit status. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(storageUnitStatus); // Update the storage unit with the new status. StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0]; storageUnitEntity.setStatus(storageUnitStatusEntity); return null; } }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLED);
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS); assertEquals(STORAGE_UNIT_STATUS, storageUnitEntity.getStatus().getCode());
/** * Retrieves a storage unit for the business object data in the specified storage and validates it. * * @param storageName the storage name * @param businessObjectDataEntity the business object data entity * * @return the storage unit entity */ protected StorageUnitEntity getStorageUnit(String storageName, BusinessObjectDataEntity businessObjectDataEntity) { // Get the storage unit and make sure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storageName, businessObjectDataEntity); // Get the storage unit status. String storageUnitStatus = storageUnitEntity.getStatus().getCode(); // Validate that S3 storage unit is in RESTORED state. if (!StorageUnitStatusEntity.RESTORED.equals(storageUnitStatus)) { throw new IllegalArgumentException(String .format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName, StorageUnitStatusEntity.RESTORED, storageUnitStatus, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } return storageUnitEntity; }
public Void answer(InvocationOnMock invocation) { // Get the new storage unit status. String storageUnitStatus = (String) invocation.getArguments()[1]; // Create a storage unit status entity for the new storage unit status. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(storageUnitStatus); // Update the storage unit with the new status. StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0]; storageUnitEntity.setStatus(storageUnitStatusEntity); return null; } }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVING, StorageUnitStatusEntity.ARCHIVING);
/** * Retrieves a storage unit for the business object data in the specified storage and validates it. * * @param storageName the storage name * @param businessObjectDataEntity the business object data entity * * @return the storage unit entity */ protected StorageUnitEntity getStorageUnit(String storageName, BusinessObjectDataEntity businessObjectDataEntity) { // Get the storage unit and make sure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storageName, businessObjectDataEntity); // Get the storage unit status. String storageUnitStatus = storageUnitEntity.getStatus().getCode(); // Validate that S3 storage unit is in RESTORED state. if (!StorageUnitStatusEntity.RESTORED.equals(storageUnitStatus)) { throw new IllegalArgumentException(String .format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName, StorageUnitStatusEntity.RESTORED, storageUnitStatus, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } return storageUnitEntity; }
public Void answer(InvocationOnMock invocation) { // Get the new storage unit status. String storageUnitStatus = (String) invocation.getArguments()[1]; // Create a storage unit status entity for the new storage unit status. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(storageUnitStatus); // Update the storage unit with the new status. StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0]; storageUnitEntity.setStatus(storageUnitStatusEntity); return null; } }).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.DISABLING);
String storageUnitStatus = storageUnitEntity.getStatus().getCode();
@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); }
String storageUnitStatus = storageUnitEntity.getStatus().getCode();
@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(); }
/** * Retrieves and validates the storage unit for the specified business object data. * * @param businessObjectDataEntity the business object data entity * @param storageEntity the storage entity * * @return the storage unit entity */ private StorageUnitEntity getStorageUnit(BusinessObjectDataEntity businessObjectDataEntity, StorageEntity storageEntity) { // Retrieve and validate storage unit for the business object data. StorageUnitEntity storageUnitEntity = storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); // Validate the storage unit. if (storageUnitEntity == null) { throw new IllegalArgumentException(String .format("Business object data has no storage unit in \"%s\" storage. Business object data: {%s}", storageEntity.getName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } else { // Validate that storage unit is in "ARCHIVING" state. Assert.isTrue(StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String.format( "Business object data is not currently being archived. " + "Storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageEntity.getName(), StorageUnitStatusEntity.ARCHIVING, storageUnitEntity.getStatus().getCode(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } return storageUnitEntity; }
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(StorageUnitStatusEntity.RESTORING);