Package org.jclouds.trmk.vcloud_0_8.compute.options

Examples of org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions


   public void testExecuteWithDefaultOptionsAlreadyHasKey() throws SecurityException, NoSuchMethodException {
      // setup constants
      URI org = URI.create("org1");
      String identity = "identity";
      String group = "group";
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();

      // create mocks
      CreateNewKeyPairUnlessUserSpecifiedOtherwise strategy = setupStrategy();
      LoginCredentials keyPairCredentials = LoginCredentials.builder().privateKey(KeyPairHandlerTest.keyPair.getPrivateKey()).build();

      // setup expectations
      expect(strategy.credentialStore.containsKey("group#group")).andReturn(true);
      expect(strategy.credentialStore.get("group#group")).andReturn(keyPairCredentials);

      // replay mocks
      replayStrategy(strategy);

      // run
      strategy.execute(org, group, identity, options);
      assertEquals(options.getSshKeyFingerprint(), KeyPairHandlerTest.keyPair.getFingerPrint());

      // verify mocks
      verifyStrategy(strategy);
   }


   public void testCreateNewKeyPairUnlessUserSpecifiedOtherwise_reusesKeyWhenToldTo() {
      // setup constants
      URI org = URI.create("org1");
      String identity = "identity";
      String group = "group";
      TerremarkVCloudTemplateOptions options = sshKeyFingerprint("fingerprintFromUser");

      // create mocks
      CreateNewKeyPairUnlessUserSpecifiedOtherwise strategy = setupStrategy();

      // setup expectations

      // replay mocks
      replayStrategy(strategy);

      // run
      strategy.execute(org, group, identity, options);
      assertEquals(options.getSshKeyFingerprint(), "fingerprintFromUser");

      // verify mocks
      verifyStrategy(strategy);
   }

      // setup constants
      URI org = URI.create("org1");
      String identity = "identity";
      String group = "group";
      String systemGeneratedFingerprint = "systemGeneratedKeyPairfinger";
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();

      // create mocks
      CreateNewKeyPairUnlessUserSpecifiedOtherwise strategy = setupStrategy();
      LoginCredentials keyPairCredentials = LoginCredentials.builder().privateKey(KeyPairHandlerTest.keyPair.getPrivateKey()).build();
      KeyPair keyPair = createMock(KeyPair.class);

      // setup expectations
      expect(strategy.credentialStore.containsKey("group#group")).andReturn(false);
      expect(strategy.createUniqueKeyPair.apply(new OrgAndName(org, "group"))).andReturn(keyPair);
      expect(keyPair.getFingerPrint()).andReturn(KeyPairHandlerTest.keyPair.getFingerPrint()).atLeastOnce();
      expect(strategy.credentialStore.put("group#group", keyPairCredentials)).andReturn(null);

      // replay mocks
      replay(keyPair);
      replayStrategy(strategy);

      // run
      strategy.execute(org, group, identity, options);
      assertEquals(options.getSshKeyFingerprint(), systemGeneratedFingerprint);

      // verify mocks
      verify(keyPair);
      verifyStrategy(strategy);
   }

   public void testCreateNewKeyPairUnlessUserSpecifiedOtherwise_doesntCreateAKeyPairAndReturnsNullWhenToldNotTo() {
      // setup constants
      URI org = URI.create("org1");
      String identity = "identity";
      String group = "group";
      TerremarkVCloudTemplateOptions options = noKeyPair();

      // create mocks
      CreateNewKeyPairUnlessUserSpecifiedOtherwise strategy = setupStrategy();

      // setup expectations

      // replay mocks
      replayStrategy(strategy);

      // run
      strategy.execute(org, group, identity, options);
      assertEquals(options.getSshKeyFingerprint(), null);

      // verify mocks
      verifyStrategy(strategy);
   }

* @author Adrian Cole
*/
public class TerremarkVCloudTemplateOptionsTest {

   public void testAs() {
      TemplateOptions options = new TerremarkVCloudTemplateOptions();
      assertEquals(options.as(TerremarkVCloudTemplateOptions.class), options);
   }

      assertEquals(options.as(TerremarkVCloudTemplateOptions.class), options);
   }

   @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "use noKeyPair option to request boot without a keypair")
   public void testkeyPairBadFormat() {
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
      options.sshKeyFingerprint("");
   }

      options.sshKeyFingerprint("");
   }

   @Test(expectedExceptions = IllegalStateException.class)
   public void testkeyPairAndNoKeyPair() {
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
      options.sshKeyFingerprint("mykeypair");
      options.noKeyPair();
   }

      options.noKeyPair();
   }

   @Test(expectedExceptions = IllegalStateException.class)
   public void testNoKeyPairAndKeyPair() {
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
      options.noKeyPair();
      options.sshKeyFingerprint("mykeypair");
   }

      options.sshKeyFingerprint("mykeypair");
   }

   @Test
   public void testkeyPair() {
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
      options.sshKeyFingerprint("mykeypair");
      assertEquals(options.getSshKeyFingerprint(), "mykeypair");
   }

      assertEquals(options.getSshKeyFingerprint(), "mykeypair");
   }

   @Test
   public void testNullkeyPair() {
      TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
      assertEquals(options.getSshKeyFingerprint(), null);
   }

TOP

Related Classes of org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions

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.