本文整理汇总了Java中com.theoryinpractise.halbuilder.api.ReadableRepresentation类的典型用法代码示例。如果您正苦于以下问题:Java ReadableRepresentation类的具体用法?Java ReadableRepresentation怎么用?Java ReadableRepresentation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadableRepresentation类属于com.theoryinpractise.halbuilder.api包,在下文中一共展示了ReadableRepresentation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: withPage
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
/**
* Add all bean properties
* from the supplied bean
* to the representation
* @param value
* @return
*/
public ResponseEntityBuilder<ReadableRepresentation> withPage(Page<?> value, String uriTemplate, String... includeFields) {
String[] fields = requestedFields == null ? includeFields : requestedFields;
// Extract page data such as size, page number
representation.withProperty("size", value.getSize());
representation.withProperty("number", value.getNumber());
representation.withProperty("numberOfElements", value.getNumberOfElements());
representation.withProperty("totalElements", value.getTotalElements());
// Next/back links
if (value.hasNextPage()) {
buildNextLink(representation, request);
}
if (value.hasPreviousPage()) {
buildPreviousLink(representation, request);
}
// Build the content of the page
for (Object object : value.getContent()) {
Representation content = converter.convert(object, new UriTemplate(uriTemplate), fields);
this.representation.withRepresentation("content", content);
}
return this;
}
示例2: testWithBean
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testWithBean() throws Exception {
HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
Customer customer = customer();
ResponseEntity<ReadableRepresentation> response =
builder.withBean(customer)
.etag(MODIFIED_DATE)
.lastModified(MODIFIED_DATE)
.expireIn(1000000)
.get();
assertHeaders(response);
Assert.assertEquals("123", response.getBody().getValue("customerId").toString());
Assert.assertEquals("[email protected]", response.getBody().getValue("email").toString());
Assert.assertEquals("First", response.getBody().getValue("firstName").toString());
Assert.assertEquals("Last", response.getBody().getValue("lastName").toString());
Assert.assertEquals("Fri Jan 02 11:17:36 GMT 1970", response.getBody().getValue("joined").toString());
}
示例3: testWithBeanWithChildrenIncludeFields
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testWithBeanWithChildrenIncludeFields() throws Exception {
HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
Customer customer = customerWithBaskets();
ResponseEntity<ReadableRepresentation> response =
builder.withBean(customer, "firstName", "email")
.etag(MODIFIED_DATE)
.lastModified(MODIFIED_DATE)
.expireIn(1000000)
.get();
assertHeaders(response);
Set<String> keys = response.getBody().getProperties().keySet();
Assert.assertTrue(keys.size() == 2);
Assert.assertTrue(keys.contains("email"));
Assert.assertTrue(keys.contains("firstName"));
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
示例4: testWithBeanWithChildrenRequestFields
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testWithBeanWithChildrenRequestFields() throws Exception {
Customer customer = customerWithBaskets();
request.setParameter("fields", new String[]{"lastName", "customerId"});
HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
ResponseEntity<ReadableRepresentation> response =
builder.withBean(customer)
.etag(MODIFIED_DATE)
.lastModified(MODIFIED_DATE)
.expireIn(1000000)
.get();
assertHeaders(response);
Set<String> keys = response.getBody().getProperties().keySet();
System.out.println(response.getBody().toString("application/hal+xml"));
Assert.assertTrue(keys.size() == 2);
Assert.assertTrue(keys.contains("lastName"));
Assert.assertTrue(keys.contains("customerId"));
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
示例5: testRequestFieldsOverridesIncludedFields
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testRequestFieldsOverridesIncludedFields() throws Exception {
Customer customer = customerWithBaskets();
request.setParameter("fields", new String[]{"lastName", "customerId"});
HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
ResponseEntity<ReadableRepresentation> response =
builder.withBean(customer, "firstName", "email")
.etag(MODIFIED_DATE)
.lastModified(MODIFIED_DATE)
.expireIn(1000000)
.get();
assertHeaders(response);
Set<String> keys = response.getBody().getProperties().keySet();
Assert.assertTrue(keys.size() == 2);
Assert.assertTrue(keys.contains("lastName"));
Assert.assertTrue(keys.contains("customerId"));
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
示例6: testRequestInvalidField
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testRequestInvalidField() throws Exception {
Customer customer = customerWithBaskets();
request.setParameter("fields", new String[]{"noChance", "firstName"});
HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
ResponseEntity<ReadableRepresentation> response =
builder.withBean(customer)
.etag(MODIFIED_DATE)
.lastModified(MODIFIED_DATE)
.expireIn(1000000)
.get();
assertHeaders(response);
Set<String> keys = response.getBody().getProperties().keySet();
Assert.assertTrue(keys.size() == 1);
Assert.assertTrue(keys.contains("firstName"));
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
示例7: testIncludeInvalidField
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testIncludeInvalidField() throws Exception {
HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
Customer customer = customerWithBaskets();
ResponseEntity<ReadableRepresentation> response =
builder.withBean(customer, "noChance", "firstName")
.etag(MODIFIED_DATE)
.lastModified(MODIFIED_DATE)
.expireIn(1000000)
.get();
assertHeaders(response);
Set<String> keys = response.getBody().getProperties().keySet();
Assert.assertTrue(keys.size() == 1);
Assert.assertTrue(keys.contains("firstName"));
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
示例8: testConvertEmbeddedManyToOne
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testConvertEmbeddedManyToOne() {
Customer customer = customer();
Basket basket = basket(1);
basket.setCustomer(customer);
customer.getBaskets().add(basket);
Representation representation = converter.convert(basket, new UriTemplate("/basket/{basketId}"));
Assert.assertEquals("1", representation.getValue("basketId").toString());
Collection<ReadableRepresentation> reps = representation.getResourceMap().get("customer");
Assert.assertNotNull(reps);
Assert.assertTrue(reps.size() == 1);
System.out.println(representation.toString("application/hal+xml"));
}
示例9: testSkuSearchPaging
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
@Transactional
public void testSkuSearchPaging() throws Exception {
MvcResult result = webAppContextSetup(context)
.build()
.perform(get("http://localhost/sku/?page=0&size=3&sort=skuId,desc")
.contentType(HAL_JSON).accept(HAL_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_JSON))
.andReturn();
// Verify result
ReadableRepresentation skus = getContent(result);
Assert.assertEquals(Integer.valueOf(3), Integer.valueOf(skus.getResourcesByRel("content").size()));
}
示例10: testSkuSearchWithAttr
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
@Transactional
public void testSkuSearchWithAttr() throws Exception {
MvcResult result = webAppContextSetup(context)
.build()
.perform(get("http://localhost/sku/?price.min=1000&price.max=1150&attr.neck=maple&attr.colour=sonic blue")
.contentType(HAL_XML).accept(HAL_XML))
.andExpect(status().isOk())
.andExpect(content().contentType(HAL_XML))
.andReturn();
// Verify result
ReadableRepresentation skus = getContent(result);
Assert.assertEquals(Integer.valueOf(1), Integer.valueOf(skus.getResourcesByRel("content").size()));
}
示例11: unmarshal
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
/**
* This function return an Object resulting of the unmarshalling of a certain
* representation for a certain class
* @param is input stream from where to read the representation
* @param type object class to be build
* @return the object of class type created out of the representation
* @throws Exception when an error creating the object occurs
*/
public static Object unmarshal( InputStream is, Class type) throws Exception
{
ReadableRepresentation r;
r = HalContext.getRepresentationFactory().readRepresentation( new InputStreamReader( is));
if( r == null)
return null;
return getObjectFromRepresentation( r, type);
}
示例12: build
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Override
public Name build(Object s) {
Name n = null;
if( ReadableRepresentation.class.isAssignableFrom( s.getClass())) {
ReadableRepresentation r = (ReadableRepresentation) s;
n = new Name( (String) r.getValue("firstName"), (String) r.getValue("lastName"));
}
return n;
}
示例13: getResourcesByRel
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
/**
* Get embedded resources by relation
*
* @param rel Relation name
* @return Embedded resources
*/
public List<HalResource> getResourcesByRel(final String rel)
{
final List<? extends ReadableRepresentation> resources = representation.getResourcesByRel(rel);
return resources.stream()
.map(representation -> new HalResource(objectMapper, representation))
.collect(Collectors.toList());
}
示例14: create
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Override
public ResponseEntity<ReadableRepresentation> create() {
if (this.headers.getLocation() == null) {
throw new RuntimeException("Location header must be set before calling create().");
}
return new ResponseEntity<ReadableRepresentation>(headers, HttpStatus.CREATED);
}
示例15: findOne
import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@RequestMapping(value="/{id}",
method=RequestMethod.GET)
@Transactional
public ResponseEntity<ReadableRepresentation> findOne(@PathVariable("id") Integer id, HalResponseEntityBuilder halBuilder) {
StockKeepingUnit sku = skuRepo.findOne(id);
return halBuilder.withBean(sku).etag().get();
}