Skip to content

Commit

Permalink
2) Integration test that contains classpath from both modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuud committed Aug 7, 2022
1 parent 2b8fcd5 commit cfbebf6
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
@@ -1 +1,3 @@
1) Initial code
1) Initial
code [rev:2b8fcd50](https://github.com/Fuud/integration-tests-article/commit/2b8fcd509151ebc83c24d2b4e9fd0b665eb82ded)
2) Integration test module contains classpath from both microservices.
Expand Up @@ -9,7 +9,7 @@
public class ClientServiceApplication {

public static void main(String[] args) {
SpringApplication.run(ClientServiceApplication.class, args);
SpringApplication.run(ClientServiceApplication.class, "--spring.config.name=application-client");
}

}
46 changes: 46 additions & 0 deletions integration-tests/pom.xml
@@ -0,0 +1,46 @@
<?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">
<parent>
<artifactId>parent</artifactId>
<groupId>com.github.fuud.habr-article-microservices</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>integration-tests</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.github.fuud.habr-article-microservices</groupId>
<artifactId>client-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.fuud.habr-article-microservices</groupId>
<artifactId>worker-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.1.3</version>
</dependency>
</dependencies>

</project>
33 changes: 33 additions & 0 deletions integration-tests/src/test/java/fuud/test/TaskIntegrationTest.java
@@ -0,0 +1,33 @@
package fuud.test;

import fuud.client.service.ClientServiceApplication;
import fuud.worker.service.WorkerServiceApplication;
import org.junit.Test;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class TaskIntegrationTest {
@Test
public void testTaskSubmission() throws Exception {
ClientServiceApplication.main(new String[0]);
WorkerServiceApplication.main(new String[0]);

HttpResponse<String> response = HttpClient.newBuilder().build().send(
HttpRequest.newBuilder()
.method("POST", HttpRequest.BodyPublishers.ofString("{ \"data\":\"my-data\"}"))
.header("Content-Type", "application/json")
.uri(URI.create("http://localhost:8080/task"))
.build(),
HttpResponse.BodyHandlers.ofString()
);

assertEquals(response.statusCode(), 200);
assertFalse(response.body().isBlank());
}
}
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -11,6 +11,7 @@
<modules>
<module>client-service</module>
<module>worker-service</module>
<module>integration-tests</module>
</modules>

<properties>
Expand Down
Expand Up @@ -4,12 +4,12 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;

@SpringBootApplication
@SpringBootApplication()
@ConfigurationPropertiesScan
public class WorkerServiceApplication {

public static void main(String[] args) {
SpringApplication.run(WorkerServiceApplication.class, args);
SpringApplication.run(WorkerServiceApplication.class, "--spring.config.name=application-worker");
}

}

0 comments on commit cfbebf6

Please sign in to comment.