DATAREST-835 - Search resources returning a single resource now get and consider ETag and Last-Modified headers.
We now interpret If-None-Match and If-Modified-Since headers on requests to resources backed by query methods returning a single instance only. This allows clients to optimize GET requests to those resources to save bandwidth.
This commit is contained in:
@@ -21,6 +21,7 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -36,6 +37,7 @@ public class Profile {
|
||||
private Long person;
|
||||
private @JsonProperty(required = true) String type;
|
||||
private @LastModifiedDate Date lastModifiedDate;
|
||||
private @Version Long version;
|
||||
private @JsonProperty("renamed") String aliased;
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
|
||||
@@ -343,4 +343,34 @@ public class MongoWebTests extends CommonWebTests {
|
||||
|
||||
mvc.perform(get(href)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-835
|
||||
*/
|
||||
@Test
|
||||
public void exposesETagHeaderForSearchResourceYieldingItemResource() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("profiles", "search", "findById");
|
||||
|
||||
Profile profile = repository.findAll().iterator().next();
|
||||
|
||||
mvc.perform(get(link.expand(profile.getId()).getHref()))//
|
||||
.andExpect(header().string("ETag", is("\"0\"")))//
|
||||
.andExpect(header().string("Last-Modified", is(notNullValue())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-835
|
||||
*/
|
||||
@Test
|
||||
public void doesNotAddETagHeaderForCollectionQueryResource() throws Exception {
|
||||
|
||||
Link link = client.discoverUnique("profiles", "search", "findByType");
|
||||
|
||||
Profile profile = repository.findAll().iterator().next();
|
||||
|
||||
mvc.perform(get(link.expand(profile.getType()).getHref()))//
|
||||
.andExpect(header().string("ETag", is(nullValue())))//
|
||||
.andExpect(header().string("Last-Modified", is(nullValue())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user