From ae164b0e8ea51002902e7aecc4ac8ff5608cce9f Mon Sep 17 00:00:00 2001 From: xstefank Date: Fri, 5 Nov 2021 14:11:37 +0100 Subject: [PATCH] REST Client codestart --- .../base/README.tpl.qute.md | 1 + .../rest-client-codestart/codestart.yml | 13 ++++++++ .../main/java/org/acme/MyRemoteService.java | 24 ++++++++++++++ .../java/org/acme/MyRemoteServiceTest.java | 31 ++++++++++++++++++ .../main/kotlin/org/acme/MyRemoteService.kt | 16 ++++++++++ .../kotlin/org/acme/MyRemoteServiceTest.kt | 28 ++++++++++++++++ .../resources/META-INF/quarkus-extension.yaml | 8 ++++- .../quarkus/RESTClientCodestartTest.java | 32 +++++++++++++++++++ ...n_java_ilove_quark_us_MyRemoteService.java | 24 ++++++++++++++ ...n_kotlin_ilove_quark_us_MyRemoteService.kt | 16 ++++++++++ ...va_ilove_quark_us_MyRemoteServiceTest.java | 31 ++++++++++++++++++ ...tlin_ilove_quark_us_MyRemoteServiceTest.kt | 28 ++++++++++++++++ 12 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/test/java/org/acme/MyRemoteServiceTest.java create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/test/kotlin/org/acme/MyRemoteServiceTest.kt create mode 100644 integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTClientCodestartTest.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_java_ilove_quark_us_MyRemoteService.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyRemoteService.kt create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_java_ilove_quark_us_MyRemoteServiceTest.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_kotlin_ilove_quark_us_MyRemoteServiceTest.kt diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md new file mode 100644 index 0000000000000..405280158877d --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md @@ -0,0 +1 @@ +{#include readme-header /} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml new file mode 100644 index 0000000000000..067c3561eecbf --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml @@ -0,0 +1,13 @@ +name: rest-client-codestart +ref: rest-client +type: code +tags: extension-codestart +metadata: + title: REST Client + description: Invoke different services through REST with JSON + related-guide-section: https://quarkus.io/guides/rest-client +language: + base: + dependencies: + - io.quarkus:quarkus-rest-client + - io.quarkus:quarkus-rest-client-jackson diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java new file mode 100644 index 0000000000000..29025089d4292 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java @@ -0,0 +1,24 @@ +package org.acme; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import java.util.List; +import java.util.Set; + +@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api") +public interface MyRemoteService { + + @GET + @Path("/extensions") + Set getExtensionsById(@QueryParam("id") String id); + + class Extension { + public String id; + public String name; + public String shortName; + public List keywords; + } +} diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/test/java/org/acme/MyRemoteServiceTest.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/test/java/org/acme/MyRemoteServiceTest.java new file mode 100644 index 0000000000000..c98427afd9c0e --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/test/java/org/acme/MyRemoteServiceTest.java @@ -0,0 +1,31 @@ +package org.acme; + +import io.quarkus.test.junit.QuarkusTest; +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; +import java.util.Set; + +@QuarkusTest +public class MyRemoteServiceTest { + + @Inject + @RestClient + MyRemoteService myRemoteService; + + @Test + public void testExtensionsRestClientEndpoint() { + Set restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-rest-client"); + + Assertions.assertEquals(1, restClientExtensions.size()); + for (MyRemoteService.Extension extension : restClientExtensions) { + Assertions.assertEquals("io.quarkus:quarkus-rest-client", extension.id); + Assertions.assertEquals("REST Client", extension.name); + Assertions.assertEquals("REST Client", extension.shortName); + Assertions.assertTrue(extension.keywords.size() > 1); + Assertions.assertTrue(extension.keywords.contains("rest-client")); + } + } +} diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt new file mode 100644 index 0000000000000..337aba7d297f8 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt @@ -0,0 +1,16 @@ +package org.acme + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient +import javax.ws.rs.GET +import javax.ws.rs.Path +import javax.ws.rs.QueryParam + +@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api") +interface MyRemoteService { + + @GET + @Path("/extensions") + fun getExtensionsById(@QueryParam("id") id: String): Set + + data class Extension(val id: String, val name: String, val shortName: String, val keywords: List) +} diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/test/kotlin/org/acme/MyRemoteServiceTest.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/test/kotlin/org/acme/MyRemoteServiceTest.kt new file mode 100644 index 0000000000000..647ace46ef974 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/test/kotlin/org/acme/MyRemoteServiceTest.kt @@ -0,0 +1,28 @@ +package org.acme + +import io.quarkus.test.junit.QuarkusTest +import org.eclipse.microprofile.rest.client.inject.RestClient +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import javax.inject.Inject + +@QuarkusTest +class MyRemoteServiceTest { + + @Inject + @RestClient + lateinit var myRemoteService: MyRemoteService + + @Test + fun testRestClientEndpoint() { + val restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-rest-client") + Assertions.assertEquals(1, restClientExtensions.size) + restClientExtensions.forEach { + Assertions.assertEquals("io.quarkus:quarkus-rest-client", it.id) + Assertions.assertEquals("REST Client", it.name) + Assertions.assertEquals("REST Client", it.shortName) + Assertions.assertTrue(it.keywords.size > 1) + Assertions.assertTrue(it.keywords.contains("rest-client")) + } + } +} diff --git a/extensions/resteasy-classic/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/resteasy-classic/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml index f9c87a42a1fbb..a52b3fe35944b 100644 --- a/extensions/resteasy-classic/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/resteasy-classic/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -8,4 +8,10 @@ metadata: - "microprofile-rest-client" guide: "https://quarkus.io/guides/rest-client" categories: - - "web" \ No newline at end of file + - "web" + codestart: + name: "rest-client" + languages: + - "java" + - "kotlin" + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTClientCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTClientCodestartTest.java new file mode 100644 index 0000000000000..6fed63beab440 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/RESTClientCodestartTest.java @@ -0,0 +1,32 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; + +public class RESTClientCodestartTest { + + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("rest-client") + .languages(JAVA, KOTLIN) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.MyRemoteService"); + codestartTest.checkGeneratedTestSource("org.acme.MyRemoteServiceTest"); + } + + @Test + @EnabledIfSystemProperty(named = "build-projects", matches = "true") + void buildAllProjectsForLocalUse() throws Throwable { + codestartTest.buildAllProjects(); + } + +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_java_ilove_quark_us_MyRemoteService.java b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_java_ilove_quark_us_MyRemoteService.java new file mode 100644 index 0000000000000..9ef7c31b4701e --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_java_ilove_quark_us_MyRemoteService.java @@ -0,0 +1,24 @@ +package ilove.quark.us; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import java.util.List; +import java.util.Set; + +@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api") +public interface MyRemoteService { + + @GET + @Path("/extensions") + Set getExtensionsById(@QueryParam("id") String id); + + class Extension { + public String id; + public String name; + public String shortName; + public List keywords; + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyRemoteService.kt b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyRemoteService.kt new file mode 100644 index 0000000000000..67abb8e5071ff --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyRemoteService.kt @@ -0,0 +1,16 @@ +package ilove.quark.us + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient +import javax.ws.rs.GET +import javax.ws.rs.Path +import javax.ws.rs.QueryParam + +@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api") +interface MyRemoteService { + + @GET + @Path("/extensions") + fun getExtensionsById(@QueryParam("id") id: String): Set + + data class Extension(val id: String, val name: String, val shortName: String, val keywords: List) +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_java_ilove_quark_us_MyRemoteServiceTest.java b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_java_ilove_quark_us_MyRemoteServiceTest.java new file mode 100644 index 0000000000000..44c5fd514601a --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_java_ilove_quark_us_MyRemoteServiceTest.java @@ -0,0 +1,31 @@ +package ilove.quark.us; + +import io.quarkus.test.junit.QuarkusTest; +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; +import java.util.Set; + +@QuarkusTest +public class MyRemoteServiceTest { + + @Inject + @RestClient + MyRemoteService myRemoteService; + + @Test + public void testExtensionsRestClientEndpoint() { + Set restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-rest-client"); + + Assertions.assertEquals(1, restClientExtensions.size()); + for (MyRemoteService.Extension extension : restClientExtensions) { + Assertions.assertEquals("io.quarkus:quarkus-rest-client", extension.id); + Assertions.assertEquals("REST Client", extension.name); + Assertions.assertEquals("REST Client", extension.shortName); + Assertions.assertTrue(extension.keywords.size() > 1); + Assertions.assertTrue(extension.keywords.contains("rest-client")); + } + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_kotlin_ilove_quark_us_MyRemoteServiceTest.kt b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_kotlin_ilove_quark_us_MyRemoteServiceTest.kt new file mode 100644 index 0000000000000..c89c066c68b80 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/RESTClientCodestartTest/testContent/src_test_kotlin_ilove_quark_us_MyRemoteServiceTest.kt @@ -0,0 +1,28 @@ +package ilove.quark.us + +import io.quarkus.test.junit.QuarkusTest +import org.eclipse.microprofile.rest.client.inject.RestClient +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import javax.inject.Inject + +@QuarkusTest +class MyRemoteServiceTest { + + @Inject + @RestClient + lateinit var myRemoteService: MyRemoteService + + @Test + fun testRestClientEndpoint() { + val restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-rest-client") + Assertions.assertEquals(1, restClientExtensions.size) + restClientExtensions.forEach { + Assertions.assertEquals("io.quarkus:quarkus-rest-client", it.id) + Assertions.assertEquals("REST Client", it.name) + Assertions.assertEquals("REST Client", it.shortName) + Assertions.assertTrue(it.keywords.size > 1) + Assertions.assertTrue(it.keywords.contains("rest-client")) + } + } +}