Skip to content

Commit

Permalink
Resolves #2784 (#2785)
Browse files Browse the repository at this point in the history
* Resolves #2784

* Cleaned up imports
  • Loading branch information
aklish committed Sep 21, 2022
1 parent 362842b commit c61859e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public ResponseEntity<String> call() throws Exception {
};
}

@PatchMapping(value = "/**", consumes = { JSON_API_CONTENT_TYPE, JSON_API_PATCH_CONTENT_TYPE})
@PatchMapping(
value = "/**",
consumes = { JSON_API_CONTENT_TYPE, JSON_API_PATCH_CONTENT_TYPE},
produces = JSON_API_CONTENT_TYPE
)
public Callable<ResponseEntity<String>> elidePatch(@RequestHeader HttpHeaders requestHeaders,
@RequestParam MultiValueMap<String, String> allRequestParams,
@RequestBody String body,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2022, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package example.tests;

import static io.restassured.RestAssured.given;

import com.yahoo.elide.core.exceptions.HttpStatus;
import com.yahoo.elide.spring.controllers.JsonApiController;
import com.yahoo.elide.test.jsonapi.JsonApiDSL;
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;

/**
* Verifies 200 Status for patch Requests.
*/
@Import(Update200StatusTestSetup.class)
@SqlMergeMode(SqlMergeMode.MergeMode.MERGE)
@Sql(
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD,
scripts = "classpath:db/test_init.sql",
statements = "INSERT INTO ArtifactGroup (name, commonName, description, deprecated) VALUES\n"
+ "\t\t('com.example.repository','Example Repository','The code for this project', false);"
)
public class Update200StatusTest extends IntegrationTest {
private String baseUrl;

@BeforeAll
@Override
public void setUp() {
super.setUp();
baseUrl = "https://elide.io/json/";
}

@Test
public void jsonApiPatchTest() {
given()
.contentType(JsonApiController.JSON_API_CONTENT_TYPE)
.body(
JsonApiDSL.datum(
JsonApiDSL.resource(
JsonApiDSL.type("group"),
JsonApiDSL.id("com.example.repository"),
JsonApiDSL.attributes(
JsonApiDSL.attr("commonName", "Changed It.")
)
)
)
)
.when()
.patch("/json/group/com.example.repository")
.then()
.contentType(JsonApiController.JSON_API_CONTENT_TYPE)
.statusCode(HttpStatus.SC_OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2022, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package example.tests;

import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettingsBuilder;
import com.yahoo.elide.RefreshableElide;
import com.yahoo.elide.core.TransactionRegistry;
import com.yahoo.elide.core.audit.Slf4jLogger;
import com.yahoo.elide.core.datastore.DataStore;
import com.yahoo.elide.core.dictionary.EntityDictionary;
import com.yahoo.elide.core.exceptions.ErrorMapper;
import com.yahoo.elide.core.filter.dialect.RSQLFilterDialect;
import com.yahoo.elide.jsonapi.JsonApiMapper;
import com.yahoo.elide.spring.config.ElideConfigProperties;
import com.yahoo.elide.utils.HeaderUtils;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;

import java.util.TimeZone;

@TestConfiguration
public class Update200StatusTestSetup {
@Bean
public RefreshableElide getRefreshableElide(EntityDictionary dictionary,
DataStore dataStore,
HeaderUtils.HeaderProcessor headerProcessor,
TransactionRegistry transactionRegistry,
ElideConfigProperties settings,
JsonApiMapper mapper,
ErrorMapper errorMapper) {

ElideSettingsBuilder builder = new ElideSettingsBuilder(dataStore)
.withEntityDictionary(dictionary)
.withErrorMapper(errorMapper)
.withJsonApiMapper(mapper)
.withDefaultMaxPageSize(settings.getMaxPageSize())
.withDefaultPageSize(settings.getPageSize())
.withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build())
.withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build())
.withAuditLogger(new Slf4jLogger())
.withBaseUrl(settings.getBaseUrl())
.withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
.withJsonApiPath(settings.getJsonApi().getPath())
.withHeaderProcessor(headerProcessor)
.withGraphQLApiPath(settings.getGraphql().getPath())
.withUpdate200Status();

Elide elide = new Elide(builder.build(), transactionRegistry, dictionary.getScanner(), true);

return new RefreshableElide(elide);
}
}

0 comments on commit c61859e

Please sign in to comment.