Skip to content

Commit 76b90fe

Browse files
authored
Chapter 5: Kafka: use dev services (#103)
1 parent c07b8ed commit 76b90fe

File tree

6 files changed

+56
-42
lines changed

6 files changed

+56
-42
lines changed

chapter-5/chapter-5-quarkus-kafka-streams/pom.xml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
1717
<quarkus.platform.version>2.0.3.Final</quarkus.platform.version>
1818
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
19-
<testcontainers.version>1.16.0</testcontainers.version>
2019
</properties>
2120
<dependencyManagement>
2221
<dependencies>
@@ -27,13 +26,6 @@
2726
<type>pom</type>
2827
<scope>import</scope>
2928
</dependency>
30-
<dependency>
31-
<groupId>org.testcontainers</groupId>
32-
<artifactId>testcontainers-bom</artifactId>
33-
<version>${testcontainers.version}</version>
34-
<type>pom</type>
35-
<scope>import</scope>
36-
</dependency>
3729
</dependencies>
3830
</dependencyManagement>
3931
<dependencies>
@@ -70,8 +62,8 @@
7062
<scope>test</scope>
7163
</dependency>
7264
<dependency>
73-
<groupId>org.testcontainers</groupId>
74-
<artifactId>testcontainers</artifactId>
65+
<groupId>org.assertj</groupId>
66+
<artifactId>assertj-core</artifactId>
7567
<scope>test</scope>
7668
</dependency>
7769
</dependencies>

chapter-5/chapter-5-quarkus-kafka-streams/src/main/java/org/acme/service/PriceConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
@ApplicationScoped
1515
public class PriceConverter {
16-
private static final double CONVERSION_RATE = 0.88;
16+
static final double CONVERSION_RATE = 0.88;
1717

1818
// Consume from the `prices` channel and produce to the `my-data-stream` channel
1919
@Incoming("prices")

chapter-5/chapter-5-quarkus-kafka-streams/src/test/java/org/acme/DockerComposeResource.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

chapter-5/chapter-5-quarkus-kafka-streams/src/test/java/org/acme/rest/PriceResourceTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
import javax.ws.rs.client.WebTarget;
1313
import javax.ws.rs.sse.SseEventSource;
1414

15-
import org.acme.DockerComposeResource;
1615
import org.junit.jupiter.api.Test;
1716

18-
import io.quarkus.test.common.QuarkusTestResource;
1917
import io.quarkus.test.common.http.TestHTTPEndpoint;
2018
import io.quarkus.test.common.http.TestHTTPResource;
2119
import io.quarkus.test.junit.QuarkusTest;
2220

2321
@QuarkusTest
24-
@QuarkusTestResource(DockerComposeResource.class)
2522
class PriceResourceTest {
2623
@TestHTTPEndpoint(PriceResource.class)
2724
@TestHTTPResource("/stream")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.acme.service;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.ValueSource;
8+
9+
class PriceConverterTests {
10+
PriceConverter priceConverter = new PriceConverter();
11+
12+
@ParameterizedTest(name = ParameterizedTest.DISPLAY_NAME_PLACEHOLDER + "[" + ParameterizedTest.INDEX_PLACEHOLDER + "] (" + ParameterizedTest.ARGUMENTS_WITH_NAMES_PLACEHOLDER + ")")
13+
@ValueSource(ints = { 1, 2 })
14+
@DisplayName("process")
15+
public void process(int price) {
16+
assertThat(this.priceConverter.process(price))
17+
.isEqualTo(price * PriceConverter.CONVERSION_RATE);
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.acme.service;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.time.Duration;
6+
import java.util.List;
7+
import java.util.function.Predicate;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import io.smallrye.mutiny.helpers.test.AssertSubscriber;
12+
13+
class PriceGeneratorTests {
14+
PriceGenerator priceGenerator = new PriceGenerator();
15+
16+
private static final Predicate<Integer> VALUE_TEST =
17+
value -> (value >= 0) && (value < 100);
18+
19+
@Test
20+
public void generatesProperly() {
21+
List<Integer> prices = this.priceGenerator.generate()
22+
.select().first(2)
23+
.subscribe().withSubscriber(AssertSubscriber.create(2))
24+
.assertSubscribed()
25+
.awaitItems(2, Duration.ofSeconds(10))
26+
.awaitCompletion(Duration.ofSeconds(15))
27+
.assertCompleted()
28+
.getItems();
29+
30+
assertThat(prices)
31+
.hasSize(2)
32+
.allMatch(VALUE_TEST);
33+
}
34+
}

0 commit comments

Comments
 (0)