use of com.quorum.gauge.ext.ObjectResponse in project quorum-acceptance-tests by ConsenSys.
the class PluginSecurity method invokeMultipleWithExpectation.
@Step("`<clientId>` sends a batch `<apis>` to `<node>` and expect: <table>")
public void invokeMultipleWithExpectation(String clientId, String apis, QuorumNetworkProperty.Node node, Table table) {
String token = mustHaveValue(DataStoreFactory.getScenarioDataStore(), clientId, String.class);
Context.storeAccessToken(token);
BatchRequest.Collector collector = BatchRequest.Collector.create();
Arrays.stream(apis.split(",")).map(String::trim).forEach(n -> collector.add(n, Collections.emptyList()));
Map<String, String> expect = table.getTableRows().stream().collect(Collectors.toMap(r -> StringUtils.removeEnd(StringUtils.removeStart(r.getCell("callApi"), "`"), "`"), r -> r.getCell("expectation")));
rpcService.call(node, collector).blockingForEach(batchResponse -> {
assertThat(batchResponse.getResponses()).as("Number of returned responses").hasSize(collector.size());
for (ObjectResponse res : batchResponse.getResponses()) {
assertThat(res.getId()).as("Response must have id").isNotZero();
Request r = collector.getByID(res.getId());
String policy = Optional.ofNullable(expect.get(r.getMethod())).orElseThrow(() -> new IllegalStateException("no such method in expectation table: " + r.getMethod()));
boolean expectAuthorized = "success".equalsIgnoreCase(policy);
String description = policy + ": " + r.getMethod() + "@" + node.getName();
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
}
});
}
use of com.quorum.gauge.ext.ObjectResponse in project quorum-acceptance-tests by ConsenSys.
the class PluginSecurity method invokeMultiple.
@Step("`<clientId>` is responded with <policy> when trying to: <table>")
public void invokeMultiple(String clientId, String policy, Table table) {
boolean expectAuthorized = "success".equalsIgnoreCase(policy);
String token = mustHaveValue(DataStoreFactory.getScenarioDataStore(), clientId, String.class);
Context.storeAccessToken(token);
Map<String, QuorumNetworkProperty.Node> nodeMap = networkProperty.getNodes();
table.getTableRows().stream().map(r -> new ApiCall(r.getCell("callApi"), r.getCell("targetNode"))).onClose(Context::removeAccessToken).forEach(a -> {
if (a.isBatch) {
rpcService.call(nodeMap.get(a.node), a.collector).blockingForEach(batchResponse -> {
assertThat(batchResponse.getResponses()).as("Number of returned responses").hasSize(a.collector.size());
for (ObjectResponse res : batchResponse.getResponses()) {
assertThat(res.getId()).as("Response must have id").isNotZero();
Request r = a.collector.getByID(res.getId());
String description = policy + ": " + r.getMethod() + "@" + a.node;
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
}
});
} else {
rpcService.call(nodeMap.get(a.node), a.name, Collections.emptyList(), ObjectResponse.class).blockingForEach(res -> {
assertThat(res.getId()).as("Response must have ID").isNotZero();
String description = policy + ": " + a.name + "@" + a.node;
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
});
}
});
}
Aggregations