Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing codestart tests #20876

Merged
merged 3 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.devtools.codestarts.quarkus;

import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA;

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 FunqyGoogleCloudFunctionsCodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("funqy-google-cloud-functions")
.languages(JAVA)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.funqygooglecloudfunctions.GreetingFunctions");
codestartTest.checkGeneratedSource("org.acme.funqygooglecloudfunctions.GreetingService");
}

@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,29 @@
package io.quarkus.devtools.codestarts.quarkus;

import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA;

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 GoogleCloudFunctionsCodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("google-cloud-functions")
.languages(JAVA)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.HelloWorldBackgroundFunction");
codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.HelloWorldHttpFunction");
}

@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,31 @@
package io.quarkus.devtools.codestarts.quarkus;

import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA;

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 GoogleCloudFunctionsHttpCodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("google-cloud-functions-http")
.languages(JAVA)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingFunqy");
codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingResource");
codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingRoutes");
codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingServlet");
}

@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,26 @@
package ilove.quark.us.funqygooglecloudfunctions;

import javax.inject.Inject;

import io.quarkus.funqy.Funq;
import io.quarkus.funqy.gcp.functions.event.PubsubMessage;
import io.quarkus.funqy.gcp.functions.event.StorageEvent;

public class GreetingFunctions {

@Inject
GreetingService service;

@Funq
public void helloPubSubWorld(PubsubMessage pubSubEvent) {
String message = service.hello("world");
System.out.println(pubSubEvent.messageId + " - " + message);
}

@Funq
public void helloGCSWorld(StorageEvent storageEvent) {
String message = service.hello("world");
System.out.println(storageEvent.name + " - " + message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ilove.quark.us.funqygooglecloudfunctions;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class GreetingService {
private String greeting = "Hello";
private String punctuation = "!";

public void setGreeting(String greet) {
greeting = greet;
}

public void setPunctuation(String punctuation) {
this.punctuation = punctuation;
}

public String hello(String val) {
return greeting + " " + val + punctuation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ilove.quark.us.googlecloudfunctions;

import javax.enterprise.context.ApplicationScoped;

import com.google.cloud.functions.BackgroundFunction;
import com.google.cloud.functions.Context;

@ApplicationScoped
public class HelloWorldBackgroundFunction implements BackgroundFunction<HelloWorldBackgroundFunction.StorageEvent> {

@Override
public void accept(StorageEvent event, Context context) throws Exception {
System.out.println("Receive event on file: " + event.name);
}

public static class StorageEvent {
public String name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ilove.quark.us.googlecloudfunctions;

import java.io.Writer;

import javax.enterprise.context.ApplicationScoped;

import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;

@ApplicationScoped
public class HelloWorldHttpFunction implements HttpFunction {

@Override
public void service(HttpRequest httpRequest, HttpResponse httpResponse) throws Exception {
Writer writer = httpResponse.getWriter();
writer.write("Hello World");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ilove.quark.us.googlecloudfunctionshttp;

import io.quarkus.funqy.Funq;
import io.smallrye.mutiny.Uni;

public class GreetingFunqy {

@Funq
public String funqy() {
return "Make it funqy";
}

@Funq
public Uni<String> funqyAsync() {
return Uni.createFrom().item(() -> "Make it funqy asynchronously");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ilove.quark.us.googlecloudfunctionshttp;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}

@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public String hello(String name) {
return "hello " + name;
}

@POST
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public byte[] hello(byte[] bytes) {
if (bytes[0] != 0 || bytes[1] != 1 || bytes[2] != 2 || bytes[3] != 3) {
throw new RuntimeException("bad input");
}
byte[] rtn = { 4, 5, 6 };
return rtn;
}

@POST
@Path("empty")
public void empty() {

}

@GET
@Path("error")
public void error() {
throw new RuntimeException("Oups!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ilove.quark.us.googlecloudfunctionshttp;

import static io.quarkus.vertx.web.Route.HttpMethod.GET;

import io.quarkus.vertx.web.Route;
import io.vertx.ext.web.RoutingContext;

public class GreetingRoutes {
@Route(path = "/vertx/hello", methods = GET)
void hello(RoutingContext context) {
context.response().headers().set("Content-Type", "text/plain");
context.response().setStatusCode(200).end("hello");
}

@Route(path = "/vertx/error", methods = GET)
void error(RoutingContext context) {
context.response().headers().set("Content-Type", "text/plain");
context.response().setStatusCode(500).end("Oups!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ilove.quark.us.googlecloudfunctionshttp;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "ServletGreeting", urlPatterns = "/servlet/hello")
public class GreetingServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(200);
resp.addHeader("Content-Type", "text/plain");
resp.getWriter().write("hello");
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name = req.getReader().readLine();
resp.setStatus(200);
resp.addHeader("Content-Type", "text/plain");
resp.getWriter().write("hello " + name);
}
}