From 6296e2357253cef69321714aed447d17ea498345 Mon Sep 17 00:00:00 2001 From: Aaron Klish Date: Fri, 7 Aug 2020 22:56:32 -0500 Subject: [PATCH] Finished rebase --- .../elide/async/service/AsyncQueryThread.java | 8 ++++++-- .../async/service/DefaultAsyncQueryDAO.java | 2 +- .../async/service/AsyncQueryThreadTest.java | 4 ++-- .../src/main/java/com/yahoo/elide/Elide.java | 9 +++++---- .../com/yahoo/elide/ElideSettingsBuilder.java | 2 +- .../elide/resources/JsonApiEndpoint.java | 7 ++++--- .../com/yahoo/elide/core/LifeCycleTest.java | 4 ++-- .../yahoo/elide/core/TestRequestScope.java | 15 +++++++++++++-- .../com/yahoo/elide/jsonapi/JsonApiTest.java | 14 +++++++------- .../transaction/AbstractJpaTransaction.java | 2 +- .../yahoo/elide/graphql/GraphQLEndpoint.java | 2 +- .../elide/graphql/GraphQLRequestScope.java | 3 ++- .../com/yahoo/elide/graphql/QueryRunner.java | 2 +- .../elide/graphql/GraphQLEndpointTest.java | 8 ++++---- .../PersistentResourceFetcherTest.java | 3 ++- .../async/integration/tests/AsyncIT.java | 7 ++++--- .../java/example/tests/ControllerTest.java | 19 +++++++++++++++---- .../java/example/tests/IntegrationTest.java | 2 -- .../example/tests/IntegrationTestSetup.java | 4 +--- 19 files changed, 72 insertions(+), 45 deletions(-) diff --git a/elide-async/src/main/java/com/yahoo/elide/async/service/AsyncQueryThread.java b/elide-async/src/main/java/com/yahoo/elide/async/service/AsyncQueryThread.java index 16796d4546..446e47355f 100644 --- a/elide-async/src/main/java/com/yahoo/elide/async/service/AsyncQueryThread.java +++ b/elide-async/src/main/java/com/yahoo/elide/async/service/AsyncQueryThread.java @@ -78,12 +78,16 @@ protected AsyncQueryResult processQuery() throws URISyntaxException, NoHttpRespo if (queryObj.getQueryType().equals(QueryType.JSONAPI_V1_0)) { MultivaluedMap queryParams = getQueryParams(queryObj.getQuery()); log.debug("Extracted QueryParams from AsyncQuery Object: {}", queryParams); - response = elide.get(getPath(queryObj.getQuery()), queryParams, user, apiVersion, requestId); + + //TODO - we need to add the baseUrlEndpoint to the queryObject. + response = elide.get("", getPath(queryObj.getQuery()), queryParams, user, apiVersion, requestId); log.debug("JSONAPI_V1_0 getResponseCode: {}, JSONAPI_V1_0 getBody: {}", response.getResponseCode(), response.getBody()); } else if (queryObj.getQueryType().equals(QueryType.GRAPHQL_V1_0)) { - response = runner.run(queryObj.getQuery(), user, requestId); + //TODO - we need to add the baseUrlEndpoint to the queryObject. + + response = runner.run("", queryObj.getQuery(), user, requestId); log.debug("GRAPHQL_V1_0 getResponseCode: {}, GRAPHQL_V1_0 getBody: {}", response.getResponseCode(), response.getBody()); } diff --git a/elide-async/src/main/java/com/yahoo/elide/async/service/DefaultAsyncQueryDAO.java b/elide-async/src/main/java/com/yahoo/elide/async/service/DefaultAsyncQueryDAO.java index 24f785a341..df83e05383 100644 --- a/elide-async/src/main/java/com/yahoo/elide/async/service/DefaultAsyncQueryDAO.java +++ b/elide-async/src/main/java/com/yahoo/elide/async/service/DefaultAsyncQueryDAO.java @@ -184,7 +184,7 @@ protected Object executeInTransaction(DataStore dataStore, Transactional action) try (DataStoreTransaction tx = dataStore.beginTransaction()) { JsonApiDocument jsonApiDoc = new JsonApiDocument(); MultivaluedMap queryParams = new MultivaluedHashMap(); - RequestScope scope = new RequestScope("query", NO_VERSION, jsonApiDoc, + RequestScope scope = new RequestScope("", "query", NO_VERSION, jsonApiDoc, tx, null, queryParams, UUID.randomUUID(), elide.getElideSettings()); result = action.execute(tx, scope); tx.flush(scope); diff --git a/elide-async/src/test/java/com/yahoo/elide/async/service/AsyncQueryThreadTest.java b/elide-async/src/test/java/com/yahoo/elide/async/service/AsyncQueryThreadTest.java index c95e86172e..4ef990e5ac 100644 --- a/elide-async/src/test/java/com/yahoo/elide/async/service/AsyncQueryThreadTest.java +++ b/elide-async/src/test/java/com/yahoo/elide/async/service/AsyncQueryThreadTest.java @@ -53,7 +53,7 @@ public void testProcessQueryJsonApi() throws NoHttpResponseException, URISyntaxE queryObj.setId(id); queryObj.setQuery(query); queryObj.setQueryType(QueryType.JSONAPI_V1_0); - when(elide.get(anyString(), any(), any(), anyString(), any())).thenReturn(response); + when(elide.get(anyString(), anyString(), any(), any(), anyString(), any())).thenReturn(response); AsyncQueryThread queryThread = new AsyncQueryThread(queryObj, user, elide, runner, asyncQueryDao, "v1"); queryResultObj = queryThread.processQuery(); assertEquals(queryResultObj.getResponseBody(), "ResponseBody"); @@ -69,7 +69,7 @@ public void testProcessQueryGraphQl() throws NoHttpResponseException, URISyntaxE queryObj.setId(id); queryObj.setQuery(query); queryObj.setQueryType(QueryType.GRAPHQL_V1_0); - when(runner.run(eq(query), eq(user), any())).thenReturn(response); + when(runner.run(anyString(), eq(query), eq(user), any())).thenReturn(response); AsyncQueryThread queryThread = new AsyncQueryThread(queryObj, user, elide, runner, asyncQueryDao, "v1"); queryResultObj = queryThread.processQuery(); assertEquals(queryResultObj.getResponseBody(), "ResponseBody"); diff --git a/elide-core/src/main/java/com/yahoo/elide/Elide.java b/elide-core/src/main/java/com/yahoo/elide/Elide.java index ff65a074b6..c157207d7e 100644 --- a/elide-core/src/main/java/com/yahoo/elide/Elide.java +++ b/elide-core/src/main/java/com/yahoo/elide/Elide.java @@ -204,7 +204,7 @@ public ElideResponse get(String baseUrlEndPoint, String path, MultivaluedMap queryParams, + public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDocument, + MultivaluedMap queryParams, User opaqueUser, String apiVersion, UUID requestId) { return handleRequest(false, opaqueUser, dataStore::beginTransaction, requestId, (tx, user) -> { JsonApiDocument jsonApiDoc = mapper.readJsonApiDocument(jsonApiDocument); @@ -250,7 +251,7 @@ public ElideResponse post(String baseUrlEndPoint, String path, String jsonApiDoc public ElideResponse patch(String baseUrlEndPoint, String contentType, String accept, String path, String jsonApiDocument, User opaqueUser, String apiVersion) { - return patch(baseUrlEndPoint, contentType, accept, path, jsonApiDocument, + return patch(baseUrlEndPoint, contentType, accept, path, jsonApiDocument, null, opaqueUser, apiVersion, UUID.randomUUID()); } @@ -328,7 +329,7 @@ public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiD * @param requestId the request ID * @return Elide response object */ - public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiDocument, + public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiDocument, MultivaluedMap queryParams, User opaqueUser, String apiVersion, UUID requestId) { return handleRequest(false, opaqueUser, dataStore::beginTransaction, requestId, (tx, user) -> { diff --git a/elide-core/src/main/java/com/yahoo/elide/ElideSettingsBuilder.java b/elide-core/src/main/java/com/yahoo/elide/ElideSettingsBuilder.java index 698878c2e7..b0f4b87775 100644 --- a/elide-core/src/main/java/com/yahoo/elide/ElideSettingsBuilder.java +++ b/elide-core/src/main/java/com/yahoo/elide/ElideSettingsBuilder.java @@ -94,7 +94,7 @@ public ElideSettings build() { defaultMaxPageSize, defaultPageSize, updateStatusCode, - serdes, + serdes, enableJsonLinks); } diff --git a/elide-core/src/main/java/com/yahoo/elide/resources/JsonApiEndpoint.java b/elide-core/src/main/java/com/yahoo/elide/resources/JsonApiEndpoint.java index c0763589f5..1ed8ed1d38 100644 --- a/elide-core/src/main/java/com/yahoo/elide/resources/JsonApiEndpoint.java +++ b/elide-core/src/main/java/com/yahoo/elide/resources/JsonApiEndpoint.java @@ -68,7 +68,7 @@ public Response post( MultivaluedMap queryParams = uriInfo.getQueryParameters(); String safeApiVersion = apiVersion == null ? NO_VERSION : apiVersion; User user = new SecurityContextUser(securityContext); - return build(elide.post(uriInfo.getBaseUri().toString(), path, jsonapiDocument, + return build(elide.post(uriInfo.getBaseUri().toString(), path, jsonapiDocument, queryParams, user, safeApiVersion, UUID.randomUUID())); } @@ -121,7 +121,7 @@ public Response patch( String safeApiVersion = apiVersion == null ? NO_VERSION : apiVersion; User user = new SecurityContextUser(securityContext); - return build(elide.patch(uriInfo.getBaseUri().toString(), contentType, accept, path, + return build(elide.patch(uriInfo.getBaseUri().toString(), contentType, accept, path, jsonapiDocument, queryParams, user, safeApiVersion, UUID.randomUUID())); } @@ -147,7 +147,8 @@ public Response delete( MultivaluedMap queryParams = uriInfo.getQueryParameters(); String safeApiVersion = apiVersion == null ? NO_VERSION : apiVersion; User user = new SecurityContextUser(securityContext); - return build(elide.delete(uriInfo.getBaseUri(), path, jsonApiDocument, queryParams, user, safeApiVersion, UUID.randomUUID())); + return build(elide.delete(uriInfo.getBaseUri().toString(), path, jsonApiDocument, queryParams, + user, safeApiVersion, UUID.randomUUID())); } private static Response build(ElideResponse response) { diff --git a/elide-core/src/test/java/com/yahoo/elide/core/LifeCycleTest.java b/elide-core/src/test/java/com/yahoo/elide/core/LifeCycleTest.java index a5906587f4..e3554b6c1f 100644 --- a/elide-core/src/test/java/com/yahoo/elide/core/LifeCycleTest.java +++ b/elide-core/src/test/java/com/yahoo/elide/core/LifeCycleTest.java @@ -131,7 +131,6 @@ public void execute(LifeCycleHookBinding.Operation operation, } } - private final String baseUrl = "http://localhost:8080/api/v1"; static class ClassPreCommitHook implements LifeCycleHook { @Override public void execute(LifeCycleHookBinding.Operation operation, @@ -298,6 +297,7 @@ public void relationCallback(LifeCycleHookBinding.Operation operation, */ public class LifeCycleTest { + private final String baseUrl = "http://localhost:8080/api/v1"; private static final AuditLogger MOCK_AUDIT_LOGGER = mock(AuditLogger.class); private EntityDictionary dictionary; @@ -492,7 +492,7 @@ public void testElideGetRelationship() throws Exception { when(tx.loadObject(isA(EntityProjection.class), any(), isA(RequestScope.class))).thenReturn(mockModel); MultivaluedMap headers = new MultivaluedHashMap<>(); - ElideResponse response = elide.get("/testModel/1/relationships/models", headers, null, NO_VERSION); + ElideResponse response = elide.get(baseUrl, "/testModel/1/relationships/models", headers, null, NO_VERSION); assertEquals(HttpStatus.SC_OK, response.getResponseCode()); verify(mockModel, never()).classAllFieldsCallback(any(), any()); diff --git a/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java b/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java index 08f8bae750..463ac04369 100644 --- a/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java +++ b/elide-core/src/test/java/com/yahoo/elide/core/TestRequestScope.java @@ -22,10 +22,21 @@ public class TestRequestScope extends RequestScope { private MultivaluedMap queryParamOverrides = null; + public TestRequestScope(String baseURL, + DataStoreTransaction transaction, + User user, + EntityDictionary dictionary) { + super(baseURL, null, NO_VERSION, new JsonApiDocument(), transaction, user, null, UUID.randomUUID(), + new ElideSettingsBuilder(null) + .withEntityDictionary(dictionary) + .withJSONApiLinks(new DefaultJSONApiLinks()) + .build()); + } + public TestRequestScope(DataStoreTransaction transaction, User user, EntityDictionary dictionary) { - super(null, NO_VERSION, new JsonApiDocument(), transaction, user, null, UUID.randomUUID(), + super(null, null, NO_VERSION, new JsonApiDocument(), transaction, user, null, UUID.randomUUID(), new ElideSettingsBuilder(null) .withEntityDictionary(dictionary) .build()); @@ -34,7 +45,7 @@ public TestRequestScope(DataStoreTransaction transaction, public TestRequestScope(EntityDictionary dictionary, String path, MultivaluedMap queryParams) { - super(path, NO_VERSION, new JsonApiDocument(), null, null, queryParams, UUID.randomUUID(), + super(null, path, NO_VERSION, new JsonApiDocument(), null, null, queryParams, UUID.randomUUID(), new ElideSettingsBuilder(null) .withEntityDictionary(dictionary) .build()); diff --git a/elide-core/src/test/java/com/yahoo/elide/jsonapi/JsonApiTest.java b/elide-core/src/test/java/com/yahoo/elide/jsonapi/JsonApiTest.java index 9a12e6c1da..809afae80d 100644 --- a/elide-core/src/test/java/com/yahoo/elide/jsonapi/JsonApiTest.java +++ b/elide-core/src/test/java/com/yahoo/elide/jsonapi/JsonApiTest.java @@ -10,7 +10,6 @@ import static org.mockito.Mockito.mock; import com.yahoo.elide.core.DataStoreTransaction; -import com.yahoo.elide.core.DefaultJSONApiLinks; import com.yahoo.elide.core.EntityDictionary; import com.yahoo.elide.core.PersistentResource; import com.yahoo.elide.core.RequestScope; @@ -50,6 +49,7 @@ public class JsonApiTest { private JsonApiMapper mapper; private User user = new TestUser("0"); + private static String BASE_URL = "http://localhost:8080/json/"; private EntityDictionary dictionary; private DataStoreTransaction tx = mock(DataStoreTransaction.class, Answers.CALLS_REAL_METHODS); @@ -67,7 +67,7 @@ public void writeSingleNoAttributesNoRel() throws JsonProcessingException { Parent parent = new Parent(); parent.setId(123L); - RequestScope userScope = new TestRequestScope(tx, user, dictionary); + RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary); JsonApiDocument jsonApiDocument = new JsonApiDocument(); jsonApiDocument.setData(new Data<>(new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope).toResource())); @@ -104,7 +104,7 @@ public void writeSingle() throws JsonProcessingException { child.setParents(Collections.singleton(parent)); child.setFriends(new HashSet<>()); - RequestScope userScope = new TestRequestScope(tx, user, dictionary); + RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary); JsonApiDocument jsonApiDocument = new JsonApiDocument(); jsonApiDocument.setData(new Data<>(new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope).toResource())); @@ -141,7 +141,7 @@ public void writeSingleIncluded() throws JsonProcessingException { child.setParents(Collections.singleton(parent)); child.setFriends(new HashSet<>()); - RequestScope userScope = new TestRequestScope(tx, user, dictionary); + RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary); PersistentResource pRec = new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope); @@ -195,7 +195,7 @@ public void writeList() throws JsonProcessingException { parent.setFirstName("bob"); child.setFriends(new HashSet<>()); - RequestScope userScope = new TestRequestScope(tx, user, dictionary); + RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary); JsonApiDocument jsonApiDocument = new JsonApiDocument(); jsonApiDocument.setData( @@ -233,7 +233,7 @@ public void writeListIncluded() throws JsonProcessingException { parent.setFirstName("bob"); child.setFriends(new HashSet<>()); - RequestScope userScope = new TestRequestScope(tx, user, dictionary); + RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary); PersistentResource pRec = new PersistentResource<>(parent, null, userScope.getUUIDFor(parent), userScope); @@ -475,7 +475,7 @@ public void compareOrder() throws JsonProcessingException { Parent parent2 = new Parent(); parent2.setId(456L); - RequestScope userScope = new TestRequestScope(tx, user, dictionary); + RequestScope userScope = new TestRequestScope(BASE_URL, tx, user, dictionary); PersistentResource pRec1 = new PersistentResource<>(parent1, null, userScope.getUUIDFor(parent1), userScope); PersistentResource pRec2 = new PersistentResource<>(parent2, null, userScope.getUUIDFor(parent2), userScope); diff --git a/elide-datastore/elide-datastore-jpa/src/main/java/com/yahoo/elide/datastores/jpa/transaction/AbstractJpaTransaction.java b/elide-datastore/elide-datastore-jpa/src/main/java/com/yahoo/elide/datastores/jpa/transaction/AbstractJpaTransaction.java index b56804c8b4..92f78483ea 100644 --- a/elide-datastore/elide-datastore-jpa/src/main/java/com/yahoo/elide/datastores/jpa/transaction/AbstractJpaTransaction.java +++ b/elide-datastore/elide-datastore-jpa/src/main/java/com/yahoo/elide/datastores/jpa/transaction/AbstractJpaTransaction.java @@ -203,7 +203,7 @@ public Iterable loadObjects( if (pagination != null) { //Issue #1429 - if (pagination.returnPageTotals() && (!results.isEmpty() || p.getLimit() == 0)) { + if (pagination.returnPageTotals() && (!results.isEmpty() || pagination.getLimit() == 0)) { pagination.setPageTotals(getTotalRecords(entityClass, Optional.ofNullable(filterExpression), scope.getDictionary())); } diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLEndpoint.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLEndpoint.java index 93fd9bac89..b78773b165 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLEndpoint.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLEndpoint.java @@ -76,7 +76,7 @@ public Response post( if (runner == null) { response = buildErrorResponse(elide, new InvalidOperationException("Invalid API Version"), false); } else { - response = runner.run(graphQLDocument, user); + response = runner.run(uriInfo.getBaseUri().toString(), graphQLDocument, user); } return Response.status(response.getResponseCode()).entity(response.getBody()).build(); } diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLRequestScope.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLRequestScope.java index e5c2cde3aa..8792aa4684 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLRequestScope.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/GraphQLRequestScope.java @@ -39,7 +39,8 @@ public GraphQLRequestScope( // we should have a GraphQLRequestScope and a JSONAPIRequestScope. // TODO: What should mutate multiple entity value be? There is a problem with this setting in practice. // Namely, we don't filter or paginate in the data store. - super(baseUrlEndPoint, "/", apiVersion, null, transaction, user, new MultivaluedHashMap<>(), requestId, elideSettings); + super(baseUrlEndpoint, "/", apiVersion, null, transaction, user, + new MultivaluedHashMap<>(), requestId, elideSettings); this.projectionInfo = projectionInfo; // Entity Projection is retrieved from projectionInfo. diff --git a/elide-graphql/src/main/java/com/yahoo/elide/graphql/QueryRunner.java b/elide-graphql/src/main/java/com/yahoo/elide/graphql/QueryRunner.java index 8a50447e6a..06f5823f7f 100644 --- a/elide-graphql/src/main/java/com/yahoo/elide/graphql/QueryRunner.java +++ b/elide-graphql/src/main/java/com/yahoo/elide/graphql/QueryRunner.java @@ -93,7 +93,7 @@ public QueryRunner(Elide elide, String apiVersion) { * @return The response. */ public ElideResponse run(String baseUrlEndPoint, String graphQLDocument, User user) { - return run(graphQLDocument, user, UUID.randomUUID()); + return run(baseUrlEndPoint, graphQLDocument, user, UUID.randomUUID()); } /** diff --git a/elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLEndpointTest.java b/elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLEndpointTest.java index 7d2bee7447..7887534267 100644 --- a/elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLEndpointTest.java +++ b/elide-graphql/src/test/java/com/yahoo/elide/graphql/GraphQLEndpointTest.java @@ -360,7 +360,7 @@ void testCrypticErrorOnUpsert() throws IOException, JSONException { ) ).toQuery(); - Response response = endpoint.post(uriInfo, user2, graphQLRequestToJSON(graphQLRequest)); + Response response = endpoint.post(uriInfo, NO_VERSION, user2, graphQLRequestToJSON(graphQLRequest)); JsonNode node = extract200Response(response); Iterator errors = node.get("errors").elements(); assertTrue(errors.hasNext()); @@ -876,7 +876,7 @@ public void testMultipleRoot() throws JSONException { ).toResponse(); - Response response = endpoint.post(NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest)); + Response response = endpoint.post(uriInfo, NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest)); assert200EqualBody(response, graphQLResponse); } @@ -942,7 +942,7 @@ public void testMultipleQueryWithAlias() throws JSONException { ).toResponse(); - Response response = endpoint.post(NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest)); + Response response = endpoint.post(uriInfo, NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest)); assert200EqualBody(response, graphQLResponse); } @@ -1026,7 +1026,7 @@ public void testMultipleQueryWithAliasAndArguments() throws JSONException { variables.put("author1", "1"); variables.put("author2", "2"); - Response response = endpoint.post(NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest, variables)); + Response response = endpoint.post(uriInfo, NO_VERSION, user1, graphQLRequestToJSON(graphQLRequest, variables)); assert200EqualBody(response, graphQLResponse); } diff --git a/elide-graphql/src/test/java/com/yahoo/elide/graphql/PersistentResourceFetcherTest.java b/elide-graphql/src/test/java/com/yahoo/elide/graphql/PersistentResourceFetcherTest.java index f9ae43c3a8..a6389f4f94 100644 --- a/elide-graphql/src/test/java/com/yahoo/elide/graphql/PersistentResourceFetcherTest.java +++ b/elide-graphql/src/test/java/com/yahoo/elide/graphql/PersistentResourceFetcherTest.java @@ -252,7 +252,8 @@ protected void assertParsingFails(String graphQLRequest) { protected ExecutionResult runGraphQLRequest(String graphQLRequest, Map variables) { DataStoreTransaction tx = inMemoryDataStore.beginTransaction(); GraphQLProjectionInfo projectionInfo = new GraphQLEntityProjectionMaker(settings).make(graphQLRequest); - GraphQLRequestScope requestScope = new GraphQLRequestScope(tx, null, NO_VERSION, settings, projectionInfo, UUID.randomUUID()); + GraphQLRequestScope requestScope = new GraphQLRequestScope(baseUrl, tx, null, NO_VERSION, settings, + projectionInfo, UUID.randomUUID()); return api.execute(graphQLRequest, requestScope, variables); } diff --git a/elide-integration-tests/src/test/java/com/yahoo/elide/async/integration/tests/AsyncIT.java b/elide-integration-tests/src/test/java/com/yahoo/elide/async/integration/tests/AsyncIT.java index 72c0763252..97f1a1e636 100644 --- a/elide-integration-tests/src/test/java/com/yahoo/elide/async/integration/tests/AsyncIT.java +++ b/elide-integration-tests/src/test/java/com/yahoo/elide/async/integration/tests/AsyncIT.java @@ -724,16 +724,17 @@ public String getAuthenticationScheme() { } }); + String baseUrl = "/"; // Principal is Owner - response = elide.get("/asyncQuery/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION); + response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION); assertEquals(HttpStatus.SC_OK, response.getResponseCode()); // Principal has Admin Role - response = elide.get("/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION); + response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION); assertEquals(HttpStatus.SC_OK, response.getResponseCode()); // Principal without Admin Role - response = elide.get("/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION); + response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION); assertEquals(HttpStatus.SC_FORBIDDEN, response.getResponseCode()); } diff --git a/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/ControllerTest.java b/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/ControllerTest.java index 633616a6d2..368b03cec8 100644 --- a/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/ControllerTest.java +++ b/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/ControllerTest.java @@ -34,7 +34,9 @@ import com.yahoo.elide.contrib.testhelpers.graphql.GraphQLDSL; import com.yahoo.elide.core.HttpStatus; import com.yahoo.elide.spring.controllers.JsonApiController; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlMergeMode; @@ -50,14 +52,22 @@ + "\t\t('com.example.repository','Example Repository','The code for this project', false);") @Sql(executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, statements = "DELETE FROM ArtifactVersion; DELETE FROM ArtifactProduct; DELETE FROM ArtifactGroup;") +@Import(IntegrationTestSetup.class) public class ControllerTest extends IntegrationTest { - private String hostname = "localhost"; + private String baseUrl; + + @BeforeAll + @Override + public void setUp() { + super.setUp(); + baseUrl = "http://localhost:" + port + "/json/"; + } + /** * This test demonstrates an example test using the JSON-API DSL. */ @Test public void jsonApiGetTest() { - String baseUrl = "http://" + hostname + ":" + port + "/json/"; when() .get("/json/group") .then() @@ -103,6 +113,9 @@ public void versionedJsonApiGetTest() { id("com.example.repository"), attributes( attr("title", "Example Repository") + ), + links( + attr("self", baseUrl + "group/com.example.repository") ) ) ).toJSON()) @@ -112,7 +125,6 @@ public void versionedJsonApiGetTest() { @Test public void jsonApiPatchTest() { - String baseUrl = "http://" + hostname + ":" + port + "/json/"; given() .contentType(JsonApiController.JSON_API_CONTENT_TYPE) .body( @@ -212,7 +224,6 @@ public void jsonApiPatchExtensionTest() { @Test public void jsonApiPostTest() { - String baseUrl = "http://" + hostname + ":" + port + "/json/"; given() .contentType(JsonApiController.JSON_API_CONTENT_TYPE) .body( diff --git a/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTest.java b/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTest.java index ed55ebf7e2..c37a13575b 100644 --- a/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTest.java +++ b/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTest.java @@ -9,7 +9,6 @@ import org.junit.jupiter.api.TestInstance; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.annotation.Import; import io.restassured.RestAssured; @@ -21,7 +20,6 @@ */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestInstance(TestInstance.Lifecycle.PER_CLASS) -@Import(IntegrationTestSetup.class) public class IntegrationTest { @LocalServerPort diff --git a/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTestSetup.java b/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTestSetup.java index ae4ae53900..f50086c000 100644 --- a/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTestSetup.java +++ b/elide-spring/elide-spring-boot-autoconfigure/src/test/java/example/tests/IntegrationTestSetup.java @@ -3,7 +3,7 @@ * Licensed under the Apache License, Version 2.0 * See LICENSE file in project root for terms. */ -package com.yahoo.elide.spring.tests; +package example.tests; import com.yahoo.elide.Elide; import com.yahoo.elide.ElideSettingsBuilder; @@ -33,11 +33,9 @@ public Elide initializeElide(EntityDictionary dictionary, .withDefaultMaxPageSize(settings.getMaxPageSize()) .withDefaultPageSize(settings.getPageSize()) .withJSONApiLinks(new DefaultJSONApiLinks()) - .withUseFilterExpressions(true) .withJoinFilterDialect(new RSQLFilterDialect(dictionary)) .withSubqueryFilterDialect(new RSQLFilterDialect(dictionary)) .withAuditLogger(new Slf4jLogger()) - .withEncodeErrorResponses(true) .withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")); return new Elide(builder.build());