Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
f9c3baed
Commit
f9c3baed
authored
Jan 07, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add TestNG sample application
Add a TestNG sample that also demonstrates @WebIntegrationTest. See gh-2135
parent
be30385e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
233 additions
and
1 deletion
+233
-1
pom.xml
spring-boot-samples/pom.xml
+2
-1
.gitignore
spring-boot-samples/spring-boot-sample-testng/.gitignore
+1
-0
pom.xml
spring-boot-samples/spring-boot-sample-testng/pom.xml
+52
-0
SampleTestNGApplication.java
.../src/main/java/sample/testng/SampleTestNGApplication.java
+54
-0
HelloWorldService.java
...rc/main/java/sample/testng/service/HelloWorldService.java
+32
-0
SampleController.java
...tng/src/main/java/sample/testng/web/SampleController.java
+38
-0
test.css
...ing-boot-sample-testng/src/main/resources/public/test.css
+1
-0
SampleTestNGApplicationTests.java
...test/java/sample/testng/SampleTestNGApplicationTests.java
+53
-0
No files found.
spring-boot-samples/pom.xml
View file @
f9c3baed
...
@@ -55,9 +55,10 @@
...
@@ -55,9 +55,10 @@
<module>
spring-boot-sample-secure
</module>
<module>
spring-boot-sample-secure
</module>
<module>
spring-boot-sample-servlet
</module>
<module>
spring-boot-sample-servlet
</module>
<module>
spring-boot-sample-simple
</module>
<module>
spring-boot-sample-simple
</module>
<module>
spring-boot-sample-testng
</module>
<module>
spring-boot-sample-tomcat
</module>
<module>
spring-boot-sample-tomcat-jsp
</module>
<module>
spring-boot-sample-tomcat-jsp
</module>
<module>
spring-boot-sample-tomcat-ssl
</module>
<module>
spring-boot-sample-tomcat-ssl
</module>
<module>
spring-boot-sample-tomcat
</module>
<module>
spring-boot-sample-tomcat-multi-connectors
</module>
<module>
spring-boot-sample-tomcat-multi-connectors
</module>
<module>
spring-boot-sample-tomcat7-jsp
</module>
<module>
spring-boot-sample-tomcat7-jsp
</module>
<module>
spring-boot-sample-traditional
</module>
<module>
spring-boot-sample-traditional
</module>
...
...
spring-boot-samples/spring-boot-sample-testng/.gitignore
0 → 100644
View file @
f9c3baed
test-output
spring-boot-samples/spring-boot-sample-testng/pom.xml
0 → 100644
View file @
f9c3baed
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-samples
</artifactId>
<version>
1.2.1.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-sample-testng
</artifactId>
<name>
Spring Boot TestNG Sample
</name>
<description>
Spring Boot TestNG Sample
</description>
<url>
http://projects.spring.io/spring-boot/
</url>
<organization>
<name>
Pivotal Software, Inc.
</name>
<url>
http://www.spring.io
</url>
</organization>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
</dependency>
<dependency>
<groupId>
org.testng
</groupId>
<artifactId>
testng
</artifactId>
<version>
6.8.13
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/SampleTestNGApplication.java
0 → 100644
View file @
f9c3baed
/*
* 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
sample
.
testng
;
import
javax.servlet.ServletContextEvent
;
import
javax.servlet.ServletContextListener
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
@SpringBootApplication
public
class
SampleTestNGApplication
{
private
static
Log
logger
=
LogFactory
.
getLog
(
SampleTestNGApplication
.
class
);
@Bean
protected
ServletContextListener
listener
()
{
return
new
ServletContextListener
()
{
@Override
public
void
contextInitialized
(
ServletContextEvent
sce
)
{
logger
.
info
(
"ServletContext initialized"
);
}
@Override
public
void
contextDestroyed
(
ServletContextEvent
sce
)
{
logger
.
info
(
"ServletContext destroyed"
);
}
};
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleTestNGApplication
.
class
,
args
);
}
}
spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/service/HelloWorldService.java
0 → 100644
View file @
f9c3baed
/*
* 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
sample
.
testng
.
service
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
@Component
public
class
HelloWorldService
{
@Value
(
"${name:World}"
)
private
String
name
;
public
String
getHelloMessage
()
{
return
"Hello "
+
this
.
name
;
}
}
spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/web/SampleController.java
0 → 100644
View file @
f9c3baed
/*
* 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
sample
.
testng
.
web
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
sample.testng.service.HelloWorldService
;
@Controller
public
class
SampleController
{
@Autowired
private
HelloWorldService
helloWorldService
;
@RequestMapping
(
"/"
)
@ResponseBody
public
String
helloWorld
()
{
return
this
.
helloWorldService
.
getHelloMessage
();
}
}
spring-boot-samples/spring-boot-sample-testng/src/main/resources/public/test.css
0 → 100644
View file @
f9c3baed
p
.
{}
spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java
0 → 100644
View file @
f9c3baed
/*
* 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
sample
.
testng
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.testng.AbstractTestNGSpringContextTests
;
import
org.testng.annotations.Test
;
import
sample.testng.SampleTestNGApplication
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
/**
* Basic integration tests for demo application.
*
* @author Phillip Webb
*/
@SpringApplicationConfiguration
(
classes
=
SampleTestNGApplication
.
class
)
@WebIntegrationTest
(
"server.port:0"
)
@DirtiesContext
public
class
SampleTestNGApplicationTests
extends
AbstractTestNGSpringContextTests
{
@Value
(
"${local.server.port}"
)
private
int
port
;
@Test
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertEquals
(
"Hello World"
,
entity
.
getBody
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment