Skip to content

Commit

Permalink
Merge fec332d into 4181eeb
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Mar 19, 2021
2 parents 4181eeb + fec332d commit b5d90d5
Show file tree
Hide file tree
Showing 38 changed files with 1,442 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
**/build/
**/target/
**/out/
**/.idea/
**/*.iml
Expand All @@ -10,3 +11,13 @@ gradle-app.setting
!gradle-wrapper.jar

**.hprof

Thumbs.db
.DS_Store
*.iml
*.ipr
*.iws
.project
.settings
.classpath
.factorypath
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ projects {
compileOnly platform("org.codehaus.groovy:groovy-bom:$groovyVersion")
testCompile platform("org.codehaus.groovy:groovy-bom:$groovyVersion")
testImplementation platform("org.codehaus.groovy:groovy-bom:$groovyVersion")

testImplementation "org.spockframework:spock-core:$spockVersion", {
force = true
}
}
}

Expand All @@ -193,6 +189,12 @@ projects {
enabled = true
}
}

dependencies {
testImplementation "org.spockframework:spock-core:$spockVersion", {
force = true
}
}
}
}
}
53 changes: 51 additions & 2 deletions docs/guide/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[.ribbon]
image::ribbon.png[link={project-url}]

Gru is HTTP interaction testing framework with out-of-box support for Grails, Spring MVC, API Gateway but it can be used with any
HTTP server such as Micronaut embedded server.
Gru is HTTP interaction testing framework with out-of-box support for Micronaut, Grails, Spring MVC, API Gateway but it can be used with any
HTTP server framework.

== Installation

Expand All @@ -23,12 +23,14 @@ dependencies {
testCompile "com.agorapulse:gru-grails:{project-version}" // <2>
testCompile "com.agorapulse:gru-spring:{project-version}" // <3>
testCompile "com.agorapulse:gru-api-gateway:{project-version}" // <4>
testCompile "com.agorapulse:gru-micronaut:{project-version}" // <5>
}
----
<1> HTTP module for any HTTP backend such as Micronaut embedded server
<2> Grails module to emulate HTTP interaction within Grails Unit tests
<3> Spring module to emulate HTTP interaction using `MockMvc`
<4> AWS API Gateway module for HTTP proxy lambdas
<5> Micronaut module for running HTTP request against the embedded server

[NOTE]
====
Expand All @@ -55,6 +57,53 @@ include::{root-dir}/examples/heist/src/test/groovy/heist/HttpSpec.groovy[lines=1
<2> Set the base URL `http://despicableme.wikia.com` for HTTP calls
<3> Execute HTTP GET request on `/wiki/Felonius_Gru` URI and verify it is accessible and returns `OK(200)` status code.

=== Micronaut

Micronaut plays well with `@MicronautTest` annotation. If you are using `@MicronautTest` you can simply inject
`Gru` instance into your test.

.Using @Inject with @MicronautTest
[source,groovy]
----
include::{root-dir}/examples/heist-micronaut/src/test/groovy/heist/InjectNativeMicronautSpec.groovy[lines=18..-1]
----
<1> Annotate your test with @MicronautTest`
<2> Inject `Gru`

Alternatively, you can let `Gru` to create default `ApplicationContext` for you.

.Using Default Application Context
[source,groovy]
----
include::{root-dir}/examples/heist-micronaut/src/test/groovy/heist/AutomaticMicronautSpec.groovy[lines=18..-1]
----
<1> Create a simple `Micronaut` client for `Gru`
<2> Default application context is created and fields can be injected into the test

If you construct the application context yourself then you need to point `Gru` to the field of type `ApplicationContext`.

.Using a Custom Application Context
[source,groovy]
----
include::{root-dir}/examples/heist-micronaut/src/test/groovy/heist/ManualWithSimpleProviderMicronautSpec.groovy[lines=18..-1]
----
<1> Point `Gru` to field `context` holding the custom `ApplicationContext` instance

NOTE: As an alternative, you can make your test class implement `io.micronaut.context.ApplicationContextProvider`.

Gru can actually help you create the custom context:

.Creating a Custom Application Context
[source,groovy]
----
include::{root-dir}/examples/heist-micronaut/src/test/groovy/heist/AdvancedAutomaticMicronautSpec.groovy[lines=18..-1]
----
<1> Declare any field you want to reference from the context before `Gru` declaration
<2> Customize the `ApplicationContextBuilder`
<3> Customize the `ApplicationContext` itself, e.g. register mocks
<4> Start the application and injects fields into the test automatically
<5> The field can be automatically injected

=== Grails

Gru for Grails tests controllers in context of other Grails artifacts such as url mappings or interceptors.
Expand Down
12 changes: 12 additions & 0 deletions examples/heist-micronaut/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Micronaut 2.4.0 Documentation

- [User Guide](https://docs.micronaut.io/2.4.0/guide/index.html)
- [API Reference](https://docs.micronaut.io/2.4.0/api/index.html)
- [Configuration Reference](https://docs.micronaut.io/2.4.0/guide/configurationreference.html)
- [Micronaut Guides](https://guides.micronaut.io/index.html)
---

## Feature http-client documentation

- [Micronaut HTTP Client documentation](https://docs.micronaut.io/latest/guide/index.html#httpClient)

59 changes: 59 additions & 0 deletions examples/heist-micronaut/heist-micronaut.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2021 Agorapulse.
*
* 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
*
* https://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.
*/
plugins {
id("groovy")
id("com.github.johnrengelman.shadow") version "6.1.0"
id("io.micronaut.application") version "1.4.2"
}

