// 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);
}