Skip to content

Commit

Permalink
Merge pull request #29974 from loicmathieu/missing-codestart-tests
Browse files Browse the repository at this point in the history
Add missing IT for codestart examples
  • Loading branch information
gsmet authored Dec 20, 2022
2 parents aa4ff64 + 6814dc1 commit 3534e9d
Show file tree
Hide file tree
Showing 19 changed files with 361 additions and 0 deletions.
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 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 AmazonLambdaCodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("amazon-lambda")
.languages(JAVA)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.lambda.GreetingLambda");
codestartTest.checkGeneratedSource("org.acme.lambda.Person");

codestartTest.checkGeneratedTestSource("org.acme.lambda.LambdaHandlerTest");
codestartTest.checkGeneratedTestSource("org.acme.lambda.LambdaHandlerTestIT");
}

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

@Test
void testContent() throws Throwable {
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "azure-config/function.json");
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "azure-config/host.json");
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "azure-config/local.settings.json");
}

@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,32 @@
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 FunqyAmazonLambdaCodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("funqy-amazon-lambda")
.languages(JAVA)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.funqy.GreetingFunction");
codestartTest.checkGeneratedSource("org.acme.funqy.Person");

codestartTest.checkGeneratedTestSource("org.acme.funqy.FunqyTest");
codestartTest.checkGeneratedTestSource("org.acme.funqy.FunqyIT");
}

@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,32 @@
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 FunqyKnativeEventsCodestartTest {
@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder()
.codestarts("funqy-knative-events")
.languages(JAVA)
.build();

@Test
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.funqy.cloudevent.CloudEventGreeting");
codestartTest.checkGeneratedSource("org.acme.funqy.cloudevent.Person");

codestartTest.checkGeneratedTestSource("org.acme.funqy.cloudevent.FunqyTest");
codestartTest.checkGeneratedTestSource("org.acme.funqy.cloudevent.FunqyIT");
}

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

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class GreetingLambda implements RequestHandler<Person, String> {

@Override
public String handleRequest(Person input, Context context) {
return "Hello " + input.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ilove.quark.us.lambda;

public class Person {

private String name;

public String getName() {
return name;
}

public Person setName(String name) {
this.name = name;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ilove.quark.us.lambda;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

@QuarkusTest
public class LambdaHandlerTest {

@Test
public void testSimpleLambdaSuccess() throws Exception {
// you test your lambdas by invoking on http://localhost:8081
// this works in dev mode too

Person in = new Person();
in.setName("Stu");
given()
.contentType("application/json")
.accept("application/json")
.body(in)
.when()
.post()
.then()
.statusCode(200)
.body(containsString("Hello Stu"));
}

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

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class LambdaHandlerTestIT extends LambdaHandlerTest {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"scriptFile" : "../test-codestart-1.0.0-codestart.jar",
"entryPoint" : "io.quarkus.azure.functions.resteasy.runtime.Function.run",
"bindings" : [ {
"type" : "httpTrigger",
"direction" : "in",
"name" : "req",
"route" : "{*path}",
"methods" : [ "GET", "POST", "HEAD", "PUT", "OPTIONS", "DELETE" ],
"dataType" : "binary",
"authLevel" : "ANONYMOUS"
}, {
"type" : "http",
"direction" : "out",
"name" : "$return"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "java"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ilove.quark.us.funqy;

import io.quarkus.funqy.Funq;

public class GreetingFunction {

@Funq
public String myFunqyGreeting(Person friend) {
return "Hello " + friend.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ilove.quark.us.funqy;

public class Person {
private String name;

public Person() {}

public Person(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ilove.quark.us.funqy;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class FunqyIT extends FunqyTest {

// Run the same tests

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

import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

@QuarkusTest
public class FunqyTest {

@Test
public void testFunqyLambda() throws Exception {
// you test your lambdas by invoking on http://localhost:8081
// this works in dev mode too

Person in = new Person();
in.setName("Bill");
given()
.contentType("application/json")
.accept("application/json")
.body(in)
.when()
.post()
.then()
.statusCode(200)
.body(containsString("Hello Bill"));
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ilove.quark.us.funqy.cloudevent;

import io.quarkus.funqy.Funq;
import org.jboss.logging.Logger;

public class CloudEventGreeting {
private static final Logger log = Logger.getLogger(CloudEventGreeting.class);

@Funq
public void myCloudEventGreeting(Person input) {
log.info("Hello " + input.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ilove.quark.us.funqy.cloudevent;

public class Person {
private String name;

public Person() {}

public Person(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ilove.quark.us.funqy.cloudevent;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class FunqyIT extends FunqyTest {

// Run the same tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ilove.quark.us.funqy.cloudevent;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import java.util.UUID;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;

@QuarkusTest
public class FunqyTest {

@Test
public void testCloudEvent() {
RestAssured.given().contentType("application/json")
.header("ce-specversion", "1.0")
.header("ce-id", UUID.randomUUID().toString())
.header("ce-type", "myCloudEventGreeting")
.header("ce-source", "test")
.body("{ \"name\": \"Bill\" }")
.post("/")
.then().statusCode(204);
}
}

0 comments on commit 3534e9d

Please sign in to comment.