forked from spockframework/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for Spring TestContext Framework 4.0
- handle meta-annotations - added spring-boot project/test sample
- Loading branch information
Showing
8 changed files
with
176 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def springVersion = "4.1.0.RELEASE" | ||
def bootVersion = "1.1.6.RELEASE" | ||
|
||
dependencies { | ||
compile "org.springframework:spring-core:$springVersion" | ||
compile "org.springframework.boot:spring-boot:$bootVersion" | ||
compile "org.springframework.boot:spring-boot-autoconfigure:$bootVersion" | ||
|
||
testCompile project(":spock-core") | ||
testCompile "org.springframework:spring-context:$springVersion" | ||
testCompile "org.springframework:spring-test:$springVersion" | ||
|
||
testRuntime project(":spock-spring") | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
spock-boot/src/main/java/org/spockframework/boot/SimpleBootApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2012-2013 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 org.spockframework.boot; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import org.spockframework.boot.service.HelloWorldService; | ||
|
||
@Configuration | ||
@EnableAutoConfiguration | ||
@ComponentScan | ||
public class SimpleBootApp implements CommandLineRunner { | ||
@Autowired | ||
private HelloWorldService helloWorldService; | ||
|
||
@Override | ||
public void run(String... args) { | ||
System.out.println(this.helloWorldService.getHelloMessage()); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(SimpleBootApp.class, args); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
spock-boot/src/main/java/org/spockframework/boot/service/HelloWorldService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2012-2013 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 org.spockframework.boot.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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: Spock |
44 changes: 44 additions & 0 deletions
44
spock-boot/src/test/groovy/org/spockframework/boot/SimpleBootAppIntegrationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2012-2014 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 org.spockframework.boot | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.SpringApplicationConfiguration | ||
import org.springframework.context.ApplicationContext | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* Spock test for {@link org.spockframework.boot.SimpleBootApp}. | ||
* Adapted from https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/ | ||
* spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java. | ||
* | ||
* @author Dave Syer | ||
* @author Peter Niederwieser | ||
*/ | ||
@SpringApplicationConfiguration(classes = SimpleBootApp.class) | ||
class SimpleBootAppIntegrationSpec extends Specification { | ||
@Autowired | ||
ApplicationContext ctx | ||
|
||
def "test context loads"() { | ||
expect: | ||
ctx != null | ||
ctx.containsBean("helloWorldService") | ||
ctx.containsBean("simpleBootApp") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters