diff --git a/core-java/src/test/java/com/baeldung/maths/FloatingPointArithmeticTest.java b/core-java/src/test/java/com/baeldung/maths/FloatingPointArithmeticTest.java index 84dd41b1d7..2066f13c6d 100644 --- a/core-java/src/test/java/com/baeldung/maths/FloatingPointArithmeticTest.java +++ b/core-java/src/test/java/com/baeldung/maths/FloatingPointArithmeticTest.java @@ -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)))); } } diff --git a/core-java/src/test/java/com/baeldung/maths/RoundTest.java b/core-java/src/test/java/com/baeldung/maths/RoundTest.java index ead21265c0..5ce9523e21 100644 --- a/core-java/src/test/java/com/baeldung/maths/RoundTest.java +++ b/core-java/src/test/java/com/baeldung/maths/RoundTest.java @@ -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); } } diff --git a/spring-cloud-bus/spring-cloud-config-client/pom.xml b/spring-cloud-bus/spring-cloud-config-client/pom.xml new file mode 100644 index 0000000000..977f18b17f --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-client/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + com.baeldung.spring.cloud + spring-cloud-config-client + 0.0.1-SNAPSHOT + jar + + spring-cloud-config-client + Demo Spring Cloud Config Client + + + org.springframework.boot + spring-boot-starter-parent + 1.5.4.RELEASE + + + + UTF-8 + UTF-8 + 1.8 + Dalston.SR1 + + + + + org.springframework.cloud + spring-cloud-starter-config + 1.3.1.RELEASE + + + org.springframework.boot + spring-boot-starter-web + 1.5.4.RELEASE + + + + org.springframework.boot + spring-boot-starter-test + 1.5.4.RELEASE + test + + + + org.springframework.boot + spring-boot-actuator + 1.5.4.RELEASE + + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + 1.3.1.RELEASE + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.4.RELEASE + + + + + diff --git a/spring-cloud-bus/spring-cloud-config-client/src/main/java/com/baeldung/SpringCloudConfigClientApplication.java b/spring-cloud-bus/spring-cloud-config-client/src/main/java/com/baeldung/SpringCloudConfigClientApplication.java new file mode 100644 index 0000000000..d0afd7f6bf --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-client/src/main/java/com/baeldung/SpringCloudConfigClientApplication.java @@ -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); + } +} diff --git a/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml b/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml new file mode 100644 index 0000000000..547e0284f3 --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml @@ -0,0 +1,7 @@ +--- +spring: + rabbitmq: + host: localhost + port: 5672 + username: guest + password: guest \ No newline at end of file diff --git a/spring-cloud-bus/spring-cloud-config-client/src/main/resources/bootstrap.properties b/spring-cloud-bus/spring-cloud-config-client/src/main/resources/bootstrap.properties new file mode 100644 index 0000000000..7b362614ba --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-client/src/main/resources/bootstrap.properties @@ -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 \ No newline at end of file diff --git a/spring-cloud-bus/spring-cloud-config-client/src/test/java/com/baeldung/SpringCloudConfigClientApplicationTests.java b/spring-cloud-bus/spring-cloud-config-client/src/test/java/com/baeldung/SpringCloudConfigClientApplicationTests.java new file mode 100644 index 0000000000..3b361f385a --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-client/src/test/java/com/baeldung/SpringCloudConfigClientApplicationTests.java @@ -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() { + } + +} diff --git a/spring-cloud-bus/spring-cloud-config-server/pom.xml b/spring-cloud-bus/spring-cloud-config-server/pom.xml new file mode 100644 index 0000000000..e37f601d2c --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-server/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.baeldung.spring.cloud + spring-cloud-config-server + 0.0.1-SNAPSHOT + jar + + spring-cloud-config-server + Demo Spring Cloud Config Server + + + org.springframework.boot + spring-boot-starter-parent + 1.5.4.RELEASE + + + + UTF-8 + UTF-8 + 1.8 + Dalston.SR1 + + + + + org.springframework.cloud + spring-cloud-config-server + 1.3.1.RELEASE + + + + org.springframework.boot + spring-boot-starter-security + 1.5.4.RELEASE + + + + org.springframework.boot + spring-boot-starter-test + 1.5.4.RELEASE + test + + + + org.springframework.cloud + spring-cloud-config-monitor + 1.3.1.RELEASE + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + 1.2.1.RELEASE + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 1.5.4.RELEASE + + + + + diff --git a/spring-cloud-bus/spring-cloud-config-server/src/main/java/com/baeldung/SpringCloudConfigServerApplication.java b/spring-cloud-bus/spring-cloud-config-server/src/main/java/com/baeldung/SpringCloudConfigServerApplication.java new file mode 100644 index 0000000000..4feace7c89 --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-server/src/main/java/com/baeldung/SpringCloudConfigServerApplication.java @@ -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); + } +} diff --git a/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties new file mode 100644 index 0000000000..4c18c192c0 --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/spring-cloud-bus/spring-cloud-config-server/src/main/resources/config-server.jks b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/config-server.jks new file mode 100644 index 0000000000..f3dddb4a8f Binary files /dev/null and b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/config-server.jks differ diff --git a/spring-cloud-bus/spring-cloud-config-server/src/test/java/com/baeldung/SpringCloudConfigServerApplicationTests.java b/spring-cloud-bus/spring-cloud-config-server/src/test/java/com/baeldung/SpringCloudConfigServerApplicationTests.java new file mode 100644 index 0000000000..3969c7ba2d --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-server/src/test/java/com/baeldung/SpringCloudConfigServerApplicationTests.java @@ -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() { + } + +}