Search in sources :

Example 1 with Book

use of org.folio.rest.jaxrs.model.Book 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;
}
Also used : Book(org.folio.rest.jaxrs.model.Book) Data(org.folio.rest.jaxrs.model.Data) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Datetime(org.folio.rest.jaxrs.model.Datetime)

Example 2 with Book

use of org.folio.rest.jaxrs.model.Book 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 ---------------------------");
        }
    });
}
Also used : Metadata(org.folio.rest.jaxrs.model.Metadata) JsonObject(io.vertx.core.json.JsonObject) Data(org.folio.rest.jaxrs.model.Data) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Book(org.folio.rest.jaxrs.model.Book) JsonObject(io.vertx.core.json.JsonObject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Datetime(org.folio.rest.jaxrs.model.Datetime) RmbtestsClient(org.folio.rest.client.RmbtestsClient) Test(org.junit.Test)

Example 3 with Book

use of org.folio.rest.jaxrs.model.Book in project raml-module-builder by folio-org.

the class DemoRamlRestTest method postBook.

private void postBook(TestContext context, String parameterString, int expectedStatus) {
    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 = "";
    try {
        book = om.writerWithDefaultPrettyPrinter().writeValueAsString(b);
    } catch (JsonProcessingException e) {
        context.fail(e);
    }
    postData(context, "http://localhost:" + port + "/rmbtests/books", Buffer.buffer(book), expectedStatus, 1, "application/json", TENANT, false);
}
Also used : Book(org.folio.rest.jaxrs.model.Book) Data(org.folio.rest.jaxrs.model.Data) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with Book

use of org.folio.rest.jaxrs.model.Book in project raml-module-builder by folio-org.

the class DemoRamlRestTest method getListOfBooks.

private List<Object> getListOfBooks() {
    List<Object> list = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        Book b = createBook();
        b.setStatus(i);
        list.add(b);
    }
    return list;
}
Also used : Book(org.folio.rest.jaxrs.model.Book) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

Book (org.folio.rest.jaxrs.model.Book)4 Data (org.folio.rest.jaxrs.model.Data)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonObject (io.vertx.core.json.JsonObject)2 Date (java.util.Date)2 Datetime (org.folio.rest.jaxrs.model.Datetime)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 RmbtestsClient (org.folio.rest.client.RmbtestsClient)1 Metadata (org.folio.rest.jaxrs.model.Metadata)1 Test (org.junit.Test)1