jclouds-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ignasi Barrera <ignasi.barr...@gmail.com>
Subject Re: How to mock up novaApi object?
Date Mon, 01 Dec 2014 21:24:20 GMT
The "stub" provider is not intended to be used with the "underlying"
provider specific api, as it does not have one.

The "unwrap" method provides access to the "provider specific api". In
OpenStack based clouds it provides the Nova api, in EC2 based clouds,
it provides the EC2 api, etc. Note that you can't get an EC2 api out
from a context created for an OpenStack cloud.

For this reason, you just can't get a provider specific API from the
"stub" provider, as it doesn't have one. It is just meant to be used
as an abstraction, but nothing more.

If you have to mock the Nova API you'll have to mock it manually with
EasyMock, Mockito or any other mocking framework.



On 1 December 2014 at 07:04, Xianyi Ye <yexianyi@sina.com> wrote:
> Hi all,
>
>
>
> I have a question about how to do JClouds mock test.
>
> My target codes are showing as below.
>
>
>
> ComputeServiceContext context = ContextBuilder.newBuilder(provider)
>
>                 .endpoint(endpoint.get())
>
>                 .credentials(identity.get(),
> password.get()).modules(modules)
>
>                 .buildView(ComputeServiceContext.class);
>
> RestContext<NovaApi, NovaAsyncApi> nova = context.unwrap();
>
> compute = context.getComputeService();
>
> novaApi = nova.getApi();
>
>
>
>
>
> And I knew that I can mock ComputeService with following codes.
>
>
>
> ComputeServiceContext context =
> ContextBuilder.newBuilder("stub").buildView(ComputeServiceContext.class) ;
>
> compute = context.getComputeService();
>
>
>
> But how can I mock novaApi?
>
>
>
> When I tried to call following codes, it always said to me
> “java.lang.ClassCastException: org.jclouds.internal.ContextImpl cannot be
> cast to org.jclouds.rest.RestContext”
>
> RestContext<NovaApi, NovaAsyncApi> nova = context.unwrap();
>
>
>
> Is there anyone aware of any solution?
>
>
>
> Thanks in advance,
>
> Xianyi Ye

Mime
View raw message