Search in sources :

Example 6 with InternalServerErrorException

use of io.crnk.core.exception.InternalServerErrorException in project crnk-framework by crnk-project.

the class ClientStubBaseTest method check500AndNoBodyGivesInternalServerErrorException.

@Test
public void check500AndNoBodyGivesInternalServerErrorException() throws IOException {
    HttpAdapterResponse response = Mockito.mock(HttpAdapterResponse.class);
    Mockito.when(response.body()).thenReturn("");
    Mockito.when(response.code()).thenReturn(500);
    RuntimeException exception = stub.handleError(response);
    Assert.assertTrue(exception instanceof InternalServerErrorException);
}
Also used : HttpAdapterResponse(io.crnk.client.http.HttpAdapterResponse) InternalServerErrorException(io.crnk.core.exception.InternalServerErrorException) Test(org.junit.Test)

Example 7 with InternalServerErrorException

use of io.crnk.core.exception.InternalServerErrorException in project crnk-framework by crnk-project.

the class ClientStubBaseTest method checkBodyWithNoErrorsAnd500Status.

@Test
public void checkBodyWithNoErrorsAnd500Status() throws IOException {
    Document document = new Document();
    document.setErrors(new ArrayList<ErrorData>());
    String body = client.getObjectMapper().writeValueAsString(document);
    HttpAdapterResponse response = Mockito.mock(HttpAdapterResponse.class);
    Mockito.when(response.body()).thenReturn(body);
    Mockito.when(response.code()).thenReturn(500);
    RuntimeException exception = stub.handleError(response);
    Assert.assertTrue(exception instanceof InternalServerErrorException);
}
Also used : HttpAdapterResponse(io.crnk.client.http.HttpAdapterResponse) InternalServerErrorException(io.crnk.core.exception.InternalServerErrorException) Document(io.crnk.core.engine.document.Document) ErrorData(io.crnk.core.engine.document.ErrorData) Test(org.junit.Test)

Example 8 with InternalServerErrorException

use of io.crnk.core.exception.InternalServerErrorException in project crnk-framework by crnk-project.

the class DynamicClientTest method testRelationship.

@Test
public void testRelationship() throws IOException {
    ResourceRepositoryV2<Resource, String> resourceRepository = client.getRepositoryForPath("dynamic1");
    RelationshipRepositoryV2<Resource, String, Resource, String> repository = client.getRepositoryForPath("dynamic1", "tasks");
    ObjectMapper mapper = new ObjectMapper();
    Resource target = repository.findOneTarget("a", "parent", new QuerySpec("tasks"));
    Assert.assertEquals("doe", target.getAttributes().get("value").asText());
    List<Resource> targets = repository.findManyTargets("a", "children", new QuerySpec("tasks"));
    Assert.assertEquals(1, targets.size());
    Assert.assertEquals("doe", targets.get(0).getAttributes().get("value").asText());
    Resource source = new Resource();
    source.setId("john");
    source.setType("dynamic1");
    source.getAttributes().put("value", mapper.readTree("\"doe\""));
    resourceRepository.create(source);
    repository.setRelation(source, "12", "parent");
    repository.setRelations(source, Arrays.asList("12"), "children");
    repository.addRelations(source, Arrays.asList("12"), "children");
    repository.removeRelations(source, Arrays.asList("12"), "children");
    try {
        repository.setRelation(source, "13", "parent");
        Assert.fail();
    } catch (InternalServerErrorException e) {
    // ok
    }
}
Also used : Resource(io.crnk.core.engine.document.Resource) InternalServerErrorException(io.crnk.core.exception.InternalServerErrorException) QuerySpec(io.crnk.core.queryspec.QuerySpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

InternalServerErrorException (io.crnk.core.exception.InternalServerErrorException)8 Test (org.junit.Test)5 HttpAdapterResponse (io.crnk.client.http.HttpAdapterResponse)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Document (io.crnk.core.engine.document.Document)2 ErrorData (io.crnk.core.engine.document.ErrorData)2 Resource (io.crnk.core.engine.document.Resource)2 ArrayList (java.util.ArrayList)2 HttpAdapter (io.crnk.client.http.HttpAdapter)1 HttpAdapterRequest (io.crnk.client.http.HttpAdapterRequest)1 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)1 ErrorResponse (io.crnk.core.engine.error.ErrorResponse)1 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)1 ExceptionMapperRegistry (io.crnk.core.engine.internal.exception.ExceptionMapperRegistry)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 Operation (io.crnk.operations.Operation)1 OperationResponse (io.crnk.operations.OperationResponse)1 OperationsCall (io.crnk.operations.client.OperationsCall)1 MovieEntity (io.crnk.operations.model.MovieEntity)1