Package org.jclouds.abiquo

Examples of org.jclouds.abiquo.AbiquoContext


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

   @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "Missing required field nameLabel")
   public void testNameLabelIsMandatory() {
      AbiquoContext context = EasyMock.createMock(AbiquoContext.class);
      VirtualAppliance vapp = EasyMock.createMock(VirtualAppliance.class);
      VirtualMachineTemplate template = EasyMock.createMock(VirtualMachineTemplate.class);

      VirtualMachine.builder(context.getApiContext(), vapp, template).build();
   }
View Full Code Here


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

   @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "Missing required field nameLabel")
   public void testNameLabelIsMandatory() {
      AbiquoContext context = EasyMock.createMock(AbiquoContext.class);
      VirtualAppliance vapp = EasyMock.createMock(VirtualAppliance.class);
      VirtualMachineTemplate template = EasyMock.createMock(VirtualMachineTemplate.class);

      VirtualMachine.builder(context.getApiContext(), vapp, template).build();
   }
View Full Code Here

      Properties props = new Properties();
      props.setProperty(AbiquoProperties.CREDENTIAL_IS_TOKEN, "true");

      // Create a new context that uses the generated token to perform the API
      // calls
      AbiquoContext tokenContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) //
            .endpoint(endpoint) //
            .credentials("token", token) //
            .modules(ImmutableSet.<Module> of(new SLF4JLoggingModule())) //
            .overrides(props) //
            .build(AbiquoContext.class);

      try {
         // Perform a call to get the logged user and verify the identity
         UserDto user = tokenContext.getApiContext().getApi().getAdminApi().getCurrentUser();
         assertNotNull(user);
         assertEquals(user.getNick(), identity);
      } finally {
         if (tokenContext != null) {
            tokenContext.close();
         }
      }
   }
View Full Code Here

      Properties props = new Properties();
      props.setProperty(AbiquoProperties.CREDENTIAL_IS_TOKEN, "true");

      // Create a new context that uses the generated token to perform the API
      // calls
      AbiquoContext tokenContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) //
            .endpoint(endpoint) //
            .credentials("token", token) //
            .modules(ImmutableSet.<Module> of(new SLF4JLoggingModule())) //
            .overrides(props) //
            .build(AbiquoContext.class);

      // Perform a call to get the logged user. It should fail
      try {
         tokenContext.getApiContext().getApi().getAdminApi().getCurrentUser();
      } catch (AuthorizationException ex) {
         // Test succeeded
         return;
      } finally {
         if (tokenContext != null) {
            tokenContext.close();
         }
      }

      fail("Token authentication should have failed");
   }
View Full Code Here

   }

   private String getAuthtenticationToken() {
      String token = null;

      AbiquoContext context = ContextBuilder.newBuilder(new AbiquoApiMetadata()) //
            .endpoint(endpoint) //
            .credentials(identity, credential) //
            .modules(ImmutableSet.<Module> of(new SLF4JLoggingModule())) //
            .build(AbiquoContext.class);

      try {
         // Create a request to authenticate to the API and generate the token
         HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create(endpoint)).build();

         request = request.toBuilder().replaceHeader(HttpHeaders.AUTHORIZATION, basic(identity, credential)).build();

         // Execute the request and read the generated token
         HttpResponse response = context.utils().http().invoke(request);
         assertEquals(response.getStatusCode(), 200);

         token = readAuthenticationToken(response);
         assertNotNull(token);

         releasePayload(response);
      } finally {
         if (context != null) {
            context.close();
         }
      }

      return token;
   }
View Full Code Here

TOP

Related Classes of org.jclouds.abiquo.AbiquoContext

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.