Skip to content

Commit

Permalink
Merge pull request quarkusio#12579 from aureamunoz/spring-web-example…
Browse files Browse the repository at this point in the history
…-12559
  • Loading branch information
ia3andy authored Oct 8, 2020
2 parents cedceb3 + 10590d0 commit ce4c0ac
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Spring Web

Guide: https://quarkus.io/guides/spring-web


Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{project.artifact-id} - {project.version}</title>
<style>
h1, h2, h3, h4, h5, h6 {
margin-bottom: 0.5rem;
font-weight: 400;
line-height: 1.5;
}

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 2rem
}

h3 {
font-size: 1.75rem
}

h4 {
font-size: 1.5rem
}

h5 {
font-size: 1.25rem
}

h6 {
font-size: 1rem
}

.lead {
font-weight: 300;
font-size: 2rem;
}

.banner {
font-size: 2.7rem;
margin: 0;
padding: 2rem 1rem;
background-color: #00A1E2;
color: white;
}

body {
margin: 0;
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

code {
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 87.5%;
color: #e83e8c;
word-break: break-word;
}

.left-column {
padding: .75rem;
max-width: 75%;
min-width: 55%;
}

.right-column {
padding: .75rem;
max-width: 25%;
}

.container {
display: flex;
width: 100%;
}

li {
margin: 0.75rem;
}

.right-section {
margin-left: 1rem;
padding-left: 0.5rem;
}

.right-section h3 {
padding-top: 0;
font-weight: 200;
}

.right-section ul {
border-left: 0.3rem solid #00A1E2;
list-style-type: none;
padding-left: 0;
}

</style>
</head>
<body>

<div class="banner lead">
Your new Cloud-Native application is ready!
</div>

<div class="container">
<div class="left-column">
<p class="lead"> Congratulations, you have created a new Quarkus application with Spring Web.</p>

<h2>Why do you see this?</h2>

<p>This page is served by Quarkus. The source is in
<code>src/main/resources/META-INF/resources/index.html</code>.</p>

<h2>What can I do from here?</h2>

<p>If not already done, run the application in <em>dev mode</em> using: <code>{buildtool.cmd.dev}</code>.
</p>
<ul>
<li>Open the example <a href="{resource.path}" target="_blank">"/hello"</a> endpoint</li>
<li>Add REST resources, Servlets, functions and other services in <code>{language.dir.code}</code>.</li>
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
<li>Configure your application in <code>src/main/resources/{config.file-name}</code>.
</li>
</ul>

<h2>Do you like Quarkus?</h2>
<p>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</p>

<h2>How do I get rid of this page?</h2>
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
</div>
<div class="right-column">
<div class="right-section">
<h3>Application</h3>
<ul>
<li>GroupId: {project.group-id}</li>
<li>ArtifactId: {project.artifact-id}</li>
<li>Version: {project.version}</li>
<li>Quarkus Version: {quarkus.version}</li>
</ul>
</div>
<div class="right-section">
<h3>Next steps</h3>
<ul>
<li><a href="{buildtool.guide}" target="_blank">Setup your IDE</a></li>
<li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li>
<li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: spring-web-example
ref: spring-web
type: code
tags: example
language:
base:
data:
resource:
class-name: ExampleController
path: "/springweb/hello"
response: "hello"
package-name: org.acme.spring.web
dependencies:
- io.quarkus:quarkus-spring-web
test-dependencies:
- io.rest-assured:rest-assured
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package {package-name};

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("{resource.path}")
public class {resource.class-name} {

@GetMapping
public String hello() {
return "{resource.response}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package {package-name};

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class Native{resource.class-name}IT extends {resource.class-name}Test {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package {package-name};

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

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

@QuarkusTest
public class {resource.class-name}Test {

@Test
public void testHelloEndpoint() {
given()
.when().get("{resource.path}")
.then()
.statusCode(200)
.body(is("{resource.response}"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package {package-name}

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("{resource.path}")
class {resource.class-name} {

@GetMapping
fun hello() = "{resource.response}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package {package-name}

import io.quarkus.test.junit.NativeImageTest

@NativeImageTest
class Native{resource.class-name}IT : {resource.class-name}Test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package {package-name}

import io.quarkus.test.junit.QuarkusTest
import io.restassured.RestAssured.given
import org.hamcrest.CoreMatchers.`is`
import org.junit.jupiter.api.Test

@QuarkusTest
class {resource.class-name}Test {

@Test
fun testHelloEndpoint() {
given()
.`when`().get("{resource.path}")
.then()
.statusCode(200)
.body(`is`("{resource.response}"))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package {package-name};

import org.springframework.web.bind.annotation.\{GetMapping, RequestMapping, RestController}


@RestController
@RequestMapping(Array[String]("{resource.path}"))
class {resource.class-name} {

@GetMapping
def hello() = "{resource.response}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package {package-name}

import io.quarkus.test.junit.NativeImageTest

@NativeImageTest
class Native{resource.class-name}IT extends {resource.class-name}Test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package {package-name}

import io.quarkus.test.junit.QuarkusTest
import io.restassured.RestAssured.given
import org.hamcrest.CoreMatchers.`is`
import org.junit.jupiter.api.Test

@QuarkusTest
class {resource.class-name}Test {

@Test
def testHelloEndpoint() = {
given()
.`when`().get("{resource.path}")
.then()
.statusCode(200)
.body(`is`("{resource.response}"))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ metadata:
categories:
- "compatibility"
status: "preview"
codestart: "spring-web"
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public enum DataKey {
RESTEASY_EXAMPLE_PACKAGE_NAME("resteasy-example.package-name"),
RESTEASY_EXAMPLE_RESOURCE_CLASS_NAME("resteasy-example.resource.class-name"),

SPRING_WEB_EXAMPLE_RESOURCE_PATH("spring-web-example.resource.path"),
SPRING_WEB_EXAMPLE_PACKAGE_NAME("spring-web-example.package-name"),
SPRING_WEB_EXAMPLE_RESOURCE_CLASS_NAME("spring-web-example.resource.class-name"),

COMMANDMODE_EXAMPLE_PACKAGE_NAME("commandmode-example.package-name"),
COMMANDMODE_EXAMPLE_RESOURCE_CLASS_NAME("commandmode-example.main.class-name"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ public void generateCustomizedRESTEasyProjectRun() throws Exception {
genName(buildTool, language, codestarts) + "-customized");
}

@Test
public void generateCustomizedSpringWebProjectRun() throws Exception {
final HashMap<String, Object> data = new HashMap<>();
data.put(DataKey.SPRING_WEB_EXAMPLE_PACKAGE_NAME.getKey(), "com.test.spring.web");
data.put(DataKey.SPRING_WEB_EXAMPLE_RESOURCE_CLASS_NAME.getKey(), "SpringWebEndpoint");
data.put(DataKey.SPRING_WEB_EXAMPLE_RESOURCE_PATH.getKey(), "/springweb");
final String buildTool = "maven";
final String language = "java";
final List<String> codestarts = Collections.singletonList("spring-web-example");
generateProjectRunTests(buildTool, language, codestarts, data,
genName(buildTool, language, codestarts) + "-customized");
}

@Test
public void generateCustomizedCommandModeProjectRun() throws Exception {
final HashMap<String, Object> data = new HashMap<>();
Expand Down

0 comments on commit ce4c0ac

Please sign in to comment.