Search in sources :

Example 1 with RestSchemaClient

use of org.infinispan.client.rest.RestSchemaClient in project infinispan by infinispan.

the class ProtobufResourceTest method checkListProtobufEndpointUrl.

private void checkListProtobufEndpointUrl(String fileName, String errorMessage) {
    RestSchemaClient schemaClient = client.schemas();
    RestResponse response = join(schemaClient.names());
    Json jsonNode = Json.read(response.getBody());
    assertEquals(1, jsonNode.asList().size());
    assertEquals(fileName, jsonNode.at(0).at("name").asString());
    assertEquals("Schema error.proto has errors", jsonNode.at(0).at("error").at("message").asString());
    assertEquals(errorMessage, jsonNode.at(0).at("error").at("cause").asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) RestSchemaClient(org.infinispan.client.rest.RestSchemaClient)

Example 2 with RestSchemaClient

use of org.infinispan.client.rest.RestSchemaClient in project infinispan by infinispan.

the class ProtobufResourceTest method addAndGetListOrderedByName.

@Test
public void addAndGetListOrderedByName() throws Exception {
    RestSchemaClient schemaClient = client.schemas();
    String personProto = getResourceAsString("person.proto", getClass().getClassLoader());
    join(schemaClient.post("users", personProto));
    join(schemaClient.post("people", personProto));
    join(schemaClient.post("dancers", personProto));
    RestResponse response = join(schemaClient.names());
    ResponseAssertion.assertThat(response).isOk();
    Json jsonNode = Json.read(response.getBody());
    assertEquals(3, jsonNode.asList().size());
    assertEquals("dancers.proto", jsonNode.at(0).at("name").asString());
    assertEquals("people.proto", jsonNode.at(1).at("name").asString());
    assertEquals("users.proto", jsonNode.at(2).at("name").asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Json(org.infinispan.commons.dataconversion.internal.Json) RestSchemaClient(org.infinispan.client.rest.RestSchemaClient) Test(org.testng.annotations.Test)

Example 3 with RestSchemaClient

use of org.infinispan.client.rest.RestSchemaClient in project infinispan by infinispan.

the class MultiResourceTest method getProtobuf.

private String getProtobuf(String name) {
    RestSchemaClient schemas = client.schemas();
    RestResponse response = join(schemas.get(name));
    ResponseAssertion.assertThat(response).isOk();
    return response.getBody();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestSchemaClient(org.infinispan.client.rest.RestSchemaClient)

Example 4 with RestSchemaClient

use of org.infinispan.client.rest.RestSchemaClient in project infinispan by infinispan.

the class MultiResourceTest method createSchema.

private void createSchema(String name, String value) throws Exception {
    RestSchemaClient schemas = client.schemas();
    RestResponse response = join(schemas.put(name, value));
    ResponseAssertion.assertThat(response).isOk();
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonNode = objectMapper.readTree(response.getBody());
    assertEquals("null", jsonNode.get("error").asText());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) RestSchemaClient(org.infinispan.client.rest.RestSchemaClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with RestSchemaClient

use of org.infinispan.client.rest.RestSchemaClient in project infinispan by infinispan.

the class ProtobufResourceTest method crudSchema.

@Test
public void crudSchema() throws Exception {
    RestSchemaClient schemaClient = client.schemas();
    String personProto = getResourceAsString("person.proto", getClass().getClassLoader());
    // Create
    RestResponse response = join(schemaClient.post("person", personProto));
    ResponseAssertion.assertThat(response).isOk();
    Json jsonNode = Json.read(response.getBody());
    assertTrue(jsonNode.at("error").isNull());
    // Read
    response = join(schemaClient.get("person"));
    ResponseAssertion.assertThat(response).isOk();
    ResponseAssertion.assertThat(response).hasContentEqualToFile("person.proto");
    // Read adding .proto should also work
    response = join(schemaClient.get("person.proto"));
    ResponseAssertion.assertThat(response).isOk();
    ResponseAssertion.assertThat(response).hasContentEqualToFile("person.proto");
    // Update
    response = join(schemaClient.put("person", personProto));
    ResponseAssertion.assertThat(response).isOk();
    // Delete
    response = join(schemaClient.delete("person"));
    ResponseAssertion.assertThat(response).isOk();
    response = join(schemaClient.get("person"));
    ResponseAssertion.assertThat(response).isNotFound();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Json(org.infinispan.commons.dataconversion.internal.Json) RestSchemaClient(org.infinispan.client.rest.RestSchemaClient) Test(org.testng.annotations.Test)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)7 RestSchemaClient (org.infinispan.client.rest.RestSchemaClient)7 Json (org.infinispan.commons.dataconversion.internal.Json)4 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)4 Test (org.testng.annotations.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1