use of org.folio.rest.jaxrs.model.Datetime in project raml-module-builder by folio-org.
the class DemoRamlRestTest method createBook.
private Book createBook() {
int ran = ThreadLocalRandom.current().nextInt(0, 11);
Book b = new Book();
b.setStatus(99 + ran);
b.setSuccess(true);
b.setData(null);
Data d = new Data();
d.setAuthor("a" + ran);
Datetime dt = new Datetime();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS\'Z\'");
String parsedDate = format.format(new Date());
dt.set$date(parsedDate);
d.setDatetime(dt);
d.setGenre("b");
d.setDescription("c");
d.setLink("d");
d.setTitle("title" + ran);
b.setData(d);
return b;
}
use of org.folio.rest.jaxrs.model.Datetime 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);
ObjectMapper om = new ObjectMapper();
String book = om.writerWithDefaultPrettyPrinter().writeValueAsString(b);
// check File Uploads
postData(context, "http://localhost:" + port + "/admin/uploadmultipart", getBody("uploadtest.json", true), 200, 1, null, null, false);
postData(context, "http://localhost:" + port + "/admin/uploadmultipart?file_name=test.json", getBody("uploadtest.json", true), 200, 1, null, null, false);
postData(context, "http://localhost:" + port + "/rmbtests/test", Buffer.buffer(book), 200, 1, "application/json", TENANT, false);
d.setDatetime(new Datetime());
d.setTitle("title");
d.setLink("link");
b.setStatus(0);
b.setSuccess(true);
book = om.writerWithDefaultPrettyPrinter().writeValueAsString(b);
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(book), 201, 1, "application/json", TENANT, true);
postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(book), 201, 1, "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, 1, "application/json", TENANT, false);
postData(context, "http://localhost:" + port + "/admin/loglevel?level=FINE&java_package=org", null, 200, 0, "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, 1, "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, 1, "application/json", TENANT, false);
List<Object> list = getListOfBooks();
// should be 200
checkURLs(context, "http://localhost:" + port + "/apidocs/index.html", 200);
// should be 200
checkURLs(context, "http://localhost:" + port + "/admin/loglevel", 200);
// use generated client
checkClientCode(context);
RmbtestsClient testClient = new RmbtestsClient("localhost", port, "abc", "abc", false);
String[] facets = new String[] { "author:10", "name:5" };
testClient.getBooks("aaa", new BigDecimal(1999), null, null, facets, handler -> {
if (handler.statusCode() != 200) {
context.fail();
} else {
log.info(handler.statusCode() + "----------------------------------------- passed ---------------------------");
}
});
}
Aggregations