Polish contribution

This commit is contained in:
Phillip Webb
2016-04-06 15:26:27 -07:00
parent a2adc5a130
commit 48800f1818
27 changed files with 693 additions and 547 deletions

View File

@@ -1,57 +1,56 @@
<?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>
<artifactId>spring-boot-samples</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-jta-narayana</artifactId>
<name>Spring Boot Narayana JTA Sample</name>
<description>Spring Boot Narayana JTA Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-narayana</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hornetq</artifactId>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-server</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
<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>
<artifactId>spring-boot-samples</artifactId>
<groupId>org.springframework.boot</groupId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-jta-narayana</artifactId>
<name>Spring Boot Narayana JTA Sample</name>
<description>Spring Boot Narayana JTA Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-narayana</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hornetq</artifactId>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-server</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-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.
@@ -26,7 +26,8 @@ import org.springframework.context.ApplicationContext;
public class SampleNarayanaApplication {
public static void main(String[] args) throws Exception {
ApplicationContext context = SpringApplication.run(SampleNarayanaApplication.class, args);
ApplicationContext context = SpringApplication
.run(SampleNarayanaApplication.class, args);
AccountService service = context.getBean(AccountService.class);
AccountRepository repository = context.getBean(AccountRepository.class);
service.createAccountAndNotify("josh");
@@ -34,7 +35,8 @@ public class SampleNarayanaApplication {
try {
// Using username "error" will cause service to throw SampleRuntimeException
service.createAccountAndNotify("error");
} catch (SampleRuntimeException ex) {
}
catch (SampleRuntimeException ex) {
// Log message to let test case know that exception was thrown
System.out.println(ex.getMessage());
}

View File

@@ -1,8 +1,21 @@
/*
* Copyright 2012-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 sample.narayana;
/**
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
*/
public class SampleRuntimeException extends RuntimeException {
public SampleRuntimeException(String message) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-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.
@@ -16,16 +16,18 @@
package sample.narayana;
import org.hamcrest.Matcher;
import org.hamcrest.core.SubstringMatcher;
import org.assertj.core.api.Condition;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertThat;
import org.springframework.boot.test.rule.OutputCapture;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
* Basic integration tests for demo application.
*
* @author Gytis Trikleris
*/
public class SampleNarayanaApplicationTests {
@@ -36,25 +38,22 @@ public class SampleNarayanaApplicationTests {
public void testTransactionRollback() throws Exception {
SampleNarayanaApplication.main(new String[] {});
String output = this.outputCapture.toString();
assertThat(output, containsString(1, "---->"));
assertThat(output, containsString(1, "----> josh"));
assertThat(output, containsString(2, "Count is 1"));
assertThat(output, containsString(1, "Simulated error"));
assertThat(output).has(substring(1, "---->"));
assertThat(output).has(substring(1, "----> josh"));
assertThat(output).has(substring(2, "Count is 1"));
assertThat(output).has(substring(1, "Simulated error"));
}
private Matcher<? super String> containsString(final int times, String s) {
return new SubstringMatcher(s) {
private Condition<String> substring(final int times, final String substring) {
return new Condition<String>(
"containing '" + substring + "' " + times + " times") {
@Override
protected String relationship() {
return "containing " + times + " times";
}
@Override
protected boolean evalSubstringOf(String s) {
public boolean matches(String value) {
int i = 0;
while (s.contains(this.substring)) {
s = s.substring(s.indexOf(this.substring) + this.substring.length());
while (value.contains(substring)) {
int beginIndex = value.indexOf(substring) + substring.length();
value = value.substring(beginIndex);
i++;
}
return i == times;