Package org.jclouds.cloudstack

Examples of org.jclouds.cloudstack.CloudStackClient


   }

   private void checkAuthAsUser(ApiKeyPair keyPair) {
      ComputeServiceContext context = createView(credentialsAsProperties(keyPair), setupModules());

      CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi();
      Set<Account> accounts = client.getAccountClient().listAccounts();

      assert accounts.size() > 0;

      context.close();
   }
View Full Code Here


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

   @Test
   public void testLoad() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getIngressRules()).andReturn(ImmutableSet.<IngressRule> of());
      expect(group.getId()).andReturn("sec-1234").anyTimes();
      expect(zone.isSecurityGroupsEnabled()).andReturn(true);
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-1")).andReturn(zone);
      expect(secClient.getSecurityGroupByName("group-1")).andReturn(null);
      expect(secClient.createSecurityGroup("group-1")).andReturn(group);
      expect(secClient.authorizeIngressPortsToCIDRs("sec-1234",
View Full Code Here

   }

  
   @Test
   public void testLoadAlreadyExists() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getId()).andReturn("sec-1234").anyTimes();
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();

      expect(secClient.getSecurityGroupByName("group-1")).andReturn(group);

      replay(client, secClient, zoneClient, zone, group);
View Full Code Here

      verify(client, secClient, zoneClient, zone, group);
   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testLoadZoneNoSecurityGroups() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(zone.isSecurityGroupsEnabled()).andReturn(false);
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-1")).andReturn(zone);
      expect(secClient.getSecurityGroupByName("group-1")).andReturn(null);

      replay(client, secClient, zoneClient, zone, group);
View Full Code Here

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

   @Test
   public void testLoad() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SSHKeyPairClient keyClient = createMock(SSHKeyPairClient.class);

      SshKeyPair pair = createMock(SshKeyPair.class);

      expect(client.getSSHKeyPairClient()).andReturn(keyClient);
      expect(keyClient.createSSHKeyPair("group-1")).andReturn(pair);

      replay(client, keyClient);

      CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {
View Full Code Here

         context =  ContextBuilder.newBuilder(new CloudStackApiMetadata())
               .endpoint(checkNotNull(endpoint, "endpoint").toASCIIString())
               .credentials(String.format("%s/%s", checkNotNull(domain, "domain"), checkNotNull(username, "username")), password)
               .overrides(overrides).build(CloudStackContext.class);

         CloudStackClient client = context.unwrap(CloudStackApiMetadata.CONTEXT_TOKEN).getApi();
         Set<Account> listOfAccounts = client.getAccountClient().listAccounts();

         domain = (domain.equals("") || domain.equals("/")) ? "ROOT" : domain;
         for (Account account : listOfAccounts) {
            for (User user : account.getUsers()) {
               if (user.getName().equals(username) && user.getDomain().equals(domain)) {
View Full Code Here

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

   @Test
   public void testApply() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getIngressRules()).andReturn(ImmutableSet.<IngressRule> of());
      expect(group.getId()).andReturn("sec-1234").anyTimes();
      expect(zone.isSecurityGroupsEnabled()).andReturn(true);
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-abc1")).andReturn(zone);
      expect(secClient.createSecurityGroup("group-1")).andReturn(group);
      expect(secClient.authorizeIngressPortsToCIDRs("sec-1234",
                                                    "TCP",
View Full Code Here

   }

  
   @Test
   public void testApplyGroupAlreadyExists() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(group.getId()).andReturn("sec-1234").anyTimes();
      expect(zone.isSecurityGroupsEnabled()).andReturn(true);
     
      expect(client.getSecurityGroupClient()).andReturn(secClient)
         .anyTimes();
      expect(client.getZoneClient()).andReturn(zoneClient);
      expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();

      expect(zoneClient.getZone("zone-abc2")).andReturn(zone);
      expect(secClient.createSecurityGroup("group-1")).andThrow(new IllegalStateException());
      expect(secClient.getSecurityGroupByName("group-1")).andReturn(group);
View Full Code Here

      verify(client, secClient, zoneClient, zone, group);
   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testApplyZoneNoSecurityGroups() throws UnknownHostException {
      final CloudStackClient client = createMock(CloudStackClient.class);
      SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
      ZoneClient zoneClient = createMock(ZoneClient.class);
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);
     
      SecurityGroup group = createMock(SecurityGroup.class);
     
      Zone zone = createMock(Zone.class);

      expect(zone.isSecurityGroupsEnabled()).andReturn(false);
     
      expect(client.getZoneClient()).andReturn(zoneClient);

      expect(zoneClient.getZone("zone-abc3")).andReturn(zone);

      replay(client, zoneClient, zone);
View Full Code Here

   public void testApply() {
      String id = "1";
      String jobId = "2";

      CloudStackClient client = createMock(CloudStackClient.class);
      Predicate<String> jobComplete = Predicates.alwaysTrue();
      AsyncJobClient jobClient = createMock(AsyncJobClient.class);

      expect(client.getAsyncJobClient()).andReturn(jobClient).atLeastOnce();
      expect(jobClient.getAsyncJob(jobId)).andReturn(AsyncJob.builder().id(jobId).result("foo").build()).atLeastOnce();

      replay(client);
      replay(jobClient);
View Full Code Here

TOP

Related Classes of org.jclouds.cloudstack.CloudStackClient

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.