Skip to content

Commit 60b66c5

Browse files
authored
Merge pull request #10 from unicitynetwork/java-sdk-cucumber-test
Java sdk cucumber test
2 parents a2ad60b + 9b29de7 commit 60b66c5

16 files changed

Lines changed: 2766 additions & 50 deletions

README.md

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,44 @@ A Java SDK for interacting with the Unicity network, enabling state transitions
1919

2020
## Installation
2121

22-
### Gradle (JVM)
22+
### Using JitPack
2323

24+
Add JitPack repository:
2425
```groovy
25-
dependencies {
26-
implementation 'com.unicity.sdk:unicity-sdk:1.0-SNAPSHOT'
26+
repositories {
27+
maven { url 'https://jitpack.io' }
2728
}
2829
```
2930

30-
### Gradle (Android)
31+
#### For Android Projects:
32+
```groovy
33+
dependencies {
34+
implementation 'com.github.unicitynetwork:java-state-transition-sdk:1.1:android'
35+
}
36+
```
3137

38+
#### For JVM Projects:
3239
```groovy
3340
dependencies {
34-
implementation 'com.unicity.sdk:unicity-sdk-android:1.0-SNAPSHOT'
41+
implementation 'com.github.unicitynetwork:java-state-transition-sdk:1.1:jvm'
3542
}
3643
```
3744

38-
### Maven (JVM)
45+
### Using Local Maven
3946

40-
```xml
41-
<dependency>
42-
<groupId>com.unicity.sdk</groupId>
43-
<artifactId>unicity-sdk</artifactId>
44-
<version>1.0-SNAPSHOT</version>
45-
</dependency>
47+
```groovy
48+
dependencies {
49+
implementation 'org.unicitylabs:java-state-transition-sdk:1.1-SNAPSHOT'
50+
}
4651
```
4752

4853
## Quick Start
4954

5055
### Initialize the Client
5156

5257
```java
53-
import com.unicity.sdk.StateTransitionClient;
54-
import com.unicity.sdk.api.AggregatorClient;
58+
import org.unicitylabs.sdk.StateTransitionClient;
59+
import org.unicitylabs.sdk.api.AggregatorClient;
5560

5661
// Connect to the Unicity test network
5762
String aggregatorUrl = "https://gateway-test.unicity.network";
@@ -62,12 +67,12 @@ StateTransitionClient client = new StateTransitionClient(aggregatorClient);
6267
### Mint a Token
6368

6469
```java
65-
import com.unicity.sdk.token.*;
66-
import com.unicity.sdk.token.fungible.*;
67-
import com.unicity.sdk.transaction.*;
68-
import com.unicity.sdk.predicate.*;
69-
import com.unicity.sdk.shared.signing.SigningService;
70-
import com.unicity.sdk.shared.hash.HashAlgorithm;
70+
import org.unicitylabs.sdk.token.*;
71+
import org.unicitylabs.sdk.token.fungible.*;
72+
import org.unicitylabs.sdk.transaction.*;
73+
import org.unicitylabs.sdk.predicate.*;
74+
import org.unicitylabs.sdk.signing.SigningService;
75+
import org.unicitylabs.sdk.hash.HashAlgorithm;
7176

7277
// Create signing service from secret
7378
byte[] secret = "your-secret-key".getBytes();
@@ -227,7 +232,7 @@ Token<?> updatedToken = client.finishTransaction(
227232
### Clone the Repository
228233

229234
```bash
230-
git clone https://github.com/unicity/java-state-transition-sdk.git
235+
git clone https://github.com/unicitynetwork/java-state-transition-sdk.git
231236
cd java-state-transition-sdk
232237
```
233238

@@ -247,7 +252,7 @@ cd java-state-transition-sdk
247252
./gradlew integrationTest
248253

249254
# Run E2E tests against deployed aggregator
250-
AGGREGATOR_URL=https://gateway-test.unicity.network ./gradlew integrationTest --tests "*E2ETest"
255+
AGGREGATOR_URL=https://gateway-test.unicity.network ./gradlew integrationTest
251256
```
252257

253258
## Platform-Specific Considerations
@@ -268,23 +273,25 @@ The standard JVM version uses:
268273

269274
## Architecture
270275

