SwiftStorageProvider extends S3StorageProvider { @Override protected Map<String, String> prepContentProperties(ObjectMetadata objMetadata) { Map<String, String> contentProperties = new HashMap<>(); Map<String, String> userProperties = objMetadata.getUserMetadata(); for (String metaName : userProperties.keySet()) { String metaValue = userProperties.get(metaName); if (metaName.trim().equalsIgnoreCase("tags") || metaName.trim().equalsIgnoreCase("tags" + HEADER_KEY_SUFFIX) || metaName.trim().equalsIgnoreCase(PROPERTIES_CONTENT_MIMETYPE) || metaName.trim().equalsIgnoreCase(PROPERTIES_CONTENT_MIMETYPE + HEADER_KEY_SUFFIX)) { metaName = metaName.toLowerCase(); } contentProperties.put(getWithSpace(decodeHeaderKey(metaName)), decodeHeaderValue(metaValue)); } Map<String, Object> responseMeta = objMetadata.getRawMetadata(); for (String metaName : responseMeta.keySet()) { try { if (!isSwiftMetadata(metaName)) { Object metaValue = responseMeta.get(metaName); if (metaName.trim().equalsIgnoreCase(Headers.ETAG)) { metaName = Headers.ETAG; } contentProperties.put(metaName, String.valueOf(metaValue)); } } catch (IllegalArgumentException e) { e.printStackTrace(); } if (userProperties.keySet() .contains(metaName + HEADER_KEY_SUFFIX) && contentProperties.containsKey(metaName)) { contentProperties.remove(metaName); } } String contentType = objMetadata.getContentType(); if (contentType != null) { contentProperties.put(PROPERTIES_CONTENT_MIMETYPE, contentType); contentProperties.put(Headers.CONTENT_TYPE, contentType); } String encoding = objMetadata.getContentEncoding(); if (encoding != null) { contentProperties.put(Headers.CONTENT_ENCODING, encoding); } long contentLength = objMetadata.getContentLength(); if (contentLength >= 0) { String size = String.valueOf(contentLength); contentProperties.put(PROPERTIES_CONTENT_SIZE, size); contentProperties.put(Headers.CONTENT_LENGTH, size); } String checksum = objMetadata.getETag(); if (checksum != null) { String eTagValue = getETagValue(checksum); contentProperties.put(PROPERTIES_CONTENT_CHECKSUM, eTagValue); contentProperties.put(PROPERTIES_CONTENT_MD5, eTagValue); contentProperties.put(Headers.ETAG, eTagValue); } Date modified = objMetadata.getLastModified(); if (modified != null) { String modDate = formattedDate(modified); contentProperties.put(PROPERTIES_CONTENT_MODIFIED, modDate); contentProperties.put(Headers.LAST_MODIFIED, modDate); } return contentProperties; } 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 testPrepContentProperties() { Date date = new Date(); setupS3Client(); Map<String, String> userMetadata = new HashMap<>(); userMetadata.put("header1", "value1"); userMetadata.put("header2", "value2"); Map<String, Object> responseMetadata = new HashMap<>(); responseMetadata.put("x-trans-id", "abc"); responseMetadata.put("x-openstack-request-id", "abc"); ObjectMetadata objectMetadata = createMock("ObjectMetadata", ObjectMetadata.class); expect(objectMetadata.getRawMetadata()).andReturn(responseMetadata); expect(objectMetadata.getUserMetadata()).andReturn(userMetadata); expect(objectMetadata.getContentType()).andReturn("fakeContentType"); expect(objectMetadata.getContentEncoding()).andReturn("fakeEncoding"); expect(objectMetadata.getContentLength()).andReturn(1234L); expect(objectMetadata.getETag()).andReturn("fakeETag"); expect(objectMetadata.getLastModified()).andReturn(date); SwiftStorageProvider provider = getProvider(); replay(s3Client, objectMetadata); Map<String, String> preppedProperties = provider.prepContentProperties(objectMetadata); assertNotNull(preppedProperties); assertEquals("value1", preppedProperties.get("header1")); assertEquals("value2", preppedProperties.get("header2")); assertEquals("1234", preppedProperties.get("content-size")); assertEquals("1234", preppedProperties.get("Content-Length")); assertEquals("fakeETag", preppedProperties.get("content-md5")); assertEquals("fakeETag", preppedProperties.get("content-checksum")); assertEquals("fakeETag", preppedProperties.get("ETag")); assertEquals("fakeContentType", preppedProperties.get("content-mimetype")); assertEquals("fakeContentType", preppedProperties.get("Content-Type")); assertEquals("fakeEncoding", preppedProperties.get("Content-Encoding")); assertEquals(formattedDate(date), preppedProperties.get("Last-Modified")); assertEquals(formattedDate(date), preppedProperties.get("content-modified")); assertNull(preppedProperties.get("x-trans-id")); assertNull(preppedProperties.get("x-openstack-request-id")); verify(s3Client, objectMetadata); }