Skip to content

Commit

Permalink
Ag. response eats exceptions thrown while calculating attributes #576
Browse files Browse the repository at this point in the history
test ... works correctly
  • Loading branch information
andrus committed Aug 17, 2022
1 parent 8a643b9 commit 8cdd649
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import java.util.function.Function;

public class GET_EntityOverlay_PerRequestIT extends DbTest {

Expand Down Expand Up @@ -187,6 +188,16 @@ public void test_OverlaidExclude() {
.bodyEquals(1, "{\"id\":1,\"name\":\"N\"}");
}

@Test
public void test_OverlaidDataReaderException() {

tester.e4().insertColumns("id", "c_varchar").values(2, "a").values(4, "b").exec();

tester.target("/e4_with_exception")
.get()
.wasServerError();
}

@Path("")
public static class Resource {

Expand Down Expand Up @@ -264,5 +275,22 @@ public DataResponse<E2> getE2_With_exclude(@Context UriInfo uriInfo) {
.clientParams(uriInfo.getQueryParameters())
.get();
}

@GET
@Path("e4_with_exception")
public DataResponse<E4> getE4_withException(@Context UriInfo uriInfo) {

Function<E4, String> throwing = e4 -> {
throw new RuntimeException("testing this exception");
};

AgEntityOverlay<E4> overlay = AgEntity.overlay(E4.class).attribute("ax", String.class, throwing);

return AgJaxrs
.select(E4.class, config)
.entityOverlay(overlay)
.clientParams(uriInfo.getQueryParameters())
.get();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.agrest.access.ReadFilter;
import io.agrest.access.UpdateAuthorizer;
import io.agrest.pojo.model.P1;
import io.agrest.reader.DataReader;
import io.agrest.resolver.RootDataResolver;
import io.agrest.runtime.processor.select.SelectContext;
import org.apache.cayenne.di.Injector;
Expand All @@ -16,6 +17,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -47,6 +49,33 @@ public void testResolve_attribute() {
assertEquals(1, eo.getAttributes().size());
}

@Test
public void testResolve_attribute_throwingFunction() {
RootDataResolver<P1> r1 = mock(RootDataResolver.class);

AgEntity<P1> e = new DefaultEntity<>(
"p1", P1.class,
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(),
r1,
ReadFilter.allowsAllFilter(),
CreateAuthorizer.allowsAllFilter(),
UpdateAuthorizer.allowsAllFilter(),
DeleteAuthorizer.allowsAllFilter()
);

Function<P1, String> throwing = p1 -> {
throw new RuntimeException("testing this exception");
};

AgEntityOverlay<P1> attributeOverlay = AgEntity
.overlay(P1.class)
.attribute("a1", String.class, throwing);

AgEntity<P1> eo = attributeOverlay.resolve(mock(AgSchema.class), e);
DataReader reader = eo.getAttribute("a1").getDataReader();
assertThrows(RuntimeException.class, () -> reader.read(new P1()));
}

@Test
public void testResolve_RootResolver() {
RootDataResolver<P1> r1 = mock(RootDataResolver.class);
Expand Down

0 comments on commit 8cdd649

Please sign in to comment.