content: package io.agrest.cayenne.GET;
  
  import io.agrest.DataResponse;
  import io.agrest.cayenne.cayenne.main.E4;
  import io.agrest.cayenne.unit.main.MainDbTest;
  import io.agrest.cayenne.unit.main.MainModelTester;
  import io.agrest.jaxrs3.AgJaxrs;
  import io.bootique.junit5.BQTestTool;
  import org.junit.jupiter.api.Test;
  
  import jakarta.ws.rs.GET;
  import jakarta.ws.rs.Path;
  import jakarta.ws.rs.Produces;
  import jakarta.ws.rs.core.Configuration;
  import jakarta.ws.rs.core.Context;
  import jakarta.ws.rs.core.MediaType;
  import jakarta.ws.rs.core.UriInfo;
  
  public class SortIT extends MainDbTest {
  
      @BQTestTool
      static final MainModelTester tester = tester(Resource.class)
              .entitiesAndDependencies(E4.class)
              .build();
  
  
      @Test
      public void sort_ById() {
  
          tester.e4().insertColumns("id")
                  .values(2)
                  .values(1)
                  .values(3).exec();
  
          tester.target("/e4")
                  .queryParam("sort", "[{\"property\":\"id\",\"direction\":\"DESC\"}]")
                  .queryParam("include", "id")
                  .get()
                  .wasOk()
                  .bodyEquals(3, "{\"id\":3}", "{\"id\":2}", "{\"id\":1}");
      }
  
      @Test
      public void sort_Invalid() {
  
          tester.target("/e4")
                  .queryParam("sort", "[{\"property\":\"xyz\",\"direction\":\"DESC\"}]")
                  .queryParam("include", "id")
                  .get()
                  .wasBadRequest()
                  .bodyEquals("{\"message\":\"Invalid path 'xyz' for 'E4'\"}");
      }
  
      @Path("")
      @Produces(MediaType.APPLICATION_JSON)
      public static class Resource {
  
          @Context
          private Configuration config;
  
          @GET
          @Path("e4")
          public DataResponse<E4> getE4(@Context UriInfo uriInfo) {
              return AgJaxrs.select(E4.class, config).clientParams(uriInfo.getQueryParameters()).get();
          }
      }
  
  }
  