SwiftStorageProvider extends S3StorageProvider { @Override protected void doSetSpaceProperties(String spaceId, Map<String, String> spaceProperties) { log.debug("setSpaceProperties(" + spaceId + ")"); Map<String, String> originalProperties; try { originalProperties = getAllSpaceProperties(spaceId); } catch (NotFoundException e) { createHiddenSpace(PROPERTIES_BUCKET, 0); originalProperties = new HashMap<>(); } String metadataBucketName = getBucketName(PROPERTIES_BUCKET); String creationDate = originalProperties.get(PROPERTIES_SPACE_CREATED); if (creationDate == null) { creationDate = spaceProperties.get(PROPERTIES_SPACE_CREATED); if (creationDate == null) { creationDate = formattedDate(new Date()); } } spaceProperties.put(PROPERTIES_SPACE_CREATED, creationDate); spaceProperties = replaceInMapValues(spaceProperties, "@", "+"); log.debug( "Writing space properties " + spaceProperties.toString() + " to object " + spaceId + " in Swift container " + metadataBucketName ); s3Client.putObject(metadataBucketName, spaceId, spaceProperties.toString()); } SwiftStorageProvider(String accessKey, String secretKey, Map<String, String> options);  SwiftStorageProvider(AmazonS3 s3Client, String accessKey); @Override StorageProviderType getStorageProviderType(); @Override void removeSpace(String spaceId); @Override String createHiddenSpace(String spaceId, int expirationInDays); ObjectMetadata expireObject(String bucketName, String contentId, Integer seconds);  }
@Test public void testDoSetSpaceProperties() { Date date = new Date(); setupS3Client(); String bucketName = truncateKey() + "." + spaceId; String propsBucketName = getPropsBucketName(); String properties = "{key1=value1, key2=value2, key3=value+3}"; String propsWithDate = "{key1=value1, key2=value2, space-created=" + formattedDate(date) + ", key3=value+3}"; Date mockDate = createMock(Date.class); expect(mockDate.getTime()).andReturn(date.getTime()); Bucket bucket = createMock(Bucket.class); Bucket propsBucket = createMock(Bucket.class); expect(bucket.getName()).andReturn(bucketName).anyTimes(); expect(propsBucket.getName()).andReturn(propsBucketName).anyTimes(); expect(s3Client.listBuckets()).andReturn(Arrays.asList(bucket, propsBucket)).anyTimes(); expect(s3Client.getObjectAsString(propsBucketName, spaceId)).andReturn(properties); ObjectListing objectListing = createMock("ObjectListing", ObjectListing.class); setUpListObjects(objectListing, 1); setUpListObjects(objectListing, 0); expect(s3Client.putObject( propsBucketName, spaceId, propsWithDate )).andReturn(createMock(PutObjectResult.class)); SwiftStorageProvider provider = getProvider(); replay(s3Client, bucket, propsBucket, objectListing); Map<String, String> spaceProps = new HashMap<>(); spaceProps.put("key1", "value1"); spaceProps.put("key2", "value2"); spaceProps.put("key3", "value@3"); provider.doSetSpaceProperties(spaceId, spaceProps); verify(s3Client, bucket, propsBucket, objectListing); }