Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed Aug 25, 2016
1 parent 5658773 commit 3c88ece
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 90,6 @@ A common feature of developing web apps is coding a change, restarting your app,
* Enables LiveReload to refresh browser automatically
* Other reasonable defaults based on development instead of production


== Make the application executable

Although it is possible to package this service as a traditional link:/understanding/WAR[WAR] file for deployment to an external application server, the simpler approach demonstrated below creates a standalone application. You package everything in a single, executable JAR file, driven by a good old Java `main()` method. Along the way, you use Spring's support for embedding the link:/understanding/Tomcat[Tomcat] servlet container as the HTTP runtime, instead of deploying to an external instance.
Expand Down
5 changes: 5 additions & 0 deletions complete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 23,11 @@
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down
58 changes: 58 additions & 0 deletions complete/src/test/java/hello/ApplicationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 1,58 @@
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package hello;

import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class ApplicationTest {

@Autowired
private MockMvc mockMvc;

@Test
public void homePage() throws Exception {
// N.B. jsoup can be useful for asserting HTML content
mockMvc.perform(get("/index.html"))
.andExpect(content().string(containsString("Get your greeting")));
}

@Test
public void greeting() throws Exception {
mockMvc.perform(get("/greeting"))
.andExpect(content().string(containsString("Hello, World!")));
}

@Test
public void greetingWithUser() throws Exception {
mockMvc.perform(get("/greeting").param("name", "Greg"))
.andExpect(content().string(containsString("Hello, Greg!")));
}

}

0 comments on commit 3c88ece

Please sign in to comment.