ParseSystemAndUserMetadataFromHeaders implements Function<HttpResponse, MutableBlobMetadata>,
         InvocationContext<ParseSystemAndUserMetadataFromHeaders> { @VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); } @Inject  ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory, DateService dateParser,
            @Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix); MutableBlobMetadata apply(HttpResponse from); ParseSystemAndUserMetadataFromHeaders setContext(HttpRequest request); ParseSystemAndUserMetadataFromHeaders setName(String name);  }
@Test public void testSetLastModified() { HttpResponse from = HttpResponse.builder() .statusCode(200).message("ok") .payload("") .addHeader(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT").build(); MutableBlobMetadata metadata = blobMetadataProvider.get(); parser.parseLastModifiedOrThrowException(from, metadata); assertEquals(metadata.getLastModified(), new SimpleDateFormatDateService() .rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT")); }
@Test public void testSetLastModifiedIso8601() { HttpResponse from = HttpResponse.builder() .statusCode(200).message("ok") .payload("") .addHeader(HttpHeaders.LAST_MODIFIED, "2011-01-28T17:35:08.000Z").build(); MutableBlobMetadata metadata = blobMetadataProvider.get(); parser.parseLastModifiedOrThrowException(from, metadata); assertEquals(metadata.getLastModified(), new SimpleDateFormatDateService() .iso8601DateParse("2011-01-28T17:35:08.000Z")); }
@Test(expectedExceptions = HttpException.class) public void testSetLastModifiedException() { HttpResponse from = HttpResponse.builder() .statusCode(200).message("ok") .payload("").build(); MutableBlobMetadata metadata = blobMetadataProvider.get(); parser.parseLastModifiedOrThrowException(from, metadata); }