271-
The SDK follows a modular architecture:
276+
The SDK follows a modular architecture under `org.unicitylabs.sdk`:
272277

273278
- **`api`**: Core API interfaces and aggregator client
274-
- **`api`**: Core API interfaces and aggregator client
275-
- **`address`**: Address schemes and implementations
276-
- **`predicate`**: Ownership predicates (Masked, Unmasked, Burn) and authorization
277-
- **`serializer`**: CBOR and JSON serializers for tokens and transactions
278-
- **`token`**: Token-related classes (TokenId, TokenType, TokenState) and fungible token support
279-
- **`transaction`**: Transaction types (Mint, Transfer, Commitment) and builders
280-
- **`shared`**: Common utilities
281-
- `cbor`: CBOR encoding/decoding
282-
- `hash`: Cryptographic hashing (SHA256, SHA224, SHA384, SHA512, RIPEMD160)
283-
- `jsonrpc`: JSON-RPC transport layer
284-
- `signing`: Digital signature support (ECDSA secp256k1)
285-
- `smt`/`smst`: Sparse Merkle Tree implementations
286-
- `util`: BitString and other utilities
287-
- **`utils`**: Helper utilities
279+
- **`address`**: Address schemes and implementations (DirectAddress, ProxyAddress)
280+
- **`hash`**: Cryptographic hashing (SHA256, SHA224, SHA384, SHA512, RIPEMD160)
281+
- **`jsonrpc`**: JSON-RPC transport layer with OkHttp
282+
- **`mtree`**: Merkle tree implementations
283+
- `plain`: Sparse Merkle Tree (SMT)
284+
- `sum`: Sparse Merkle Sum Tree (SMST)
285+
- **`predicate`**: Ownership predicates (Masked, Unmasked, Burn, Default)
286+
- **`serializer`**: CBOR and JSON serializers hierarchy
287+
- `cbor/`: CBOR serializers for all domain objects
288+
- `json/`: JSON serializers for all domain objects
289+
- **`signing`**: Digital signature support (ECDSA secp256k1)
290+
- **`token`**: Token types including fungible tokens and nametags
291+
- `fungible`: Fungible token support with CoinId and TokenCoinData
292+
- **`transaction`**: Transaction types and builders
293+
- `split`: Token splitting functionality with TokenSplitBuilder
294+
- **`util`**: Utilities including BitString and HexConverter
288295

289296
## Error Handling
290297

@@ -326,9 +333,10 @@ The SDK includes comprehensive test suites:
326333
Located in `src/test/java`, these test individual components in isolation.
327334

328335
### Integration Tests
329-
Located in `src/test/java/com/unicity/sdk/integration`:
330-
- `TokenIntegrationTest`: Tests against Docker-based local aggregator
331-
- `TokenE2ETest`: Tests against deployed aggregator (requires `AGGREGATOR_URL` env var)
336+
Located in `src/test/java/org/unicitylabs/sdk/`:
337+
- `integration/TokenIntegrationTest`: Tests against Docker-based local aggregator
338+
- `e2e/TokenE2ETest`: E2E tests using CommonTestFlow (requires `AGGREGATOR_URL` env var)
339+
- `e2e/BasicE2ETest`: Basic connectivity and performance tests
332340

333341
### Running Tests
334342

@@ -340,7 +348,7 @@ Located in `src/test/java/com/unicity/sdk/integration`:
340348
./gradlew integrationTest
341349

