Search in sources :

Example 6 with Metadata

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

Example 7 with Metadata

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);
    }
}
Also used : Metadata(org.folio.rest.jaxrs.model.Metadata) Method(java.lang.reflect.Method)

Example 8 with 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());
}
Also used : Metadata(org.folio.rest.jaxrs.model.Metadata) Test(org.junit.jupiter.api.Test)

Aggregations

Metadata (org.folio.rest.jaxrs.model.Metadata)8 Date (java.util.Date)4 JsonObject (io.vertx.core.json.JsonObject)3 Test (org.junit.jupiter.api.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 Book (org.folio.rest.jaxrs.model.Book)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Handler (io.vertx.core.Handler)1 Vertx (io.vertx.core.Vertx)1 Buffer (io.vertx.core.buffer.Buffer)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 HttpClientResponse (io.vertx.core.http.HttpClientResponse)1 HttpMethod (io.vertx.core.http.HttpMethod)1 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1 Async (io.vertx.ext.unit.Async)1