Skip to content

Instantly share code, notes, and snippets.

@iainporter
iainporter / gist:b0b034b369bd81f964a1e45b814cd831
Created June 21, 2016 17:08
Spring Integration DSL transform with header annotation
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
@iainporter
iainporter / gist:8ec808e612afede998e54128ba36676e
Created June 22, 2016 11:53
Spring Integration @Header annotation and dot notation properties in SPEL expression
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.Transformer;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;

Keybase proof

I hereby claim:

  • I am iainporter on github.
  • I am iainporter (https://keybase.io/iainporter) on keybase.
  • I have a public key ASBCfqAgkL0wIg_8Ie67iP7HipExA_IaNYtANpD4jeAuhwo

To claim this, I am signing this object:

@iainporter
iainporter / sms-openapi-pom.xml
Created July 17, 2020 15:51
POM file for sms-openapi maven module
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.porterhead</groupId>
<artifactId>sms-service-parent</artifactId>
@iainporter
iainporter / DefaultSmsService.kt
Created July 17, 2020 17:14
SMS Service class
@ApplicationScoped
class DefaultSmsService: SmsService {
companion object {
val DEFAULT_SORT: Sort = Sort.by("updatedAt").descending()
}
@Inject
lateinit var messageRepository: MessageRepository
@iainporter
iainporter / TestEnvironment.kt
Created July 17, 2020 18:26
Base class for component tests
abstract class TestEnvironment {
@Before
fun setup() {
val port = env.getServicePort("sms-service_1", 8080)
RestAssured.baseURI = "http://localhost:$port"
}
companion object {
@iainporter
iainporter / gist:e9f7a2932a693e9ddf65f92b69c14b9d
Last active July 18, 2020 09:28
docker-compose file for simple testcontainers testing
version: '3'
services:
postgres-db:
image: postgres:11
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=sms
sms-service:
image: porterhead/sms-service
@iainporter
iainporter / SendMessageTest.java
Created July 18, 2020 10:17
Component test to send a message
class SendMessageTest : TestEnvironment() {
@Test
fun `a valid request to send a SMS Message`() {
//send a message
val request = """{"text":"Foo Bar", "fromNumber":"+1234567890", "toNumber":"+1234567899"}"""
val response = RestFunctions.sendSmsMessage(request)
val location = response.header("Location")
//check the message can be retrieved
val messageResponse = RestFunctions.getMessage(location)
@iainporter
iainporter / V1.0.1.1__event.sql
Created July 20, 2020 18:59
migration to add outbox table
CREATE TABLE outboxevent
(
id uuid PRIMARY KEY,
aggregatetype VARCHAR(75),
aggregateid VARCHAR(50) NOT NULL,
type VARCHAR(50) NOT NULL,
timestamp TIMESTAMP NOT NULL,
payload varchar(4096) NOT NULL
);
@iainporter
iainporter / SmsMessageCreatedEvent.kt
Created July 20, 2020 19:01
Message created event
class SmsMessageCreatedEvent (private val id: UUID,
private val node: JsonNode,
private val kTimestamp: Instant = Instant.now()) : ExportedEvent<String, JsonNode> {
companion object {
private val mapper = ObjectMapper()
fun fromSmsMessage(smsMessage: SmsMessage): SmsMessageCreatedEvent {
val asJson: ObjectNode = mapper.createObjectNode()
.put("id", smsMessage.id.toString())
.put("fromNumber", smsMessage.fromNumber)