use of org.folio.rest.jaxrs.model.Metadata in project raml-module-builder by folio-org.
the class DemoRamlRestTest method test.
/**
* just send a get request for books api with and without the required author query param
* 1. one call should succeed and the other should fail (due to
* validation aspect that should block the call and return 400)
* 2. test the built in upload functionality
* @param context - the test context
*/
@Test
public void test(TestContext context) throws Exception {
Book b = new Book();
Data d = new Data();
d.setAuthor("a");
d.setGenre("g");
d.setDescription("asdfss");
b.setData(d);
d.setTitle("title");
d.setDatetime(new Datetime());
d.setLink("link");
b.setStatus(0);
b.setSuccess(true);
ObjectMapper om = new ObjectMapper();
String book = om.writerWithDefaultPrettyPrinter().writeValueAsString(b);
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(book), 201, HttpMethod.POST, "application/json", TENANT, true);
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(book), 201, HttpMethod.POST, "application/json", TENANT, false);
// check that additionalProperties (fields not appearing in schema) - returns 422
JsonObject jo = new JsonObject(book);
jo.put("lalala", "non existant");
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(jo.encode()), 422, HttpMethod.POST, "application/json", TENANT, false);
postData(context, "http://localhost:" + port + "/admin/loglevel?level=FINE&java_package=org.folio.rest", null, 200, HttpMethod.PUT, "application/json", TENANT, false);
Metadata md = new Metadata();
md.setCreatedByUserId("12345678-1234-1234-1234-123456789098");
md.setCreatedByUsername("you");
md.setCreatedDate(new Date());
md.setUpdatedDate(new Date());
md.setUpdatedByUserId("123456789098");
b.setMetadata(md);
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(om.writerWithDefaultPrettyPrinter().writeValueAsString(b)), 422, HttpMethod.POST, "application/json", TENANT, false);
md.setUpdatedByUserId("12345678-1234-1234-1234-123456789098");
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(om.writerWithDefaultPrettyPrinter().writeValueAsString(b)), 201, HttpMethod.POST, "application/json", TENANT, false);
checkURLs(context, "http://localhost:" + port + "/apidocs/index.html", 200);
checkURLs(context, "http://localhost:" + port + "/admin/loglevel", 200);
}
use of org.folio.rest.jaxrs.model.Metadata in project raml-module-builder by folio-org.
the class MetadataUtil method populateMetadata.
/**
* Populate each T of entities with the same instance of Metadata based on the userId value taken
* from user id header or token header of okapiHeaders.
*/
public static <T> void populateMetadata(List<T> entities, Map<String, String> okapiHeaders) throws ReflectiveOperationException {
if (entities == null) {
return;
}
Method setMetadata = null;
Metadata metadata = null;
for (T entity : entities) {
if (entity == null) {
continue;
}
if (metadata == null) {
setMetadata = getSetMetadataMethod(entity);
if (setMetadata == null) {
return;
}
metadata = createMetadata(okapiHeaders);
}
setMetadata.invoke(entity, metadata);
}
}
use of org.folio.rest.jaxrs.model.Metadata in project raml-module-builder by folio-org.
the class MetadataUtilTest method createMetadata.
@Test
void createMetadata() {
Metadata metadata = MetadataUtil.createMetadata(headers());
assertThat(metadata.getCreatedByUserId(), is(nullValue()));
assertThat(metadata.getUpdatedByUserId(), is(nullValue()));
assertNow(metadata.getCreatedDate());
assertNow(metadata.getUpdatedDate());
}
Aggregations