Skip to content

Commit 40b5e54

Browse files
MakarovSdmitry-timofeev
authored andcommitted
Add TestKit to BOM and archetype modules [ECR-3056] (#989)
Also add a test with testkit that verifies the correctness of the installation.
1 parent 6f076b8 commit 40b5e54

File tree

4 files changed

+51
-27
lines changed

4 files changed

+51
-27
lines changed

exonum-java-binding/bom/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
<version>${project.version}</version>
3636
</dependency>
3737

38+
<dependency>
39+
<groupId>com.exonum.binding</groupId>
40+
<artifactId>exonum-testkit</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
3844
<!-- Exported third-party artefacts the services depend upon. -->
3945
<dependency>
4046
<groupId>io.vertx</groupId>

exonum-java-binding/service-archetype/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
</properties>
2323

2424
<dependencies>
25-
<!-- The archetype has to have a dependency on core so that it is built strictly after it.
25+
<!-- The archetype has to have a dependency on core and TestKit so that it is built strictly
26+
after those.
2627
2728
The ITs naturally generate a project that is not a child of the parent project.
2829
Therefore, they also require that the core and its dependencies are available in the (local)
@@ -34,6 +35,13 @@
3435
<version>${project.version}</version>
3536
<scope>runtime</scope>
3637
</dependency>
38+
39+
<dependency>
40+
<groupId>com.exonum.binding</groupId>
41+
<artifactId>exonum-testkit</artifactId>
42+
<version>${project.version}</version>
43+
<scope>runtime</scope>
44+
</dependency>
3745
</dependencies>
3846

3947
<build>
@@ -43,6 +51,11 @@
4351
<groupId>org.apache.maven.plugins</groupId>
4452
<artifactId>maven-archetype-plugin</artifactId>
4553
<version>${maven-archetype.version}</version>
54+
<configuration>
55+
<properties>
56+
<nativeLibPath>${project.parent.basedir}/core/rust/target/debug</nativeLibPath>
57+
</properties>
58+
</configuration>
4659
<executions>
4760
<execution>
4861
<goals>

exonum-java-binding/service-archetype/src/main/resources/archetype-resources/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<java.compiler.source>8</java.compiler.source>
1717
<java.compiler.target>8</java.compiler.target>
1818
<junit.jupiter.version>5.5.0</junit.jupiter.version>
19+
<nativeLibPath>${env.EXONUM_HOME}/lib/native</nativeLibPath>
1920
<hamcrest.version>2.1</hamcrest.version>
2021
<mockito.version>3.0.0</mockito.version>
2122
<exonum.version>0.7.0-SNAPSHOT</exonum.version>
@@ -72,6 +73,12 @@
7273
<scope>test</scope>
7374
</dependency>
7475

76+
<dependency>
77+
<groupId>com.exonum.binding</groupId>
78+
<artifactId>exonum-testkit</artifactId>
79+
<scope>test</scope>
80+
</dependency>
81+
7582
<dependency>
7683
<groupId>io.vertx</groupId>
7784
<artifactId>vertx-web-client</artifactId>
@@ -117,7 +124,7 @@
117124
<version>2.22.2</version>
118125
<configuration>
119126
<argLine>
120-
-Djava.library.path=${env.EXONUM_HOME}/lib/native
127+
-Djava.library.path=${nativeLibPath}
121128
</argLine>
122129
</configuration>
123130
</plugin>
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright 2018 The Exonum Team
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,36 +16,34 @@
1616

1717
package ${package};
1818

19-
import static org.hamcrest.CoreMatchers.instanceOf;
2019
import static org.hamcrest.MatcherAssert.assertThat;
20+
import static org.hamcrest.Matchers.equalTo;
2121

22-
import com.exonum.binding.core.service.Service;
23-
import com.exonum.binding.core.service.TransactionConverter;
24-
import com.google.inject.Guice;
25-
import com.google.inject.Injector;
22+
import com.exonum.binding.core.blockchain.Blockchain;
23+
import com.exonum.binding.testkit.TestKit;
2624
import org.junit.jupiter.api.Test;
2725

2826
class ServiceModuleTest {
2927

28+
/**
29+
* This is an example service integration test with Exonum Testkit. It simply verifies
30+
* that a Service can be instantiated by Testkit, and that the libraries required for Testkit
31+
* operation are accessible.
32+
*
33+
* <p>If you get an UnsatisfiedLinkError in this test — please check that the EXONUM_HOME
34+
* environment variable is set properly:
35+
* https://exonum.com/doc/version/latest/get-started/java-binding/#after-install
36+
*/
3037
@Test
31-
void testServiceBinding() {
32-
Injector injector = createInjector();
33-
34-
Service s = injector.getInstance(Service.class);
35-
36-
assertThat(s, instanceOf(MyService.class));
37-
}
38-
39-
@Test
40-
void testTransactionConverterBinding() {
41-
Injector injector = createInjector();
42-
43-
TransactionConverter s = injector.getInstance(TransactionConverter.class);
44-
45-
assertThat(s, instanceOf(MyTransactionConverter.class));
46-
}
47-
48-
private static Injector createInjector() {
49-
return Guice.createInjector(new ServiceModule());
38+
void testServiceInstantiation() {
39+
try (TestKit testKit = TestKit.forService(ServiceModule.class)) {
40+
MyService service = testKit.getService(MyService.ID, MyService.class);
41+
42+
// Check that genesis block was committed
43+
testKit.withSnapshot((view) -> {
44+
Blockchain blockchain = Blockchain.newInstance(view);
45+
assertThat(blockchain.getBlockHashes().size(), equalTo(1L));
46+
});
47+
}
5048
}
5149
}

0 commit comments

Comments
 (0)