342350
# Specific test class
343-
./gradlew test --tests "com.unicity.sdk.api.RequestIdTest"
351+
./gradlew test --tests "org.unicitylabs.sdk.api.RequestIdTest"
344352
```
345353

346354
## License

build.gradle.kts

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@ dependencies {
4848
testImplementation("org.testcontainers:testcontainers:1.19.8")
4949
testImplementation("org.testcontainers:junit-jupiter:1.19.8")
5050
testImplementation("org.testcontainers:mongodb:1.19.8")
51+
testImplementation("org.awaitility:awaitility:4.2.0")
5152
testImplementation("org.slf4j:slf4j-simple:2.0.13")
5253
testImplementation("com.google.guava:guava:33.0.0-jre")
5354

55+
// ✅ Cucumber for BDD
56+
testImplementation("io.cucumber:cucumber-java:7.27.2")
57+
testImplementation("io.cucumber:cucumber-junit-platform-engine:7.27.2")
58+
59+
// JUnit 5 Suite annotations
60+
testImplementation("org.junit.platform:junit-platform-suite:1.13.4")
61+
5462
checkstyle("com.puppycrawl.tools:checkstyle:10.26.1")
5563
}
5664

@@ -70,9 +78,16 @@ tasks.test {
7078
excludeTags("integration")
7179
}
7280
maxHeapSize = "1024m"
81+
systemProperty("cucumber.junit-platform.naming-strategy", "long")
82+
systemProperties(System.getProperties().toMap() as Map<String, Any>)
83+
84+
filter {
85+
excludeTestsMatching("*CucumberTestRunner*")
86+
excludeTestsMatching("*Cucumber*")
87+
}
7388
}
7489

75-
tasks.withType<Checkstyle>{
90+
tasks.withType<Checkstyle> {
7691
reports {
7792
xml.required.set(false)
7893
html.required.set(true)
@@ -85,6 +100,69 @@ tasks.register<Test>("integrationTest") {
85100
}
86101
maxHeapSize = "2048m"
87102
shouldRunAfter(tasks.test)
103+
systemProperty("cucumber.junit-platform.naming-strategy", "long")
104+
105+
filter {
106+
excludeTestsMatching("*CucumberTestRunner*")
107+
excludeTestsMatching("*Cucumber*")
108+
}
109+
}
110+
111+
tasks.register<Test>("tokenTests") {
112+
useJUnitPlatform()
113+
maxHeapSize = "1024m"
114+
systemProperty("cucumber.junit-platform.naming-strategy", "long")
115+
// Set the system properties first
116+
systemProperties = System.getProperties().toMap() as Map<String, Any>
117+
// Then override the specific cucumber filter (this will take precedence)
118+
systemProperty("cucumber.filter.tags", "@token-transfer")
119+
120+
filter {
121+
includeTestsMatching("*CucumberTestRunner*")
122+
}
123+
shouldRunAfter(tasks.test)
124+
}
125+
126+
tasks.register<Test>("aggregatorTests") {
127+
useJUnitPlatform()
128+
maxHeapSize = "1024m"
129+
systemProperty("cucumber.junit-platform.naming-strategy", "long")
130+
// Set the system properties first
131+
systemProperties = System.getProperties().toMap() as Map<String, Any>
132+
systemProperty("cucumber.filter.tags", "@aggregator-connectivity")
133+
134+
filter {
135+
includeTestsMatching("*CucumberTestRunner*")
136+
}
137+
shouldRunAfter(tasks.test)
138+
}
139+
140+
tasks.register<Test>("advancedTokenTests") {
141+
useJUnitPlatform()
142+
maxHeapSize = "1024m"
143+
systemProperty("cucumber.junit-platform.naming-strategy", "long")
144+
// Set the system properties first
145+
systemProperties = System.getProperties().toMap() as Map<String, Any>
146+
systemProperty("cucumber.filter.tags", "@advanced-token")
147+
148+
filter {
149+
includeTestsMatching("*CucumberTestRunner*")
150+
}
151+
shouldRunAfter(tasks.test)
152+
}
153+
154+
// ✅ Run all cucumber tests (including integration)
155+
tasks.register<Test>("allCucumberTests") {
156+
useJUnitPlatform()
157+
maxHeapSize = "1024m"
158+
systemProperty("cucumber.junit-platform.naming-strategy", "long")
159+
systemProperties = System.getProperties().toMap() as Map<String, Any>
160+
systemProperty("cucumber.filter.tags", "not @ignore")
161+
162+
filter {
163+
includeTestsMatching("*CucumberTestRunner*")
164+
}
165+
shouldRunAfter(tasks.test)
88166
}
89167

90168
// Create separate JARs for each platform
@@ -112,40 +190,40 @@ publishing {
112190
groupId = project.group.toString()
113191
artifactId = "java-state-transition-sdk"
114192
version = project.version.toString()
115-
193+
116194
// Use the Java component as base - this includes the standard JAR
117195
from(components["java"])
118-
196+
119197
// Add Android JAR as additional artifact with classifier
120198
artifact(tasks["androidJar"]) {
121199
classifier = "android"
122200
}
123-
124-
// Add JVM JAR as additional artifact with classifier
201+
202+
// Add JVM JAR as additional artifact with classifier
125203
artifact(tasks["jvmJar"]) {
126204
classifier = "jvm"
127205
}
128-
206+
129207
// Simple POM configuration without XML manipulation
130208
pom {
131209
name.set("Unicity State Transition SDK")
132210
description.set("Unicity State Transition SDK for Android and JVM")
133211
url.set("https://github.com/unicitynetwork/java-state-transition-sdk")
134-
212+
135213
licenses {
136214
license {
137215
name.set("MIT License")
138216
url.set("https://opensource.org/licenses/MIT")
139217
}
140218
}
141-
219+
142220
developers {
143221
developer {
144222
id.set("unicitynetwork")
145223
name.set("Unicity Network")
146224
}
147225
}
148-
226+
149227
scm {
150228
connection.set("scm:git:git://github.com/unicitynetwork/java-state-transition-sdk.git")
151229
developerConnection.set("scm:git:ssh://github.com/unicitynetwork/java-state-transition-sdk.git")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.unicitylabs.sdk.e2e;
2+
3+
import io.cucumber.junit.platform.engine.Constants;
4+
import org.junit.platform.suite.api.*;
5+
6+
/**
7+
* Updated Cucumber test runner configuration for E2E tests.
8+
* This class configures the test execution environment and feature discovery
9+
* with the new shared step definitions approach.
10+
*/
11+
@Suite
12+
@IncludeEngines("cucumber")
13+
@SelectPackages("org.unicitylabs.sdk.features")
14+
@ConfigurationParameter(key = Constants.GLUE_PROPERTY_NAME, value = "org.unicitylabs.sdk.e2e.steps,org.unicitylabs.sdk.e2e.steps.shared,org.unicitylabs.sdk.e2e.config")
15+
@ConfigurationParameter(key = Constants.PLUGIN_PROPERTY_NAME, value = "pretty,html:build/cucumber-reports/cucumber.html,json:build/cucumber-reports/cucumber.json")
16+
@ConfigurationParameter(key = Constants.EXECUTION_DRY_RUN_PROPERTY_NAME, value = "false")
17+
@ConfigurationParameter(key = Constants.PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true")
18+
public class CucumberTestRunner {
19+
static {
20+
// Only set default tags if no tags are specified
21+
if (System.getProperty("cucumber.filter.tags") == null) {
22+
System.setProperty("cucumber.filter.tags", "not @ignore");
23+
}
24+
}
25+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.unicitylabs.sdk.e2e.config;
2+
3+
import org.unicitylabs.sdk.e2e.context.TestContext;
4+
import io.cucumber.java.Before;
5+
import io.cucumber.java.After;
6+
7+
/**
8+
* Cucumber configuration for dependency injection and test lifecycle management.
9+
* This ensures that TestContext is properly shared across all step definition classes.
10+
*/
11+
public class CucumberConfiguration {
12+
13+
private static TestContext testContext = new TestContext();
14+
15+
/**
16+
* Provides a shared TestContext instance for all step definition classes.
17+
* This method will be called by step definition classes to get
18+
* the shared TestContext instance.
19+
*/
20+
public static TestContext getTestContext() {
21+
return testContext;
22+
}
23+
24+
/**
25+
* Hook that runs before each scenario to reset the test context.
26+
* This ensures each scenario starts with a clean state.
27+
*/
28+
@Before
29+
public void setUp() {
30+
testContext.clearTestState(); // Clear test state but keep clients if they exist
31+
System.out.println("Test context cleared for new scenario");
32+
}
33+
34+
/**
35+
* Hook that runs after each scenario for cleanup.
36+
* This can be used for any additional cleanup if needed.
37+
*/
38+
@After
39+
public void tearDown() {
40+
// Optional: Add any cleanup logic here
41+
// For now, we keep the context alive for potential debugging
42+
System.out.println("Scenario completed");
43+
}
44+
45+
/**
46+
* Hook that runs after scenarios tagged with @reset to completely reset the context.
47+
*/
48+
@After("@reset")
49+
public void fullReset() {
50+
testContext.reset();
51+
System.out.println("Full context reset performed");
52+
}
53+
}

0 commit comments

Comments
 (0)