Skip to content

Commit

Permalink
add_redirects_after_path_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierfacq committed Apr 20, 2024
1 parent a8e8136 commit 3c3b6ac
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object OpenApiDocs {
</p>
<p>
Available Feature versions can be obtained from
<a href="${ServerConfig.SERVER}/v3/info/available_releases">${ServerConfig.SERVER}/v3/info/available_releases</a>
<a href="${ServerConfig.SERVER}/v3/info/available/releases">${ServerConfig.SERVER}/v3/info/available/releases</a>
</p>
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import jakarta.ws.rs.core.UriInfo
import net.adoptium.api.v3.models.Architecture
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.tags.Tag
Expand All @@ -14,8 +16,21 @@ import org.eclipse.microprofile.openapi.annotations.tags.Tag
@Produces(MediaType.APPLICATION_JSON)
@ApplicationScoped
class AvailableArchitecturesResource {

@GET
@Path("/available_architectures")
@Deprecated("Use the new get() method with new path /available/architectures")
fun get301(uriInfo: UriInfo): Response {
val location = uriInfo.requestUriBuilder.replacePath("/v3/info/available/architectures").build()
return Response
.status(Response.Status.MOVED_PERMANENTLY)
.location(location)
.entity(Architecture.values().map { it.name }.toList())
.build()
}

@GET
@Path("/available/architectures")
@Operation(summary = "Returns names of available architectures", operationId = "getAvailableArchitectures")
fun get(): List<String> {
return Architecture.values().map { it.name }.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import jakarta.ws.rs.core.UriInfo
import net.adoptium.api.v3.models.OperatingSystem
import org.eclipse.microprofile.openapi.annotations.Operation
import org.eclipse.microprofile.openapi.annotations.tags.Tag
Expand All @@ -14,8 +16,21 @@ import org.eclipse.microprofile.openapi.annotations.tags.Tag
@Produces(MediaType.APPLICATION_JSON)
@ApplicationScoped
class AvailableOperatingSystemsResource {

@GET
@Path("/available_operating-systems")
@Deprecated("Use the new get() method with new path /available/operating-systems")
fun get301(uriInfo: UriInfo): Response {
val location = uriInfo.requestUriBuilder.replacePath("/v3/info/available/operating-systems").build()
return Response
.status(Response.Status.MOVED_PERMANENTLY)
.location(location)
.entity(OperatingSystem.values().map { it.name }.toList())
.build()
}

@GET
@Path("/available/operating-systems")
@Operation(summary = "Returns names of available operating systems", operationId = "getAvailableOperatingSystems")
fun get(): List<String> {
return OperatingSystem.values().map { it.name }.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import jakarta.ws.rs.core.UriInfo

@Tag(name = "Release Info")
@Path("/v3/info")
Expand All @@ -20,8 +22,21 @@ class AvailableReleasesResource
constructor(
private val apiDataStore: APIDataStore
) {

@GET
@Path("/available_releases")
@Deprecated("Use the new get() method with new path /available/releases")
fun get301(uriInfo: UriInfo): Response {
val location = uriInfo.requestUriBuilder.replacePath("/v3/info/available/releases").build()
return Response
.status(Response.Status.MOVED_PERMANENTLY)
.location(location)
.entity(apiDataStore.getReleaseInfo())
.build()
}

@GET
@Path("/available/releases")
@Operation(summary = "Returns information about available releases", operationId = "getAvailableReleases")
fun get(): ReleaseInfo {
return apiDataStore.getReleaseInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
package net.adoptium.api

import io.restassured.RestAssured
import io.restassured.config.RedirectConfig
import net.adoptium.api.v3.JsonMapper
import net.adoptium.api.v3.models.Architecture
import org.junit.jupiter.api.Test

class AvailableArchitecturesPathTest : FrontendTest() {

@Test
fun availableArchitectures() {
fun availableArchitectures_deprecated() {
RestAssured.given()
.config(RestAssured.config().redirect(RedirectConfig.redirectConfig().followRedirects(false)))
.`when`()
.get("/v3/info/available_architectures")
.then()
.statusCode(301)
}

@Test
fun availableArchitectures() {
RestAssured.given()
.`when`()
.get("/v3/info/available/architectures")
.then()
.statusCode(200)
}

@Test
fun availableArchitecturesAreCorrect() {
var body = RestAssured.given()
.`when`()
.get("/v3/info/available_architectures")
.get("/v3/info/available/architectures")
.body

val architectures = parseArchitectures(body.asString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
package net.adoptium.api

import io.restassured.RestAssured
import io.restassured.config.RedirectConfig
import net.adoptium.api.v3.JsonMapper
import net.adoptium.api.v3.models.OperatingSystem
import org.junit.jupiter.api.Test

class AvailableOperatingSystemsPathTest : FrontendTest() {

@Test
fun availableOperatingSystems() {
fun availableOperatingSystems_deprecated() {
RestAssured.given()
.config(RestAssured.config().redirect(RedirectConfig.redirectConfig().followRedirects(false)))
.`when`()
.get("/v3/info/available_operating-systems")
.then()
.statusCode(301)
}

@Test
fun availableOperatingSystems() {
RestAssured.given()
.`when`()
.get("/v3/info/available/operating-systems")
.then()
.statusCode(200)
}

@Test
fun availableOperatingSystemsAreCorrect() {
var body = RestAssured.given()
.`when`()
.get("/v3/info/available_operating-systems")
.get("/v3/info/available/operating-systems")
.body

val operatingSystems = parseOperatingSystems(body.asString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.adoptium.api

import io.quarkus.test.junit.QuarkusTest
import io.restassured.RestAssured
import io.restassured.config.RedirectConfig
import net.adoptium.api.v3.JsonMapper
import net.adoptium.api.v3.models.ReleaseInfo
import org.hamcrest.Description
Expand All @@ -12,11 +13,21 @@ import org.junit.jupiter.api.Test
class AvailableReleasesPathTest : FrontendTest() {

@Test
fun availableReleases() {
fun availableReleases_deprecated() {
RestAssured.given()
.config(RestAssured.config().redirect(RedirectConfig.redirectConfig().followRedirects(false)))
.`when`()
.get("/v3/info/available_releases")
.then()
.statusCode(301)
}

@Test
fun availableReleases() {
RestAssured.given()
.`when`()
.get("/v3/info/available/releases")
.then()
.statusCode(200)
}

Expand Down Expand Up @@ -58,7 +69,7 @@ class AvailableReleasesPathTest : FrontendTest() {
private fun check(matcher: (ReleaseInfo) -> Boolean) {
RestAssured.given()
.`when`()
.get("/v3/info/available_releases")
.get("/v3/info/available/releases")
.then()
.body(object : TypeSafeMatcher<String>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JsonSerializationTest : FrontendTest() {
fun isPrettyPrinted() {
RestAssured.given()
.`when`()
.get("/v3/info/available_releases")
.get("/v3/info/available/releases")
.then()
.statusCode(200)
.body(PrettyPrintMatcher())
Expand Down
4 changes: 2 additions & 2 deletions docs/cookbook.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ to build more complex queries, including access to nightly builds, debug builds,
The first example is a simple API query that returns the list of Java versions available from Adoptium, including the regular and long term supported (LTS) versions. The API doesn't take any arguments, and returns a JSON formatted list of versions.

[source,html]
https://api.adoptium.net/v3/info/available_releases
https://api.adoptium.net/v3/info/available/releases

open that link in a browser and the result will be something like this

Expand Down Expand Up @@ -46,7 +46,7 @@ For example, to get the most recent LTS version available you can use:

[source, bash]
----
$ curl -s https://api.adoptium.net/v3/info/available_releases | jq '.most_recent_lts'
$ curl -s https://api.adoptium.net/v3/info/available/releases | jq '.most_recent_lts'
17
----

Expand Down

0 comments on commit 3c3b6ac

Please sign in to comment.