BAEL-579 Spring Cloud Bus (#2218)

* Code for Dependency Injection Article.

* Added Java based configuration. Downloaded formatter.xml and reformatted
all changed files. Manually changed tab into 4 spaces in XML
configuration files.

* BAEL-434 - Spring Roo project files generated by Spring Roo. No
formatting applied. Added POM, java and resources folders.

* Moved project from roo to spring-roo folder.

* BAEL-838 Initial code showing how to remove last char - helper class and tests.

* BAEL-838 Corrected Helper class and associated empty string test case. Added StringUtils.substing tests.

* BAEL-838 Refromatted code using formatter.xml. Added Assert.assertEquals import. Renamed test to follow convention. Reordered tests.

* BAEL-838 - Added regex method and updated tests.

* BAEL-838 Added new line examples.

* BAEL-838 Renamed RemoveLastChar class to StringHelper and added Java8 examples. Refactord code.

* BAEL-838 Changed method names

* BAEL-838 Tiny change to keep code consistant. Return null or empty.

* BAEL-838 Removed unresolved conflict.

* BAEL-821 New class that shows different rounding techniques. Updated POM.

* BAEL-821 - Added unit test for different round methods.

* BAEL-821 Changed test method name to follow the convention

* BAEL-821 Added more test and updated round methods.

* BAEL-837 - initial commit. A few examples of adding doubles.

* BAEL-837 - Couple of smaller changes

* BAEL-837 - Added jUnit test.

* BAEL-579 Updated Spring Cloud Version

I was getting error: java.lang.NoSuchMethodError:
org.springframework.cloud.config.environment.Environment
After version update, all is okay.

* BAEL-579 Added actuator to Cloud Config Client.

* BAEL-579 Enabled cloud bus and updated dependencies.

* BAEL-579 Config Client using Spring Cloud Bus.

* BAEL-579 Recreated Basic Config Server.

* BAEL-579 Recreated Config Client.

* BAEL-579 Removed test Git URL.

* BAEL-579 Added Actuator to Config Client

* BAEL-579 Added Spring Cloud Bus to Client.

* BAEL-579 Server changes for Spring Cloud Bus

Added dependencies and removed git.clone-on-start as this was causing
server to throw errors after git properties change.

* BAEL-579 Removed Git URL.

* Revert "BAEL-579 Updated Spring Cloud Version"

This reverts commit f775bf91e5.

* Revert "BAEL-579 Config Client using Spring Cloud Bus."

This reverts commit 1d96bc5761.

* Revert "BAEL-579 Enabled cloud bus and updated dependencies."

This reverts commit 7845da922d.

* Revert "BAEL-579 Added actuator to Cloud Config Client."

This reverts commit 076657a26a.

* BAEL-579 Added missing dependency versions.

* BAEL-579 Added missing dependency versions.
This commit is contained in:
iaforek 2017-07-07 18:01:53 +01:00 committed by maibin
parent 9e641358ff
commit a6ba135f77
12 changed files with 320 additions and 53 deletions

View File

@ -1,10 +1,10 @@
package com.baeldung.maths;
import java.math.BigDecimal;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
public class FloatingPointArithmeticTest {
@Test
@ -13,33 +13,33 @@ public class FloatingPointArithmeticTest {
double b = 4.88;
double c = 21.45;
double result = 39.55;
double abc = a + b + c;
double acb = a + c + b;
Assert.assertEquals(result, abc, 0);
Assert.assertNotEquals(result, acb, 0);
double ab = 18.1;
double ac = 34.67;
double ab_c = ab + c;
double ac_b = ac + b;
Assert.assertEquals(result, ab_c, 0);
Assert.assertNotEquals(result, ac_b, 0);
BigDecimal d = new BigDecimal(String.valueOf(a));
BigDecimal e = new BigDecimal(String.valueOf(b));
BigDecimal f = new BigDecimal(String.valueOf(c));
BigDecimal sum = new BigDecimal("39.55");
BigDecimal def = d.add(e).add(f);
BigDecimal dfe = d.add(f).add(e);
Assert.assertEquals(0, def.compareTo(sum));
Assert.assertEquals(0, dfe.compareTo(sum));
Assert.assertNotEquals(0, sum.compareTo(new BigDecimal(String.valueOf(acb))));
}
}

View File

@ -15,60 +15,60 @@ public class RoundTest {
private double expected = 2.03d;
@Test
public void givenDecimalNumber_whenRoundToNDecimalPlaces_thenGetExpectedResult() {
assertEquals(expected, Round.round(value, places), delta);
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
assertEquals(expected, Round.roundAvoid(value, places), delta);
assertEquals(expected, Precision.round(value, places), delta);
assertEquals(expected, DoubleRounder.round(value, places), delta);
public void givenDecimalNumber_whenRoundToNDecimalPlaces_thenGetExpectedResult() {
Assert.assertEquals(expected, Round.round(value, places), delta);
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
Assert.assertEquals(expected, Round.roundAvoid(value, places), delta);
Assert.assertEquals(expected, Precision.round(value, places), delta);
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
places = 3;
expected = 2.035d;
assertEquals(expected, Round.round(value, places), delta);
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
assertEquals(expected, Round.roundAvoid(value, places), delta);
assertEquals(expected, Precision.round(value, places), delta);
assertEquals(expected, DoubleRounder.round(value, places), delta);
Assert.assertEquals(expected, Round.round(value, places), delta);
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
Assert.assertEquals(expected, Round.roundAvoid(value, places), delta);
Assert.assertEquals(expected, Precision.round(value, places), delta);
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
value = 1000.0d;
places = 17;
expected = 1000.0d;
assertEquals(expected, Round.round(value, places), delta);
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 92.23372036854776 !
assertEquals(expected, Precision.round(value, places), delta);
assertEquals(expected, DoubleRounder.round(value, places), delta);
Assert.assertEquals(expected, Round.round(value, places), delta);
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 92.23372036854776 !
Assert.assertEquals(expected, Precision.round(value, places), delta);
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
value = 256.025d;
places = 2;
expected = 256.03d;
assertEquals(expected, Round.round(value, places), delta);
assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 256.02 !
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 256.02 !
assertEquals(expected, Precision.round(value, places), delta);
assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 256.02 !
value = 260.775d;
Assert.assertEquals(expected, Round.round(value, places), delta);
Assert.assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 256.02 !
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 256.02 !
Assert.assertEquals(expected, Precision.round(value, places), delta);
Assert.assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 256.02 !
value = 260.775d;
places = 2;
expected = 260.78d;
assertEquals(expected, Round.round(value, places), delta);
assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 260.77 !
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 260.77 !
assertEquals(expected, Precision.round(value, places), delta);
assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 260.77 !
Assert.assertEquals(expected, Round.round(value, places), delta);
Assert.assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 260.77 !
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 260.77 !
Assert.assertEquals(expected, Precision.round(value, places), delta);
Assert.assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 260.77 !
value = 90080070060.1d;
places = 9;
expected = 90080070060.1d;
assertEquals(expected, Round.round(value, places), delta);
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 9.223372036854776E9 !
assertEquals(expected, Precision.round(value, places), delta);
assertEquals(expected, DoubleRounder.round(value, places), delta);
Assert.assertEquals(expected, Round.round(value, places), delta);
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 9.223372036854776E9 !
Assert.assertEquals(expected, Precision.round(value, places), delta);
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
}
}

View File

@ -0,0 +1,81 @@
<?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>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-config-client</name>
<description>Demo Spring Cloud Config Client</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.4.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.4.RELEASE</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,32 @@
package com.baeldung;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
@RefreshScope
public class SpringCloudConfigClientApplication {
@Value("${user.role}")
private String role;
@Value("${user.password}")
private String password;
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigClientApplication.class, args);
}
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public String whoami(@PathVariable("username") String username) {
return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password);
}
}

View File

@ -0,0 +1,7 @@
---
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest

View File

@ -0,0 +1,7 @@
spring.application.name=config-client
spring.profiles.active=development
spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.username=root
spring.cloud.config.password=s3cr3t
spring.cloud.config.fail-fast=true
management.security.enabled=false

View File

@ -0,0 +1,16 @@
package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringCloudConfigClientApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -0,0 +1,82 @@
<?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>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-config-server</name>
<description>Demo Spring Cloud Config Server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.4.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.4.RELEASE</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,14 @@
package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class SpringCloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigServerApplication.class, args);
}
}

View File

@ -0,0 +1,12 @@
server.port=8888
spring.cloud.config.server.git.uri=
security.user.name=root
security.user.password=s3cr3t
encrypt.key-store.location=classpath:/config-server.jks
encrypt.key-store.password=my-s70r3-s3cr3t
encrypt.key-store.alias=config-server-key
encrypt.key-store.secret=my-k34-s3cr3t
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

View File

@ -0,0 +1,16 @@
package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringCloudConfigServerApplicationTests {
@Test
public void contextLoads() {
}
}