use of org.openclinica.ns.response.v31.Response in project keywhiz by square.
the class SecretResourceTest method listExpiringV2.
List<SanitizedSecret> listExpiringV2(Long time, String groupName) throws IOException {
String requestURL = "/automation/v2/secrets/expiring/v2/";
if (time != null && time > 0) {
requestURL += time.toString() + "/";
}
if (groupName != null && groupName.length() > 0) {
requestURL += groupName;
}
Request get = clientRequest(requestURL).get().build();
Response httpResponse = mutualSslClient.newCall(get).execute();
assertThat(httpResponse.code()).isEqualTo(200);
return mapper.readValue(httpResponse.body().byteStream(), new TypeReference<List<SanitizedSecret>>() {
});
}
use of org.openclinica.ns.response.v31.Response in project keywhiz by square.
the class SecretResourceTest method createOrUpdateSecret.
//---------------------------------------------------------------------------------------
// createOrUpdateSecret
//---------------------------------------------------------------------------------------
@Test
public void createOrUpdateSecret() throws Exception {
CreateOrUpdateSecretRequestV2 request = CreateOrUpdateSecretRequestV2.builder().content(encoder.encodeToString("supa secret".getBytes(UTF_8))).description("desc").metadata(ImmutableMap.of("owner", "root", "mode", "0440")).type("password").build();
Response httpResponse = createOrUpdate(request, "secret3");
assertThat(httpResponse.code()).isEqualTo(201);
URI location = URI.create(httpResponse.header(LOCATION));
assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3");
httpResponse = createOrUpdate(request, "secret3");
assertThat(httpResponse.code()).isEqualTo(201);
location = URI.create(httpResponse.header(LOCATION));
assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3");
}
use of org.openclinica.ns.response.v31.Response in project keywhiz by square.
the class SecretResourceTest method secretGroupsListing_notFound.
//---------------------------------------------------------------------------------------
// secretGroupsListing
//---------------------------------------------------------------------------------------
@Test
public void secretGroupsListing_notFound() throws Exception {
Request get = clientRequest("/automation/v2/secrets/non-existent/groups").get().build();
Response httpResponse = mutualSslClient.newCall(get).execute();
assertThat(httpResponse.code()).isEqualTo(404);
}
use of org.openclinica.ns.response.v31.Response in project keywhiz by square.
the class SecretResourceTest method modifySecretGroups_notFound.
//---------------------------------------------------------------------------------------
// modifySecretGroups
//---------------------------------------------------------------------------------------
@Test
public void modifySecretGroups_notFound() throws Exception {
ModifyGroupsRequestV2 request = ModifyGroupsRequestV2.builder().build();
RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(request));
Request put = clientRequest("/automation/v2/secrets/non-existent/groups").put(body).build();
Response httpResponse = mutualSslClient.newCall(put).execute();
assertThat(httpResponse.code()).isEqualTo(404);
}
use of org.openclinica.ns.response.v31.Response in project okhttp by square.
the class MockWebServer method handleWebSocketUpgrade.
private void handleWebSocketUpgrade(Socket socket, BufferedSource source, BufferedSink sink, RecordedRequest request, MockResponse response) throws IOException {
String key = request.getHeader("Sec-WebSocket-Key");
response.setHeader("Sec-WebSocket-Accept", WebSocketProtocol.acceptHeader(key));
writeHttpResponse(socket, sink, response);
// Adapt the request and response into our Request and Response domain model.
String scheme = request.getTlsVersion() != null ? "https" : "http";
// Has host and port.
String authority = request.getHeader("Host");
final Request fancyRequest = new Request.Builder().url(scheme + "://" + authority + "/").headers(request.getHeaders()).build();
final Response fancyResponse = new Response.Builder().code(Integer.parseInt(response.getStatus().split(" ")[1])).message(response.getStatus().split(" ", 3)[2]).headers(response.getHeaders()).request(fancyRequest).protocol(Protocol.HTTP_1_1).build();
final CountDownLatch connectionClose = new CountDownLatch(1);
RealWebSocket.Streams streams = new RealWebSocket.Streams(false, source, sink) {
@Override
public void close() {
connectionClose.countDown();
}
};
RealWebSocket webSocket = new RealWebSocket(fancyRequest, response.getWebSocketListener(), new SecureRandom());
response.getWebSocketListener().onOpen(webSocket, fancyResponse);
String name = "MockWebServer WebSocket " + request.getPath();
webSocket.initReaderAndWriter(name, 0, streams);
try {
webSocket.loopReader();
// Even if messages are no longer being read we need to wait for the connection close signal.
try {
connectionClose.await();
} catch (InterruptedException ignored) {
}
} catch (IOException e) {
webSocket.failWebSocket(e, null);
} finally {
closeQuietly(sink);
closeQuietly(source);
}
}
Aggregations