Skip to content

Commit a6ba135

Browse files
iaforekmaibin
authored andcommitted
BAEL-579 Spring Cloud Bus (eugenp#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 f775bf9. * Revert "BAEL-579 Config Client using Spring Cloud Bus." This reverts commit 1d96bc5. * Revert "BAEL-579 Enabled cloud bus and updated dependencies." This reverts commit 7845da9. * Revert "BAEL-579 Added actuator to Cloud Config Client." This reverts commit 076657a. * BAEL-579 Added missing dependency versions. * BAEL-579 Added missing dependency versions.
1 parent 9e64135 commit a6ba135

12 files changed

Lines changed: 320 additions & 53 deletions

File tree

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.baeldung.maths;
22

3+
import java.math.BigDecimal;
4+
35
import org.junit.Assert;
46
import org.junit.Test;
57

6-
import java.math.BigDecimal;
7-
88
public class FloatingPointArithmeticTest {
99

1010
@Test
@@ -13,33 +13,33 @@ public void givenDecimalNumbers_whenAddedTogether_thenGetExpectedResult() {
1313
double b = 4.88;
1414
double c = 21.45;
1515
double result = 39.55;
16-
16+
1717
double abc = a + b + c;
1818
double acb = a + c + b;
19-
19+
2020
Assert.assertEquals(result, abc, 0);
2121
Assert.assertNotEquals(result, acb, 0);
22-
22+
2323
double ab = 18.1;
2424
double ac = 34.67;
25-
25+
2626
double ab_c = ab + c;
2727
double ac_b = ac + b;
28-
28+
2929
Assert.assertEquals(result, ab_c, 0);
3030
Assert.assertNotEquals(result, ac_b, 0);
31-
31+
3232
BigDecimal d = new BigDecimal(String.valueOf(a));
3333
BigDecimal e = new BigDecimal(String.valueOf(b));
3434
BigDecimal f = new BigDecimal(String.valueOf(c));
3535
BigDecimal sum = new BigDecimal("39.55");
36-
36+
3737
BigDecimal def = d.add(e).add(f);
3838
BigDecimal dfe = d.add(f).add(e);
39-
39+
4040
Assert.assertEquals(0, def.compareTo(sum));
4141
Assert.assertEquals(0, dfe.compareTo(sum));
42-
42+
4343
Assert.assertNotEquals(0, sum.compareTo(new BigDecimal(String.valueOf(acb))));
4444
}
4545
}

‎core-java/src/test/java/com/baeldung/maths/RoundTest.java‎

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,60 @@ public class RoundTest {
1515
private double expected = 2.03d;
1616

1717
@Test
18-
public void givenDecimalNumber_whenRoundToNDecimalPlaces_thenGetExpectedResult() {
19-
assertEquals(expected, Round.round(value, places), delta);
20-
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
21-
assertEquals(expected, Round.roundAvoid(value, places), delta);
22-
assertEquals(expected, Precision.round(value, places), delta);
23-
assertEquals(expected, DoubleRounder.round(value, places), delta);
24-
18+
public void givenDecimalNumber_whenRoundToNDecimalPlaces_thenGetExpectedResult() {
19+
Assert.assertEquals(expected, Round.round(value, places), delta);
20+
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
21+
Assert.assertEquals(expected, Round.roundAvoid(value, places), delta);
22+
Assert.assertEquals(expected, Precision.round(value, places), delta);
23+
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
24+
2525
places = 3;
2626
expected = 2.035d;
27-
28-
assertEquals(expected, Round.round(value, places), delta);
29-
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
30-
assertEquals(expected, Round.roundAvoid(value, places), delta);
31-
assertEquals(expected, Precision.round(value, places), delta);
32-
assertEquals(expected, DoubleRounder.round(value, places), delta);
33-
27+
28+
Assert.assertEquals(expected, Round.round(value, places), delta);
29+
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
30+
Assert.assertEquals(expected, Round.roundAvoid(value, places), delta);
31+
Assert.assertEquals(expected, Precision.round(value, places), delta);
32+
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
33+
3434
value = 1000.0d;
3535
places = 17;
3636
expected = 1000.0d;
37-
38-
assertEquals(expected, Round.round(value, places), delta);
39-
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
40-
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 92.23372036854776 !
41-
assertEquals(expected, Precision.round(value, places), delta);
42-
assertEquals(expected, DoubleRounder.round(value, places), delta);
43-
37+
38+
Assert.assertEquals(expected, Round.round(value, places), delta);
39+
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
40+
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 92.23372036854776 !
41+
Assert.assertEquals(expected, Precision.round(value, places), delta);
42+
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
43+
4444
value = 256.025d;
4545
places = 2;
4646
expected = 256.03d;
47-
48-
assertEquals(expected, Round.round(value, places), delta);
49-
assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 256.02 !
50-
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 256.02 !
51-
assertEquals(expected, Precision.round(value, places), delta);
52-
assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 256.02 !
53-
54-
value = 260.775d;
47+
48+
Assert.assertEquals(expected, Round.round(value, places), delta);
49+
Assert.assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 256.02 !
50+
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 256.02 !
51+
Assert.assertEquals(expected, Precision.round(value, places), delta);
52+
Assert.assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 256.02 !
53+
54+
value = 260.775d;
5555
places = 2;
5656
expected = 260.78d;
57-
58-
assertEquals(expected, Round.round(value, places), delta);
59-
assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 260.77 !
60-
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 260.77 !
61-
assertEquals(expected, Precision.round(value, places), delta);
62-
assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 260.77 !
63-
57+
58+
Assert.assertEquals(expected, Round.round(value, places), delta);
59+
Assert.assertNotEquals(expected, Round.roundNotPrecise(value, places), delta); // Returns: 260.77 !
60+
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 260.77 !
61+
Assert.assertEquals(expected, Precision.round(value, places), delta);
62+
Assert.assertNotEquals(expected, DoubleRounder.round(value, places), delta); // Returns: 260.77 !
63+
6464
value = 90080070060.1d;
6565
places = 9;
6666
expected = 90080070060.1d;
67-
68-
assertEquals(expected, Round.round(value, places), delta);
69-
assertEquals(expected, Round.roundNotPrecise(value, places), delta);
70-
assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 9.223372036854776E9 !
71-
assertEquals(expected, Precision.round(value, places), delta);
72-
assertEquals(expected, DoubleRounder.round(value, places), delta);
67+
68+
Assert.assertEquals(expected, Round.round(value, places), delta);
69+
Assert.assertEquals(expected, Round.roundNotPrecise(value, places), delta);
70+
Assert.assertNotEquals(expected, Round.roundAvoid(value, places), delta); // Returns: 9.223372036854776E9 !
71+
Assert.assertEquals(expected, Precision.round(value, places), delta);
72+
Assert.assertEquals(expected, DoubleRounder.round(value, places), delta);
7373
}
7474
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung.spring.cloud</groupId>
7+
<artifactId>spring-cloud-config-client</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-cloud-config-client</name>
12+
<description>Demo Spring Cloud Config Client</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.4.RELEASE</version>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.cloud</groupId>
30+
<artifactId>spring-cloud-starter-config</artifactId>
31+
<version>1.3.1.RELEASE</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
<version>1.5.4.RELEASE</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-test</artifactId>
42+
<version>1.5.4.RELEASE</version>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-actuator</artifactId>
49+
<version>1.5.4.RELEASE</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.springframework.cloud</groupId>
54+
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
55+
<version>1.3.1.RELEASE</version>
56+
</dependency>
57+
</dependencies>
58+
59+
<dependencyManagement>
60+
<dependencies>
61+
<dependency>
62+
<groupId>org.springframework.cloud</groupId>
63+
<artifactId>spring-cloud-dependencies</artifactId>
64+
<version>${spring-cloud.version}</version>
65+
<type>pom</type>
66+
<scope>import</scope>
67+
</dependency>
68+
</dependencies>
69+
</dependencyManagement>
70+
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-maven-plugin</artifactId>
76+
<version>1.5.4.RELEASE</version>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
81+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cloud.context.config.annotation.RefreshScope;
7+
import org.springframework.http.MediaType;
8+
import org.springframework.web.bind.annotation.PathVariable;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@SpringBootApplication
14+
@RestController
15+
@RefreshScope
16+
public class SpringCloudConfigClientApplication {
17+
18+
@Value("${user.role}")
19+
private String role;
20+
21+
@Value("${user.password}")
22+
private String password;
23+
24+
public static void main(String[] args) {
25+
SpringApplication.run(SpringCloudConfigClientApplication.class, args);
26+
}
27+
28+
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
29+
public String whoami(@PathVariable("username") String username) {
30+
return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password);
31+
}
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
spring:
3+
rabbitmq:
4+
host: localhost
5+
port: 5672
6+
username: guest
7+
password: guest
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spring.application.name=config-client
2+
spring.profiles.active=development
3+
spring.cloud.config.uri=http://localhost:8888
4+
spring.cloud.config.username=root
5+
spring.cloud.config.password=s3cr3t
6+
spring.cloud.config.fail-fast=true
7+
management.security.enabled=false
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SpringCloudConfigClientApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung.spring.cloud</groupId>
7+
<artifactId>spring-cloud-config-server</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-cloud-config-server</name>
12+
<description>Demo Spring Cloud Config Server</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.4.RELEASE</version>
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.cloud</groupId>
30+
<artifactId>spring-cloud-config-server</artifactId>
31+
<version>1.3.1.RELEASE</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-security</artifactId>
37+
<version>1.5.4.RELEASE</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-test</artifactId>
43+
<version>1.5.4.RELEASE</version>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.springframework.cloud</groupId>
49+
<artifactId>spring-cloud-config-monitor</artifactId>
50+
<version>1.3.1.RELEASE</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework.cloud</groupId>
55+
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
56+
<version>1.2.1.RELEASE</version>
57+
</dependency>
58+
</dependencies>
59+
60+
<dependencyManagement>
61+
<dependencies>
62+
<dependency>
63+
<groupId>org.springframework.cloud</groupId>
64+
<artifactId>spring-cloud-dependencies</artifactId>
65+
<version>${spring-cloud.version}</version>
66+
<type>pom</type>
67+
<scope>import</scope>
68+
</dependency>
69+
</dependencies>
70+
</dependencyManagement>
71+
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-maven-plugin</artifactId>
77+
<version>1.5.4.RELEASE</version>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
82+
</project>

0 commit comments

Comments
 (0)