@Test public void testFalsenoKeyPair() { EC2TemplateOptions options = new EC2TemplateOptions(); assertEquals(options.getKeyPair(), null); assert options.shouldAutomaticallyCreateKeyPair(); }
@Test public void testnoKeyPairStatic() { EC2TemplateOptions options = noKeyPair(); assertEquals(options.getKeyPair(), null); assert !options.shouldAutomaticallyCreateKeyPair(); }
@Test public void testFalsenoKeyPair() { EC2TemplateOptions options = new EC2TemplateOptions(); assertEquals(options.getKeyPair(), null); assert options.shouldAutomaticallyCreateKeyPair(); }
@Test public void testnoKeyPairStatic() { EC2TemplateOptions options = noKeyPair(); assertEquals(options.getKeyPair(), null); assert !options.shouldAutomaticallyCreateKeyPair(); }
@Test public void testnoKeyPair() { EC2TemplateOptions options = new EC2TemplateOptions(); options.noKeyPair(); assertEquals(options.getKeyPair(), null); assert !options.shouldAutomaticallyCreateKeyPair(); }
@Test public void testnoKeyPair() { EC2TemplateOptions options = new EC2TemplateOptions(); options.noKeyPair(); assertEquals(options.getKeyPair(), null); assert !options.shouldAutomaticallyCreateKeyPair(); }
public void testCreateNewKeyPairUnlessUserSpecifiedOtherwise_doesntCreateAKeyPairAndReturnsNullWhenToldNotTo() { // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; String userSuppliedKeyPair = null; boolean shouldAutomaticallyCreateKeyPair = false; // here's the important // part! // create mocks CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy(); EC2TemplateOptions options = createMock(EC2TemplateOptions.class); KeyPair keyPair = createMock(KeyPair.class); // setup expectations expect(options.getKeyPair()).andReturn(userSuppliedKeyPair); expect(options.getRunScript()).andReturn(null); expect(options.shouldAutomaticallyCreateKeyPair()).andReturn(shouldAutomaticallyCreateKeyPair); // replay mocks replay(options); replay(keyPair); replayStrategy(strategy); // run assertEquals(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options), null); // verify mocks verify(options); verify(keyPair); verifyStrategy(strategy); }
public void testCreateNewKeyPairUnlessUserSpecifiedOtherwise_doesntCreateAKeyPairAndReturnsNullWhenToldNotTo() { // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; String userSuppliedKeyPair = null; boolean shouldAutomaticallyCreateKeyPair = false; // here's the important // part! // create mocks CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy(); EC2TemplateOptions options = createMock(EC2TemplateOptions.class); KeyPair keyPair = createMock(KeyPair.class); // setup expectations expect(options.getKeyPair()).andReturn(userSuppliedKeyPair); expect(options.getRunScript()).andReturn(null); expect(options.shouldAutomaticallyCreateKeyPair()).andReturn(shouldAutomaticallyCreateKeyPair); // replay mocks replay(options); replay(keyPair); replayStrategy(strategy); // run assertEquals(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options), null); // verify mocks verify(options); verify(keyPair); verifyStrategy(strategy); }
@VisibleForTesting public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { String keyPairName = null; boolean shouldAutomaticallyCreateKeyPair = true; if (options instanceof EC2TemplateOptions) { keyPairName = EC2TemplateOptions.class.cast(options).getKeyPair(); if (keyPairName == null) shouldAutomaticallyCreateKeyPair = EC2TemplateOptions.class.cast(options) .shouldAutomaticallyCreateKeyPair(); } if (keyPairName == null && shouldAutomaticallyCreateKeyPair) { keyPairName = createOrImportKeyPair(region, group, options); } else if (keyPairName != null) { if (options.getLoginPrivateKey() != null) { String pem = options.getLoginPrivateKey(); KeyPair keyPair = KeyPair.builder().region(region).keyName(keyPairName).fingerprint( fingerprintPrivateKey(pem)).sha1OfPrivateKey(sha1PrivateKey(pem)).keyMaterial(pem).build(); RegionAndName key = new RegionAndName(region, keyPairName); credentialsMap.put(key, keyPair); } } if (options.getRunScript() != null) { RegionAndName regionAndName = new RegionAndName(region, keyPairName); checkArgument( credentialsMap.containsKey(regionAndName), "no private key configured for: %s; please use options.overrideLoginCredentialWith(rsa_private_text)", regionAndName); } return keyPairName; }
expect(options.shouldAutomaticallyCreateKeyPair()).andReturn(shouldAutomaticallyCreateKeyPair); expect(keyPair.getKeyName()).andReturn(systemGeneratedKeyPairName).atLeastOnce(); expect(strategy.credentialsMap.containsKey(new RegionAndName(region, group))).andReturn(true);
@Override public void copyTo(TemplateOptions to) { super.copyTo(to); if (to instanceof EC2TemplateOptions) { EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to); if (getGroups().size() > 0) eTo.securityGroups(getGroups()); if (getKeyPair() != null) eTo.keyPair(getKeyPair()); if (getBlockDeviceMappings().size() > 0) eTo.blockDeviceMappings(getBlockDeviceMappings()); if (!shouldAutomaticallyCreateKeyPair()) eTo.noKeyPair(); if (getUserData() != null) eTo.userData(getUserData()); } }
@VisibleForTesting public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { String keyPairName = null; boolean shouldAutomaticallyCreateKeyPair = true; if (options instanceof EC2TemplateOptions) { keyPairName = EC2TemplateOptions.class.cast(options).getKeyPair(); if (keyPairName == null) shouldAutomaticallyCreateKeyPair = EC2TemplateOptions.class.cast(options) .shouldAutomaticallyCreateKeyPair(); } if (keyPairName == null && shouldAutomaticallyCreateKeyPair) { keyPairName = createOrImportKeyPair(region, group, options); } else if (keyPairName != null) { if (options.getLoginPrivateKey() != null) { String pem = options.getLoginPrivateKey(); KeyPair keyPair = KeyPair.builder().region(region).keyName(keyPairName).fingerprint( fingerprintPrivateKey(pem)).sha1OfPrivateKey(sha1PrivateKey(pem)).keyMaterial(pem).build(); RegionAndName key = new RegionAndName(region, keyPairName); credentialsMap.put(key, keyPair); } } if (options.getRunScript() != null) { RegionAndName regionAndName = new RegionAndName(region, keyPairName); checkArgument( credentialsMap.containsKey(regionAndName), "no private key configured for: %s; please use options.overrideLoginCredentialWith(rsa_private_text)", regionAndName); } return keyPairName; }
@Override public void copyTo(TemplateOptions to) { super.copyTo(to); if (to instanceof EC2TemplateOptions) { EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to); if (getGroups().size() > 0) eTo.securityGroups(getGroups()); if (getKeyPair() != null) eTo.keyPair(getKeyPair()); if (getBlockDeviceMappings().size() > 0) eTo.blockDeviceMappings(getBlockDeviceMappings()); if (!shouldAutomaticallyCreateKeyPair()) eTo.noKeyPair(); if (getUserData() != null) eTo.userData(getUserData()); } }
@VisibleForTesting public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { String keyPairName = null; boolean shouldAutomaticallyCreateKeyPair = true; if (options instanceof EC2TemplateOptions) { keyPairName = EC2TemplateOptions.class.cast(options).getKeyPair(); if (keyPairName == null) shouldAutomaticallyCreateKeyPair = EC2TemplateOptions.class.cast(options) .shouldAutomaticallyCreateKeyPair(); } if (keyPairName == null && shouldAutomaticallyCreateKeyPair) { keyPairName = createOrImportKeyPair(region, group, options); } else if (keyPairName != null) { if (options.getLoginPrivateKey() != null) { String pem = options.getLoginPrivateKey(); KeyPair keyPair = KeyPair.builder().region(region).keyName(keyPairName).fingerprint( fingerprintPrivateKey(pem)).sha1OfPrivateKey(sha1PrivateKey(pem)).keyMaterial(pem).build(); RegionAndName key = new RegionAndName(region, keyPairName); credentialsMap.put(key, keyPair); } } if (options.getRunScript() != null) { RegionAndName regionAndName = new RegionAndName(region, keyPairName); checkArgument( credentialsMap.containsKey(regionAndName), "no private key configured for: %s; please use options.overrideLoginCredentialWith(rsa_private_text)", regionAndName); } return keyPairName; }
@VisibleForTesting public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { String keyPairName = null; boolean shouldAutomaticallyCreateKeyPair = true; if (options instanceof EC2TemplateOptions) { keyPairName = EC2TemplateOptions.class.cast(options).getKeyPair(); if (keyPairName == null) shouldAutomaticallyCreateKeyPair = EC2TemplateOptions.class.cast(options) .shouldAutomaticallyCreateKeyPair(); } if (keyPairName == null && shouldAutomaticallyCreateKeyPair) { keyPairName = createOrImportKeyPair(region, group, options); } else if (keyPairName != null) { if (options.getLoginPrivateKey() != null) { String pem = options.getLoginPrivateKey(); KeyPair keyPair = KeyPair.builder().region(region).keyName(keyPairName).fingerprint( fingerprintPrivateKey(pem)).sha1OfPrivateKey(sha1PrivateKey(pem)).keyMaterial(pem).build(); RegionAndName key = new RegionAndName(region, keyPairName); credentialsMap.put(key, keyPair); } } if (options.getRunScript() != null) { RegionAndName regionAndName = new RegionAndName(region, keyPairName); checkArgument( credentialsMap.containsKey(regionAndName), "no private key configured for: %s; please use options.overrideLoginCredentialWith(rsa_private_text)", regionAndName); } return keyPairName; }
@VisibleForTesting public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { String keyPairName = null; boolean shouldAutomaticallyCreateKeyPair = true; if (options instanceof EC2TemplateOptions) { keyPairName = EC2TemplateOptions.class.cast(options).getKeyPair(); if (keyPairName == null) shouldAutomaticallyCreateKeyPair = EC2TemplateOptions.class.cast(options) .shouldAutomaticallyCreateKeyPair(); } if (keyPairName == null && shouldAutomaticallyCreateKeyPair) { keyPairName = createOrImportKeyPair(region, group, options); } else if (keyPairName != null) { if (options.getLoginPrivateKey() != null) { String pem = options.getLoginPrivateKey(); KeyPair keyPair = KeyPair.builder().region(region).keyName(keyPairName).fingerprint( fingerprintPrivateKey(pem)).sha1OfPrivateKey(sha1PrivateKey(pem)).keyMaterial(pem).build(); RegionAndName key = new RegionAndName(region, keyPairName); credentialsMap.put(key, keyPair); } } if (options.getRunScript() != null) { RegionAndName regionAndName = new RegionAndName(region, keyPairName); checkArgument( credentialsMap.containsKey(regionAndName), "no private key configured for: %s; please use options.overrideLoginCredentialWith(rsa_private_text)", regionAndName); } return keyPairName; }
public void testCreateNewKeyPairUnlessUserSpecifiedOtherwise_createsNewKeyPairAndReturnsItsNameByDefault() throws ExecutionException { // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; String userSuppliedKeyPair = null; boolean shouldAutomaticallyCreateKeyPair = true; String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; // create mocks CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy(); EC2TemplateOptions options = createMock(EC2TemplateOptions.class); KeyPair keyPair = createMock(KeyPair.class); // setup expectations expect(options.getKeyPair()).andReturn(userSuppliedKeyPair); expect(options.shouldAutomaticallyCreateKeyPair()).andReturn(shouldAutomaticallyCreateKeyPair); expect(keyPair.getKeyName()).andReturn(systemGeneratedKeyPairName).atLeastOnce(); expect(strategy.credentialsMap.putIfAbsent(anyObject(RegionAndName.class), anyObject(KeyPair.class))).andReturn(keyPair); expect(options.getRunScript()).andReturn(null); // replay mocks replay(options); replay(keyPair); replayStrategy(strategy); // run assertEquals(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options), systemGeneratedKeyPairName); // verify mocks verify(options); verify(keyPair); verifyStrategy(strategy); }
@Override public void copyTo(TemplateOptions to) { super.copyTo(to); if (to instanceof EC2TemplateOptions) { EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to); if (!getGroups().isEmpty()) eTo.securityGroups(getGroups()); if (getKeyPair() != null) eTo.keyPair(getKeyPair()); if (!getBlockDeviceMappings().isEmpty()) eTo.blockDeviceMappings(getBlockDeviceMappings()); if (!shouldAutomaticallyCreateKeyPair()) eTo.noKeyPair(); if (getUserData() != null) eTo.userData(getUserData()); if (getMaxCount() > 0) eTo.maxCount(getMaxCount()); if (getClientToken() != null) eTo.clientToken(getClientToken()); } }
@Override public void copyTo(TemplateOptions to) { super.copyTo(to); if (to instanceof EC2TemplateOptions) { EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to); if (!getGroups().isEmpty()) eTo.securityGroups(getGroups()); if (getKeyPair() != null) eTo.keyPair(getKeyPair()); if (!getBlockDeviceMappings().isEmpty()) eTo.blockDeviceMappings(getBlockDeviceMappings()); if (!shouldAutomaticallyCreateKeyPair()) eTo.noKeyPair(); if (getUserData() != null) eTo.userData(getUserData()); if (getMaxCount() > 0) eTo.maxCount(getMaxCount()); if (getClientToken() != null) eTo.clientToken(getClientToken()); } }
@Override public void copyTo(TemplateOptions to) { super.copyTo(to); if (to instanceof EC2TemplateOptions) { EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to); if (!getGroups().isEmpty()) eTo.securityGroups(getGroups()); if (getKeyPair() != null) eTo.keyPair(getKeyPair()); if (!getBlockDeviceMappings().isEmpty()) eTo.blockDeviceMappings(getBlockDeviceMappings()); if (!shouldAutomaticallyCreateKeyPair()) eTo.noKeyPair(); if (getUserData() != null) eTo.userData(getUserData()); if (getMaxCount() > 0) eTo.maxCount(getMaxCount()); if (getClientToken() != null) eTo.clientToken(getClientToken()); } }