-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration test with multiple aca-py agents #13
base: main
Are you sure you want to change the base?
Changes from 6 commits
ccdc49e
67bdf2f
33474db
324aae1
901af34
bc3a8b4
78f55ac
e674b4a
5d1f4ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (c) 2020-2021 - for information on the respective copyright owner | ||
* see the NOTICE file and/or the repository at | ||
* https://github.com/hyperledger-labs/acapy-java-client | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.aries; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import org.hyperledger.aries.util.ledger.LedgerDIDCreate; | ||
import org.hyperledger.aries.util.ledger.LedgerDIDResponse; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.*; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* ACA-PY client | ||
*/ | ||
@Slf4j | ||
@SuppressWarnings("unused") | ||
public class LedgerClient extends BaseClient { | ||
|
||
public static final String LEDGER_GENESIS_TXN_URL = "/genesis"; | ||
public static final String LEDGER_DID_REGISTRATION_URL = "/register"; | ||
public static final String LEDGER_DID_ENDORSER_ROLE = "ENDORSER"; | ||
|
||
private final String url; | ||
|
||
/** | ||
* @param url The ledger URL without a path e.g. protocol://host:[port] | ||
* @param client {@link OkHttpClient} if null a default client is created | ||
*/ | ||
@Builder | ||
public LedgerClient(@NonNull String url, | ||
@Nullable OkHttpClient client) { | ||
super(client); | ||
this.url = StringUtils.trim(url); | ||
} | ||
|
||
// ---------------------------------------------------- | ||
// Register a new public DID on the ledger | ||
// ---------------------------------------------------- | ||
|
||
/** | ||
* Create a public DID | ||
* @param didCreate {@link DIDCreate} | ||
* @return {@link DID} | ||
* @throws IOException if the request could not be executed due to cancellation, a connectivity problem or timeout. | ||
*/ | ||
public Optional<LedgerDIDResponse> ledgerDidCreate(@NonNull LedgerDIDCreate didCreate) throws IOException { | ||
Request req = buildPost(url + LEDGER_DID_REGISTRATION_URL, didCreate); | ||
return call(req, LedgerDIDResponse.class); | ||
} | ||
|
||
|
||
// ---------------------------------------------------- | ||
// Internal | ||
// ---------------------------------------------------- | ||
|
||
private Request buildPost(String u, Object body) { | ||
return request(u) | ||
.post(jsonBody(gson.toJson(body))) | ||
.build(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code below |
||
private Request buildPut(String u, Object body) { | ||
return request(u) | ||
.put(jsonBody(gson.toJson(body))) | ||
.build(); | ||
} | ||
|
||
private Request buildPatch(String u, Object body) { | ||
return request(u) | ||
.patch(jsonBody(gson.toJson(body))) | ||
.build(); | ||
} | ||
|
||
private Request buildGet(String u) { | ||
return request(u) | ||
.get() | ||
.build(); | ||
} | ||
|
||
private Request buildDelete(String u) { | ||
return request(u) | ||
.delete() | ||
.build(); | ||
} | ||
|
||
private Request.Builder request(String u) { | ||
Request.Builder b = new Request.Builder() | ||
.url(u); | ||
return b; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2020-2021 - for information on the respective copyright owner | ||
* see the NOTICE file and/or the repository at | ||
* https://github.com/hyperledger-labs/acapy-java-client | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.aries; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@Testcontainers | ||
public abstract class MultiIntegrationTestBase { | ||
|
||
private final Logger log = LoggerFactory.getLogger(MultiIntegrationTestBase.class); | ||
|
||
public static final String ARIES_VERSION = "bcgovimages/aries-cloudagent:py36-1.16-1_0.7.2"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a single version for all tests so I would use the one from IntegrationTestBase |
||
public static final Integer ARIES_ENDPOINT_PORT = 8030; | ||
public static final Integer ARIES_ADMIN_PORT = 8031; | ||
public static final Integer ARIES_ENDPOINT_PORT_2 = 8040; | ||
public static final Integer ARIES_ADMIN_PORT_2 = 8041; | ||
|
||
protected LedgerClient lc; | ||
protected AriesClient ac; | ||
protected AriesClient ac2; | ||
|
||
Network network = Network.newNetwork(); | ||
|
||
@Container | ||
protected GenericContainer<?> ariesContainer = new GenericContainer<>(ARIES_VERSION) | ||
.withNetwork(network) | ||
.withNetworkAliases("agent_1") | ||
.withExposedPorts(ARIES_ADMIN_PORT) | ||
.withCommand("start" | ||
+ " -it http 0.0.0.0 " + ARIES_ENDPOINT_PORT | ||
+ " -ot http" | ||
+ " --admin 0.0.0.0 " + ARIES_ADMIN_PORT | ||
+ " --admin-insecure-mode" | ||
+ " --log-level debug" | ||
+ " -e http://agent_1:" + ARIES_ENDPOINT_PORT | ||
+ " --plugin aries_cloudagent.messaging.jsonld" | ||
+ this.extraAgentArgs(1)) | ||
.waitingFor(Wait.defaultWaitStrategy()) | ||
.withLogConsumer(new Slf4jLogConsumer(log)) | ||
; | ||
|
||
@Container | ||
protected GenericContainer<?> ariesContainer2 = new GenericContainer<>(ARIES_VERSION) | ||
.withExposedPorts(ARIES_ADMIN_PORT_2) | ||
.withNetwork(network) | ||
.withNetworkAliases("agent_2") | ||
.withCommand("start" | ||
+ " -it http 0.0.0.0 " + ARIES_ENDPOINT_PORT_2 | ||
+ " -ot http" | ||
+ " --admin 0.0.0.0 " + ARIES_ADMIN_PORT_2 | ||
+ " --admin-insecure-mode" | ||
+ " --log-level debug" | ||
+ " -e http://agent_2:" + ARIES_ENDPOINT_PORT_2 | ||
+ " --plugin aries_cloudagent.messaging.jsonld" | ||
+ this.extraAgentArgs(2)) | ||
.waitingFor(Wait.defaultWaitStrategy()) | ||
.withLogConsumer(new Slf4jLogConsumer(log)) | ||
; | ||
|
||
protected String extraAgentArgs(int agentNum) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The api is a bit confusing, I would also make that method abstract. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I would split this up into two abstract methods like agentOneArgs() and agentTwoArgs, then you do not have to use switches all the time |
||
return " --no-ledger"; | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
ac = AriesClient.builder() | ||
.url("http://" + ariesContainer.getHost() + ":" + ariesContainer.getMappedPort(ARIES_ADMIN_PORT)) | ||
.build(); | ||
ac2 = AriesClient.builder() | ||
.url("http://" + ariesContainer2.getHost() + ":" + ariesContainer2.getMappedPort(ARIES_ADMIN_PORT_2)) | ||
.build(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be useful to have this in the main package