Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from beckje01/sendTest
Send Message Test
- Loading branch information
Showing
5 changed files
with
109 additions
and
5 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
26 changes: 26 additions & 0 deletions
26
ratpack-rabbit-producer/src/test/groovy/smartthings/ratpack/rabbit/SimpleSendSpec.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,26 @@ | ||
package smartthings.ratpack.rabbit | ||
|
||
import ratpack.test.ApplicationUnderTest | ||
import ratpack.test.http.TestHttpClient | ||
import smartthings.ratpack.rabbit.example.ExampleApp | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
class SimpleSendSpec extends Specification{ | ||
|
||
@Shared | ||
ApplicationUnderTest aut = ExampleApp.getExampleApp() | ||
|
||
@Delegate | ||
TestHttpClient client = aut.httpClient | ||
|
||
def "Simple Send"(){ | ||
when: | ||
def resp = get("/") | ||
|
||
then: | ||
resp.body.text == "working" | ||
resp.statusCode == 200 | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
ratpack-rabbit-producer/src/test/groovy/smartthings/ratpack/rabbit/example/ExampleApp.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,49 @@ | ||
package smartthings.ratpack.rabbit.example | ||
|
||
import groovy.util.logging.Slf4j | ||
import ratpack.config.ConfigData | ||
import ratpack.groovy.test.embed.GroovyEmbeddedApp | ||
import ratpack.guice.Guice | ||
import smartthings.ratpack.rabbit.RabbitProducerModule | ||
|
||
@Slf4j | ||
class ExampleApp { | ||
|
||
static String getTestRabbitServer() { | ||
return System.getenv("RABBIT_SERVER") ?: '192.168.99.100' | ||
} | ||
|
||
static def getConfig() { | ||
def config = new RabbitProducerModule.Config() | ||
config.setHostName(getTestRabbitServer()) | ||
config.setUsername("guest") | ||
config.setPassword("guest") | ||
config.setPortNumber(5672) | ||
config.setVirtualHost("/") | ||
return config | ||
} | ||
|
||
static def getExampleApp() { | ||
return GroovyEmbeddedApp.of { | ||
registry Guice.registry { | ||
it.moduleConfig(RabbitProducerModule, getConfig()) | ||
it.bind(TestQueueService) | ||
} | ||
|
||
handlers { | ||
all { | ||
TestQueueService testQueueService = registry.get(TestQueueService) | ||
def helloWorld = "Hello World".bytes | ||
testQueueService.send(helloWorld).onError({ t -> | ||
response.status(500) | ||
t.printStackTrace() | ||
render t.toString() | ||
}).then { | ||
render "working" | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...abbit-producer/src/test/groovy/smartthings/ratpack/rabbit/example/TestQueueService.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,29 @@ | ||
package smartthings.ratpack.rabbit.example | ||
|
||
import com.google.inject.Inject | ||
import smartthings.ratpack.rabbit.ChannelConfig | ||
import smartthings.ratpack.rabbit.RabbitConnectionService | ||
import smartthings.ratpack.rabbit.RabbitQueueService | ||
|
||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class TestQueueService extends RabbitQueueService { | ||
|
||
private ChannelConfig channelConfig = new ChannelConfig(queueName: "test") | ||
|
||
@Inject | ||
TestQueueService(RabbitConnectionService rabbitConnectionService) { | ||
super(rabbitConnectionService) | ||
} | ||
|
||
@Override | ||
public ChannelConfig getChannelConfig() { | ||
return channelConfig | ||
} | ||
|
||
@Override | ||
String getName() { | ||
return "Rabbit TEST queue Service" | ||
} | ||
} |