version = "0.1"
group = "heist"

repositories {
mavenCentral()
}

micronaut {
runtime("netty")
testRuntime("spock2")
processing {
incremental(true)
annotations("heist.*")
}
}

dependencies {
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut:micronaut-http-client")
runtimeOnly("ch.qos.logback:logback-classic")

testImplementation project(':gru-micronaut')
}


application {
mainClass.set("heist.Application")
}
java {
sourceCompatibility = JavaVersion.toVersion("1.8")
targetCompatibility = JavaVersion.toVersion("1.8")
}



6 changes: 6 additions & 0 deletions examples/heist-micronaut/micronaut-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
applicationType: default
defaultPackage: heist
testFramework: spock
sourceLanguage: java
buildTool: gradle
features: [app-name, gradle, http-client, java, java-application, logback, netty-server, readme, shade, spock, yaml]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2021 Agorapulse.
*
* 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
*
* https://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 heist.micronaut;

import io.micronaut.context.ApplicationContext;
import io.micronaut.runtime.Micronaut;

public class Application {

static ApplicationContext context;

public static void main(String[] args) {
context = Micronaut.run(Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2021 Agorapulse.
*
* 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
*
* https://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 heist.micronaut;

import javax.inject.Singleton;

@Singleton
public class DefaultMoonService implements MoonService {

@Override
public Moon get(String planet, String name) {
return new Moon(planet, name);
}
}
59 changes: 59 additions & 0 deletions examples/heist-micronaut/src/main/java/heist/micronaut/Moon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2021 Agorapulse.
*
* 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
*
* https://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 heist.micronaut;

import java.time.Instant;

public class Moon {

public Moon() { }

public Moon(String name, String planet) {
this.name = name;
this.planet = planet;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPlanet() {
return planet;
}

public void setPlanet(String planet) {
this.planet = planet;
}

public Instant getCreated() {
return created;
}

public void setCreated(Instant created) {
this.created = created;
}

private String name;
private String planet;
private Instant created = Instant.now();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2021 Agorapulse.
*
* 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
*
* https://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 heist.micronaut;

import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.PathVariable;

@Controller("/moons")
class MoonController {

private final MoonService moonService;

public MoonController(MoonService moonService) {
this.moonService = moonService;
}

@Get("/{planet}/{moon}")
Moon sayHello(@PathVariable("planet") String planet, @PathVariable("moon") String moon) {
return moonService.get(planet, moon);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2021 Agorapulse.
*
* 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
*
* https://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 heist.micronaut;

public interface MoonService {

Moon get(String planet, String name);

}
3 changes: 3 additions & 0 deletions examples/heist-micronaut/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
micronaut:
application:
name: heistMicronaut

0 comments on commit b5d90d5

Please sign in to comment.