@Test
public void testCreateKey() throws Exception {
MockWebServer server = mockWebServer();
server.enqueue(new MockResponse().setBody(payloadFromResource("/key.json")));
DigitalOceanApi api = api(server.getUrl("/"));
KeyPairApi keyPairApi = api.getKeyPairApi();
try {
String publicKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-rsa.txt"));
SshKey key = keyPairApi.create("my_key", publicKey);
assertRequestHasParameters(server.takeRequest(), "/ssh_keys/new",
ImmutableMultimap.of("name", "my_key", "ssh_pub_key", publicKey));
assertEquals(key.getId(), 47);
assertEquals(key.getName(), "my_key");
assertNotNull(key.getPublicKey());
} finally {
api.close();
server.shutdown();
}
}