Rebranding (#287)

This commit is contained in:
Marcin Grzejszczak
2016-06-19 23:55:09 +02:00
committed by GitHub
parent a562775980
commit 817c232d3f
747 changed files with 13363 additions and 6399 deletions

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2013-2016 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.
*/
repositories {
mavenLocal()
jcenter()
maven {
url "http://repo.spring.io/snapshot"
}
maven {
url "http://repo.spring.io/milestone"
}
}
String verifier = "spring-cloud-contract-verifier"
dependencies {
compile project(":$verifier-root:$verifier-core")
compile "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit:${springStreamVersion}"
testCompile project(":$verifier-root:$verifier-messaging-root:$verifier-stream")
testCompile "org.springframework.cloud:spring-cloud-stream-test-support:${springStreamVersion}"
testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') {
exclude(group: 'org.codehaus.groovy')
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging
import com.fasterxml.jackson.annotation.JsonCreator
import groovy.transform.CompileStatic
@CompileStatic
class BookDeleted {
final String bookName
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
BookDeleted(String bookName) {
this.bookName = bookName
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cloud.stream.annotation.EnableBinding
import org.springframework.cloud.stream.annotation.StreamListener
import org.springframework.cloud.stream.messaging.Sink
import org.springframework.cloud.stream.messaging.Source
import org.springframework.messaging.MessageHeaders
import org.springframework.messaging.support.MessageBuilder
import java.util.concurrent.atomic.AtomicBoolean
@CompileStatic
@Slf4j
@EnableBinding([DeleteSink, Sink])
class BookListener {
@Autowired Source source
/**
Scenario for "should generate tests triggered by a message":
client side: if sends a message to input.messageFrom then message will be sent to output.messageFrom
server side: will send a message to input, verify the message contents and await upon receiving message on the output messageFrom
*/
@StreamListener(Sink.INPUT)
void returnBook(BookReturned bookReturned) {
log.info("Returning book [$bookReturned]")
source.output().send(MessageBuilder.createMessage(bookReturned, new MessageHeaders([
'BOOK-NAME': bookReturned.bookName as Object
])))
}
/**
Scenario for "should generate tests triggered by a message":
client side: if sends a message to input.messageFrom then message will be sent to output.messageFrom
server side: will send a message to input, verify the message contents and await upon receiving message on the output messageFrom
*/
@StreamListener(DeleteSink.INPUT)
void bookDeleted(BookDeleted bookDeleted) {
log.info("Deleting book [$bookDeleted]")
// ... doing some work
bookSuccessfulyDeleted.set(true)
}
AtomicBoolean bookSuccessfulyDeleted = new AtomicBoolean(false)
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging
import com.fasterxml.jackson.annotation.JsonCreator
import groovy.transform.CompileStatic
@CompileStatic
class BookReturned {
final String bookName
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
BookReturned(String bookName) {
this.bookName = bookName
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cloud.stream.messaging.Source
import org.springframework.messaging.MessageHeaders
import org.springframework.messaging.support.MessageBuilder
import org.springframework.stereotype.Service
@Service
@CompileStatic
@Slf4j
class BookService {
private final Source source
@Autowired
BookService(Source source) {
this.source = source
}
/**
Scenario for "should generate tests triggered by a method":
client side: must have a possibility to "trigger" sending of a message to the given messageFrom
server side: will run the method and await upon receiving message on the output messageFrom
Method triggers sending a message to a source
*/
void returnBook(BookReturned bookReturned) {
log.info("Returning book [$bookReturned]")
source.output().send(MessageBuilder.createMessage(bookReturned, new MessageHeaders([
'BOOK-NAME': bookReturned.bookName as Object
])))
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging
import org.springframework.cloud.stream.annotation.Input
import org.springframework.cloud.stream.messaging.Sink
import org.springframework.messaging.SubscribableChannel
/**
* @author Marcin Grzejszczak
*/
interface DeleteSink extends Sink {
String INPUT = "delete";
@Input(DeleteSink.INPUT)
SubscribableChannel delete();
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
@SpringBootApplication
@EnableBinding([Source, Sink])
class StreamMessagingApplication {
static void main(String[] args) {
SpringApplication.run(StreamMessagingApplication.class, args)
}
}

View File

@@ -0,0 +1,2 @@
spring.cloud.stream.bindings.input.destination: inputDestination
spring.cloud.stream.bindings.output.destination: sentTo

View File

@@ -0,0 +1,152 @@
/*
* Copyright 2013-2016 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.springframework.cloud.contract.verifier.samples.messaging
import com.jayway.jsonpath.DocumentContext
import com.jayway.jsonpath.JsonPath
import com.toomuchcoding.jsonassert.JsonAssertion
import org.springframework.cloud.contract.verifier.dsl.Contract
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.SpringApplicationContextLoader
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierObjectMapper
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
import javax.inject.Inject
/**
* SPIKE ON TESTS FROM NOTES IN MessagingSpec
*/
// Context configuration would end up in base class
@ContextConfiguration(classes = [StreamMessagingApplication], loader = SpringApplicationContextLoader)
public class StreamMessagingApplicationSpec extends Specification {
// ALL CASES
@Inject ContractVerifierMessaging contractVerifierMessaging
ContractVerifierObjectMapper contractVerifierObjectMapper = new ContractVerifierObjectMapper()
def "should work for triggered based messaging"() {
given:
def dsl = Contract.make {
label 'some_label'
input {
triggeredBy('bookReturnedTriggered()')
}
outputMessage {
sentTo('output')
body('''{ "bookName" : "foo" }''')
headers {
header('BOOK-NAME', 'foo')
}
}
}
// generated test should look like this:
when:
bookReturnedTriggered()
then:
def response = contractVerifierMessaging.receiveMessage('output')
response.headers.get('BOOK-NAME') == 'foo'
and:
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
}
def "should generate tests triggered by a message"() {
given:
def dsl = Contract.make {
label 'some_label'
input {
messageFrom('input')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
}
outputMessage {
sentTo('output')
body([
bookName: 'foo'
])
headers {
header('BOOK-NAME', 'foo')
}
}
}
// generated test should look like this:
//given:
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
[sample: 'header']
)
when:
contractVerifierMessaging.send(inputMessage, 'input')
then:
def response = contractVerifierMessaging.receiveMessage('output')
response.headers.get('BOOK-NAME') == 'foo'
and:
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
JsonAssertion.assertThat(parsedJson).field('bookName').isEqualTo('foo')
}
def "should generate tests without destination, triggered by a message"() {
given:
def dsl = Contract.make {
label 'some_label'
input {
messageFrom('delete')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
assertThat('bookWasDeleted()')
}
}
// generated test should look like this:
//given:
ContractVerifierMessage inputMessage = contractVerifierMessaging.create(
contractVerifierObjectMapper.writeValueAsString([bookName: 'foo']),
[sample: 'header']
)
when:
contractVerifierMessaging.send(inputMessage, 'delete')
then:
noExceptionThrown()
bookWasDeleted()
}
// BASE CLASS WOULD HAVE THIS:
@Autowired BookService bookService
@Autowired BookListener bookListener
void bookReturnedTriggered() {
bookService.returnBook(new BookReturned("foo"))
}
void bookWasDeleted() {
assert bookListener.bookSuccessfulyDeleted.get()
}
}