-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVcApiTest.java
80 lines (64 loc) · 2.97 KB
/
VcApiTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.apicatalog.vc.service;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.codec.BodyCodec;
import io.vertx.junit5.Timeout;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
@ExtendWith(VertxExtension.class)
class VcApiTest {
static Stream<Arguments> testData() {
return Stream.of(
Arguments.of("issue - proof options", "0001-in.jsonld", "/credentials/issue", 201),
Arguments.of("verify - proof options", "0002-in.jsonld", "/credentials/verify", 200)
);
}
@BeforeEach
@DisplayName("Deploy a verticle")
void deployVerticle(Vertx vertx, VertxTestContext testContext) {
//set environmental variables
System.setProperty("VC_PUBLIC_KEY", "z6Mkska8oQD7QQQWxqa7L5ai4mH98HfAdSwomPFYKuqNyE2y");
System.setProperty("VC_PRIVATE_KEY", "zRuuyWBEr6MivrDHUX4Yd7jiGzMbGJH38EHFqQxztA4r1QY");
System.setProperty("VC_VERIFICATION_KEY", "did:key:z6Mkska8oQD7QQQWxqa7L5ai4mH98HfAdSwomPFYKuqNyE2y#z6Mkska8oQD7QQQWxqa7L5ai4mH98HfAdSwomPFYKuqNyE2y");
// start
vertx.deployVerticle(new VcApiVerticle(), testContext.succeedingThenComplete());
}
// @RepeatedTest(3)
@ParameterizedTest
@MethodSource("testData")
@Timeout(value = 10, timeUnit = TimeUnit.SECONDS)
@DisplayName("Execute a test")
void executeTest(String name, String path, String endpoint, int code, Vertx vertx, VertxTestContext testContext) throws Throwable {
try (final InputStream is = this.getClass().getResourceAsStream(path)) {
final byte[] input = is.readAllBytes();
WebClient client = WebClient.create(vertx);
client.post(8080, "localhost", endpoint)
.putHeader("content-type", "application/json")
.as(BodyCodec.string())
.sendBuffer(Buffer.buffer(input),
testContext.succeeding(response -> testContext.verify(() -> {
assertEquals(code, response.statusCode());
testContext.completeNow();
})));
}
}
@AfterEach
@DisplayName("Check that the verticle is still there")
void shutdown(Vertx vertx) {
assertNotNull(vertx.deploymentIDs());
assertEquals(1, vertx.deploymentIDs().size());
}
}