Package org.jclouds.chef.domain

Examples of org.jclouds.chef.domain.Client$Builder


   private Json json = injector.getInstance(Json.class);

   @Test(expectedExceptions = IllegalStateException.class)
   public void testWhenNoDatabagItem() throws IOException {
      ChefApi chefApi = createMock(ChefApi.class);
      Client client = createMock(Client.class);

      RunListForGroup fn = new RunListForGroup(new BootstrapConfigForGroup("jclouds", chefApi), json);

      expect(chefApi.getDatabagItem("jclouds", "foo")).andReturn(null);
View Full Code Here


   }

   @Override
   public Client apply(String from) {
      String clientName = findNextClientName(chefApi.listClients(), from + "-client-%02d");
      Client client = chefApi.createClient(clientName);
      // response from create only includes the key
      return Client.builder() //
            .clientname(clientName) //
            .name(clientName) //
            .isValidator(false) //
            .privateKey(client.getPrivateKey()) //
            .build();
   }
View Full Code Here

public class BootstrapConfigForGroupTest {

   @Test(expectedExceptions = IllegalStateException.class)
   public void testWhenNoDatabagItem() throws IOException {
      ChefApi chefApi = createMock(ChefApi.class);
      Client client = createMock(Client.class);

      BootstrapConfigForGroup fn = new BootstrapConfigForGroup("jclouds", chefApi);

      expect(chefApi.getDatabagItem("jclouds", "foo")).andReturn(null);
View Full Code Here

      overrides.setProperty(provider + ".credential", credential);

      A clientApi = create(overrides, setupModules());

      try {
         Client client = clientApi.getClient(identity);
         assertNotNull(client, "Client not found: " + identity);
      } finally {
         try {
            Closeables.close(clientApi, true);
         } catch (IOException e) {
View Full Code Here

@Test(groups = "unit", testName = "ClientForGroupTest")
public class ClientForGroupTest {

   public void testWhenNoClientsInList() throws IOException {
      ChefApi chefApi = createMock(ChefApi.class);
      Client client = createMock(Client.class);
      PrivateKey privateKey = createMock(PrivateKey.class);

      ClientForGroup fn = new ClientForGroup(chefApi);

      expect(chefApi.listClients()).andReturn(ImmutableSet.<String> of());
      expect(chefApi.createClient("foo-client-00")).andReturn(client);
      expect(client.getPrivateKey()).andReturn(privateKey);

      replay(client);
      replay(chefApi);

      Client compare = fn.apply("foo");
      assertEquals(compare.getClientname(), "foo-client-00");
      assertEquals(compare.getName(), "foo-client-00");
      assertEquals(compare.getPrivateKey(), privateKey);

      verify(client);
      verify(chefApi);
   }
View Full Code Here

      verify(chefApi);
   }

   public void testWhenClientsInListAddsToEnd() throws IOException {
      ChefApi chefApi = createMock(ChefApi.class);
      Client client = createMock(Client.class);
      PrivateKey privateKey = createMock(PrivateKey.class);

      ClientForGroup fn = new ClientForGroup(chefApi);

      expect(chefApi.listClients()).andReturn(
            ImmutableSet.<String> of("foo-client-00", "foo-client-01", "foo-client-02"));
      expect(chefApi.createClient("foo-client-03")).andReturn(client);
      expect(client.getPrivateKey()).andReturn(privateKey);

      replay(client);
      replay(chefApi);

      Client compare = fn.apply("foo");
      assertEquals(compare.getClientname(), "foo-client-03");
      assertEquals(compare.getName(), "foo-client-03");
      assertEquals(compare.getPrivateKey(), privateKey);

      verify(client);
      verify(chefApi);
   }
View Full Code Here

      verify(chefApi);
   }

   public void testWhenClientsInListReplacesMissing() throws IOException {
      ChefApi chefApi = createMock(ChefApi.class);
      Client client = createMock(Client.class);
      PrivateKey privateKey = createMock(PrivateKey.class);

      ClientForGroup fn = new ClientForGroup(chefApi);

      expect(chefApi.listClients()).andReturn(ImmutableSet.<String> of("foo-client-00", "foo-client-02"));
      expect(chefApi.createClient("foo-client-01")).andReturn(client);
      expect(client.getPrivateKey()).andReturn(privateKey);

      replay(client);
      replay(chefApi);

      Client compare = fn.apply("foo");
      assertEquals(compare.getClientname(), "foo-client-01");
      assertEquals(compare.getName(), "foo-client-01");
      assertEquals(compare.getPrivateKey(), privateKey);

      verify(client);
      verify(chefApi);
   }
View Full Code Here

      privateKey = crypto.rsaKeyFactory().generatePrivate(Pems.privateKeySpec(Payloads.newStringPayload(PRIVATE_KEY)));
   }

   public void test() throws IOException {

      Client user = Client.builder().certificate(certificate).orgname("jclouds").clientname("adriancole-jcloudstest")
            .name("adriancole-jcloudstest").isValidator(false).privateKey(privateKey).build();

      byte[] encrypted = ByteStreams.toByteArray(new RSAEncryptingPayload(Payloads.newPayload("fooya"), user
            .getCertificate().getPublicKey()));

      assertEquals(
            ByteStreams.toByteArray(new RSADecryptingPayload(Payloads.newPayload(encrypted), user.getPrivateKey())),
            "fooya".getBytes());

      assertEquals(
            handler.apply(HttpResponse.builder().statusCode(200).message("ok")
                  .payload(ParseClientFromJsonTest.class.getResourceAsStream("/client.json")).build()), user);
View Full Code Here

      privateKey = crypto.rsaKeyFactory().generatePrivate(Pems.privateKeySpec(ByteSource.wrap(PRIVATE_KEY.getBytes(Charsets.UTF_8))));
   }

   public void test() throws IOException, CertificateException, NoSuchAlgorithmException {

      Client user = Client.builder().certificate(certificate).orgname("jclouds").clientname("adriancole-jcloudstest")
            .name("adriancole-jcloudstest").isValidator(false).privateKey(privateKey).build();

      byte[] encrypted = ByteStreams.toByteArray(new RSAEncryptingPayload(new JCECrypto(), Payloads.newPayload("fooya"), user
            .getCertificate().getPublicKey()));

      assertEquals(
            ByteStreams.toByteArray(new RSADecryptingPayload(new JCECrypto(), Payloads.newPayload(encrypted), user.getPrivateKey())),
            "fooya".getBytes());

      assertEquals(
            handler.apply(HttpResponse.builder().statusCode(200).message("ok")
                  .payload(ParseClientFromJsonTest.class.getResourceAsStream("/client.json")).build()), user);
View Full Code Here

      overrides.setProperty(provider + ".credential", credential);

      A clientApi = create(overrides, setupModules());

      try {
         Client client = clientApi.getClient(identity);
         assertNotNull(client, "Client not found: " + identity);
      } finally {
         try {
            Closeables.close(clientApi, true);
         } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.jclouds.chef.domain.Client$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.