Skip to content

Commit

Permalink
REST Client codestart
Browse files Browse the repository at this point in the history
  • Loading branch information
xstefank committed Nov 5, 2021
1 parent acf71a8 commit ae164b0
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#include readme-header /}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<Extension> getExtensionsById(@QueryParam("id") String id);

class Extension {
public String id;
public String name;
public String shortName;
public List<String> keywords;
}
}
Original file line number Diff line number Diff line change
@@ -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<MyRemoteService.Extension> 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"));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Extension>

data class Extension(val id: String, val name: String, val shortName: String, val keywords: List<String>)
}
Original file line number Diff line number Diff line change
@@ -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"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ metadata:
- "microprofile-rest-client"
guide: "https://quarkus.io/guides/rest-client"
categories:
- "web"
- "web"
codestart:
name: "rest-client"
languages:
- "java"
- "kotlin"
artifact: "io.quarkus:quarkus-project-core-extension-codestarts"
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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<Extension> getExtensionsById(@QueryParam("id") String id);

class Extension {
public String id;
public String name;
public String shortName;
public List<String> keywords;
}
}
Original file line number Diff line number Diff line change
@@ -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<Extension>

data class Extension(val id: String, val name: String, val shortName: String, val keywords: List<String>)
}
Original file line number Diff line number Diff line change
@@ -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<MyRemoteService.Extension> 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"));
}
}
}
Original file line number Diff line number Diff line change
@@ -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"))
}
}
}

0 comments on commit ae164b0

Please sign in to comment.