apache / apache/grails-core

Inject Micronaut Http client at integrationstests

Offen
#11,368 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
relates-to: micronaut
Vorherrschende Sprache
Groovy
Sterne
2.9k
Forks
975
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
92

Beschreibung

Thanks for reporting an issue for Grails framework, please review the task list below before submitting the
issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/grails) or Slack (http://slack-signup.grails.org). DO NOT use the issue tracker to ask questions.

### Task List

- [x] Steps to reproduce provided
- [n/a] Stacktrace (if present) provided
- [n/a] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce
When doing automatic integration testing in Micronaut, I can inject the embedded httpServer without specifying host nor port. This is very convenient as the port is randomised by default in tests.

Here is an example Spock testcase from Micronaut, where I have a HelloController that returns "Hello World":
```
@Inject
@Client('/') // <-- no need to specify port nor host
RxHttpClient client

void "call app"() {
when:
String reply = client.toBlocking().retrieve('/hello')

then:
reply == 'Hello World'
}
```

With Micronaut HTTP client being introduced in Grails 4.0, it would be very nice if we could avoid having to specify the hostname and port for Micronaut HTTP client in Grails integrationtests as well.

Right now I am doing this to get the Micronaut HTTP client in my integrationtests in Grails:
```
@LocalServerPort
Integer localServerPort // random port in tests

BlockingHttpClient httpClient

def setup() {
httpClient = httpClient ?: HttpClient.create(new URL("http://localhost:${localServerPort}")).toBlocking()
}
```

It would be very nice if I could do like in Micronaut:
```
@Inject
@Client('/') // <-- no need to specify port nor host
RxHttpClient client
```
### Expected Behaviour
the http client should be injected without needing to specify port and host

### Actual Behaviour
the http client does not get injected

### Environment Information

- **Operating System**: Ubuntu 18.04
- **Grails Version:** 4.0.0
- **JDK Version:** 8u212
- **Container Version (If Applicable):** N/A

### Example Application

- N/A - it is a feature request

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, das Grails-Setup für Integrationstests und die im Issue beschriebene Micronaut-Verdrahtung von @Inject/@Client zu lokalisieren. Prüfe, wie der zufällige Port des eingebetteten Servers bereitgestellt wird, und verifiziere anschließend, dass ein HTTP-Client in einem Integrationstest injiziert werden kann, ohne Host oder Port anzugeben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
groovy
Bereich
backend, testing
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.