http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java deleted file mode 100644 index b5a2ce3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListEntities.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy; - -import org.jclouds.abiquo.domain.DomainWrapper; - -/** - * List all entities of the given type. - */ -public interface ListEntities<T extends DomainWrapper<?>, P extends DomainWrapper<?>> { - Iterable<T> execute(P parent); -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java deleted file mode 100644 index 25b7958..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/ListRootEntities.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy; - -import org.jclouds.abiquo.domain.DomainWrapper; - -/** - * List all entities of the given type. - */ -public interface ListRootEntities<T extends DomainWrapper<?>> { - Iterable<T> execute(); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java deleted file mode 100644 index 6e10b54..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListAttachedNics.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.transform; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.network.ExternalIp; -import org.jclouds.abiquo.domain.network.Ip; -import org.jclouds.abiquo.domain.network.PrivateIp; -import org.jclouds.abiquo.domain.network.PublicIp; -import org.jclouds.abiquo.domain.network.UnmanagedIp; -import org.jclouds.abiquo.domain.util.LinkUtils; -import org.jclouds.abiquo.strategy.ListEntities; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.infrastructure.network.ExternalIpDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpDto; -import com.abiquo.server.core.infrastructure.network.PublicIpDto; -import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; -import com.google.common.base.Function; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.google.inject.TypeLiteral; - -/** - * List all NICs attached to a given virtual machine. - */ -@Singleton -public class ListAttachedNics implements ListEntities<Ip<?, ?>, VirtualMachine> { - protected final ApiContext<AbiquoApi> context; - - @Inject - public ListAttachedNics(final ApiContext<AbiquoApi> context) { - this.context = checkNotNull(context, "context"); - } - - @Override - public Iterable<Ip<?, ?>> execute(final VirtualMachine parent) { - parent.refresh(); - Iterable<RESTLink> nicLinks = LinkUtils.filterNicLinks(parent.unwrap().getLinks()); - return listIps(nicLinks); - } - - private Iterable<Ip<?, ?>> listIps(final Iterable<RESTLink> nicLinks) { - return transform(nicLinks, new Function<RESTLink, Ip<?, ?>>() { - @Override - public Ip<?, ?> apply(final RESTLink input) { - HttpResponse response = context.getApi().get(input); - - if (input.getType().equals(PrivateIpDto.BASE_MEDIA_TYPE)) { - ParseXMLWithJAXB<PrivateIpDto> parser = new ParseXMLWithJAXB<PrivateIpDto>(context.utils().xml(), - TypeLiteral.get(PrivateIpDto.class)); - - return wrap(context, PrivateIp.class, parser.apply(response)); - } else if (input.getType().equals(PublicIpDto.BASE_MEDIA_TYPE)) { - ParseXMLWithJAXB<PublicIpDto> parser = new ParseXMLWithJAXB<PublicIpDto>(context.utils().xml(), - TypeLiteral.get(PublicIpDto.class)); - - return wrap(context, PublicIp.class, parser.apply(response)); - } else if (input.getType().equals(ExternalIpDto.BASE_MEDIA_TYPE)) { - ParseXMLWithJAXB<ExternalIpDto> parser = new ParseXMLWithJAXB<ExternalIpDto>(context.utils().xml(), - TypeLiteral.get(ExternalIpDto.class)); - - return wrap(context, ExternalIp.class, parser.apply(response)); - } else if (input.getType().equals(UnmanagedIpDto.BASE_MEDIA_TYPE)) { - ParseXMLWithJAXB<UnmanagedIpDto> parser = new ParseXMLWithJAXB<UnmanagedIpDto>(context.utils().xml(), - TypeLiteral.get(UnmanagedIpDto.class)); - - return wrap(context, UnmanagedIp.class, parser.apply(response)); - } else { - throw new IllegalArgumentException("Unsupported media type: " + input.getType()); - } - } - }); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java deleted file mode 100644 index 69faa28..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualAppliances.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.Constants; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.strategy.ListRootEntities; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.cloud.VirtualApplianceDto; -import com.abiquo.server.core.cloud.VirtualAppliancesDto; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * List virtual appliances in each virtual datacenter. - */ -@Singleton -public class ListVirtualAppliances implements ListRootEntities<VirtualAppliance> { - protected final ApiContext<AbiquoApi> context; - - protected final ListVirtualDatacenters listVirtualDatacenters; - - protected final ListeningExecutorService userExecutor; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - ListVirtualAppliances(final ApiContext<AbiquoApi> context, - @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor, - final ListVirtualDatacenters listVirtualDatacenters) { - this.context = checkNotNull(context, "context"); - this.listVirtualDatacenters = checkNotNull(listVirtualDatacenters, "listVirtualDatacenters"); - this.userExecutor = checkNotNull(userExecutor, "userExecutor"); - } - - @Override - public Iterable<VirtualAppliance> execute() { - return execute(userExecutor); - } - - private Iterable<VirtualApplianceDto> listConcurrentVirtualAppliances(final ListeningExecutorService executor, - final Iterable<VirtualDatacenter> vdcs) { - ListenableFuture<List<VirtualAppliancesDto>> futures = allAsList(transform(vdcs, - new Function<VirtualDatacenter, ListenableFuture<VirtualAppliancesDto>>() { - @Override - public ListenableFuture<VirtualAppliancesDto> apply(final VirtualDatacenter input) { - return executor.submit(new Callable<VirtualAppliancesDto>() { - @Override - public VirtualAppliancesDto call() throws Exception { - return context.getApi().getCloudApi().listVirtualAppliances(input.unwrap()); - } - }); - } - })); - - logger.trace("getting virtual appliances"); - return DomainWrapper.join(getUnchecked(futures)); - } - - public Iterable<VirtualAppliance> execute(ListeningExecutorService executor) { - // / Find virtual appliances in concurrent requests - Iterable<VirtualDatacenter> vdcs = listVirtualDatacenters.execute(executor); - Iterable<VirtualApplianceDto> vapps = listConcurrentVirtualAppliances(executor, vdcs); - - return wrap(context, VirtualAppliance.class, vapps); - } - - public Iterable<VirtualAppliance> execute(ListeningExecutorService executor, Predicate<VirtualAppliance> selector) { - return filter(execute(executor), selector); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java deleted file mode 100644 index 0daa737..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/cloud/ListVirtualDatacenters.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy.cloud; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.Constants; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.options.VirtualDatacenterOptions; -import org.jclouds.abiquo.strategy.ListRootEntities; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.abiquo.server.core.cloud.VirtualDatacentersDto; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * List virtual datacenters. - */ -@Singleton -public class ListVirtualDatacenters implements ListRootEntities<VirtualDatacenter> { - protected final ApiContext<AbiquoApi> context; - - protected final ListeningExecutorService userExecutor; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - ListVirtualDatacenters(final ApiContext<AbiquoApi> context, - @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) { - this.context = checkNotNull(context, "context"); - this.userExecutor = checkNotNull(userExecutor, "userExecutor"); - } - - @Override - public Iterable<VirtualDatacenter> execute() { - return execute(userExecutor); - } - - public Iterable<VirtualDatacenter> execute(final VirtualDatacenterOptions virtualDatacenterOptions) { - VirtualDatacentersDto result = context.getApi().getCloudApi().listVirtualDatacenters(virtualDatacenterOptions); - return wrap(context, VirtualDatacenter.class, result.getCollection()); - } - - public Iterable<VirtualDatacenter> execute(final Predicate<VirtualDatacenter> selector, - final VirtualDatacenterOptions virtualDatacenterOptions) { - return filter(execute(virtualDatacenterOptions), selector); - } - - public Iterable<VirtualDatacenter> execute(final List<Integer> virtualDatacenterIds) { - return execute(userExecutor, virtualDatacenterIds); - } - - public Iterable<VirtualDatacenter> execute(ListeningExecutorService executor, - final List<Integer> virtualDatacenterIds) { - return listConcurrentVirtualDatacenters(executor, virtualDatacenterIds); - } - - private Iterable<VirtualDatacenter> listConcurrentVirtualDatacenters(final ListeningExecutorService executor, - final List<Integer> ids) { - ListenableFuture<List<VirtualDatacenterDto>> futures = allAsList(transform(ids, - new Function<Integer, ListenableFuture<VirtualDatacenterDto>>() { - @Override - public ListenableFuture<VirtualDatacenterDto> apply(final Integer input) { - return executor.submit(new Callable<VirtualDatacenterDto>() { - @Override - public VirtualDatacenterDto call() throws Exception { - return context.getApi().getCloudApi().getVirtualDatacenter(input); - } - }); - - } - })); - - logger.trace("getting virtual datacenters"); - return wrap(context, VirtualDatacenter.class, newArrayList(getUnchecked(futures))); - } - - public Iterable<VirtualDatacenter> execute(ListeningExecutorService executor) { - VirtualDatacenterOptions virtualDatacenterOptions = VirtualDatacenterOptions.builder().build(); - return execute(virtualDatacenterOptions); - } - - public Iterable<VirtualDatacenter> execute(ListeningExecutorService executor, Predicate<VirtualDatacenter> selector) { - return filter(execute(executor), selector); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java deleted file mode 100644 index 01a0a11..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/enterprise/ListVirtualMachineTemplates.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy.enterprise; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.Constants; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.strategy.ListEntities; -import org.jclouds.collect.PagedIterable; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * List all virtual machine templates available to an enterprise. - */ -@Singleton -public class ListVirtualMachineTemplates implements ListEntities<VirtualMachineTemplate, Enterprise> { - protected final ApiContext<AbiquoApi> context; - - protected final ListeningExecutorService userExecutor; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - ListVirtualMachineTemplates(final ApiContext<AbiquoApi> context, - @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) { - super(); - this.context = checkNotNull(context, "context"); - this.userExecutor = checkNotNull(userExecutor, "userExecutor"); - } - - @Override - public Iterable<VirtualMachineTemplate> execute(final Enterprise parent) { - return execute(userExecutor, parent); - } - - public Iterable<VirtualMachineTemplate> execute(ListeningExecutorService executor, final Enterprise parent) { - // Find virtual machine templates in concurrent requests - Iterable<Datacenter> dcs = parent.listAllowedDatacenters(); - Iterable<VirtualMachineTemplateDto> templates = listConcurrentTemplates(executor, parent, dcs); - - return wrap(context, VirtualMachineTemplate.class, templates); - } - - public Iterable<VirtualMachineTemplate> execute(ListeningExecutorService executor, final Enterprise parent, - final Predicate<VirtualMachineTemplate> selector) { - return filter(execute(executor, parent), selector); - } - - private Iterable<VirtualMachineTemplateDto> listConcurrentTemplates(final ListeningExecutorService executor, - final Enterprise parent, final Iterable<Datacenter> dcs) { - ListenableFuture<List<Iterable<VirtualMachineTemplateDto>>> futures = allAsList(transform(dcs, - new Function<Datacenter, ListenableFuture<Iterable<VirtualMachineTemplateDto>>>() { - @Override - public ListenableFuture<Iterable<VirtualMachineTemplateDto>> apply(final Datacenter input) { - return executor.submit(new Callable<Iterable<VirtualMachineTemplateDto>>() { - @Override - public Iterable<VirtualMachineTemplateDto> call() throws Exception { - PagedIterable<VirtualMachineTemplateDto> templates = context.getApi() - .getVirtualMachineTemplateApi() - .listVirtualMachineTemplates(parent.getId(), input.getId()); - return templates.concat(); - } - }); - } - })); - - logger.trace("getting virtual machine templates"); - return concat(getUnchecked(futures)); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java b/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java deleted file mode 100644 index 3403fda..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/strategy/infrastructure/ListMachines.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.strategy.infrastructure; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.Constants; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.domain.infrastructure.Machine; -import org.jclouds.abiquo.strategy.ListRootEntities; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.infrastructure.DatacentersDto; -import com.abiquo.server.core.infrastructure.MachineDto; -import com.abiquo.server.core.infrastructure.MachinesDto; -import com.abiquo.server.core.infrastructure.RackDto; -import com.abiquo.server.core.infrastructure.RacksDto; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * List machines in each datacenter and rack. - */ -@Singleton -public class ListMachines implements ListRootEntities<Machine> { - protected ApiContext<AbiquoApi> context; - - protected final ListeningExecutorService userExecutor; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - ListMachines(final ApiContext<AbiquoApi> context, - @Named(Constants.PROPERTY_USER_THREADS) final ListeningExecutorService userExecutor) { - super(); - this.context = checkNotNull(context, "context"); - this.userExecutor = checkNotNull(userExecutor, "userExecutor"); - } - - @Override - public Iterable<Machine> execute() { - return execute(userExecutor); - } - - public Iterable<Machine> execute(ListeningExecutorService executor) { - // Find machines in concurrent requests - DatacentersDto result = context.getApi().getInfrastructureApi().listDatacenters(); - Iterable<Datacenter> datacenters = wrap(context, Datacenter.class, result.getCollection()); - Iterable<RackDto> racks = listConcurrentRacks(executor, datacenters); - Iterable<MachineDto> machines = listConcurrentMachines(executor, racks); - - return wrap(context, Machine.class, machines); - } - - public Iterable<Machine> execute(ListeningExecutorService executor, final Predicate<Machine> selector) { - return filter(execute(executor), selector); - } - - private Iterable<RackDto> listConcurrentRacks(final ListeningExecutorService executor, - final Iterable<Datacenter> datacenters) { - ListenableFuture<List<RacksDto>> futures = allAsList(transform(datacenters, - new Function<Datacenter, ListenableFuture<RacksDto>>() { - @Override - public ListenableFuture<RacksDto> apply(final Datacenter input) { - return executor.submit(new Callable<RacksDto>() { - @Override - public RacksDto call() throws Exception { - return context.getApi().getInfrastructureApi().listRacks(input.unwrap()); - } - }); - } - })); - - logger.trace("getting racks"); - return DomainWrapper.join(getUnchecked(futures)); - } - - private Iterable<MachineDto> listConcurrentMachines(final ListeningExecutorService executor, - final Iterable<RackDto> racks) { - ListenableFuture<List<MachinesDto>> futures = allAsList(transform(racks, - new Function<RackDto, ListenableFuture<MachinesDto>>() { - @Override - public ListenableFuture<MachinesDto> apply(final RackDto input) { - return executor.submit(new Callable<MachinesDto>() { - @Override - public MachinesDto call() throws Exception { - return context.getApi().getInfrastructureApi().listMachines(input); - } - }); - } - })); - - logger.trace("getting machines"); - return DomainWrapper.join(getUnchecked(futures)); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata ---------------------------------------------------------------------- diff --git a/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata deleted file mode 100644 index 642f443..0000000 --- a/abiquo/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata +++ /dev/null @@ -1 +0,0 @@ -org.jclouds.abiquo.AbiquoApiMetadata \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java b/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java index 6a7935f..936c13f 100644 --- a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java +++ b/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiMetadataTest.java @@ -20,19 +20,25 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import org.jclouds.View; import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.Apis; -import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; +import org.jclouds.apis.internal.BaseApiMetadataTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + /** * Unit tests for the {@link AbiquoApiMetadata} class. */ @Test(groups = "unit", testName = "AbiquoApiMetadataTest") -public class AbiquoApiMetadataTest extends BaseComputeServiceApiMetadataTest { +// TODO: Change inheritance to BaseComputeApiMetadataTest once the +// ComputeService abstraction is implemented +public class AbiquoApiMetadataTest extends BaseApiMetadataTest { public AbiquoApiMetadataTest() { - super(new AbiquoApiMetadata()); + super(new AbiquoApiMetadata(), ImmutableSet.<TypeToken<? extends View>> of()); } public void testAbiquoApiRegistered() { http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiTest.java deleted file mode 100644 index 212daba..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoApiTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.abiquo.features.BaseAbiquoApiTest; -import org.jclouds.functions.IdentityFunction; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.infrastructure.DatacentersDto; -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; - -/** - * Tests annotation parsing of {@code AbiquoApi}. - */ -@Test(groups = "unit", testName = "AbiquoApiTest") -public class AbiquoApiTest extends BaseAbiquoApiTest<AbiquoApi> { - public void testGet() throws SecurityException, NoSuchMethodException, IOException { - RESTLink link = new RESTLink("edit", "http://foo/bar"); - link.setType(DatacentersDto.BASE_MEDIA_TYPE); - - Invokable<?, ?> method = method(AbiquoApi.class, "get", RESTLink.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.<Object> of(link))); - - assertRequestLineEquals(request, "GET http://foo/bar HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + DatacentersDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, IdentityFunction.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java deleted file mode 100644 index 223393c..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/AbiquoDelegateApiTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo; - -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.abiquo.features.BaseAbiquoApiTest; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Tests asynchronous and synchronous API delegates. - */ -@Test(groups = "unit", testName = "AbiquoDelegateApiTest") -public class AbiquoDelegateApiTest extends BaseAbiquoApiTest<AbiquoApi> { - - private AbiquoApi syncApi; - - @BeforeClass - @Override - protected void setupFactory() throws IOException { - super.setupFactory(); - syncApi = injector.getInstance(AbiquoApi.class); - } - - public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException { - assertNotNull(syncApi.getAdminApi()); - assertNotNull(syncApi.getConfigApi()); - assertNotNull(syncApi.getInfrastructureApi()); - assertNotNull(syncApi.getEnterpriseApi()); - assertNotNull(syncApi.getCloudApi()); - assertNotNull(syncApi.getVirtualMachineTemplateApi()); - assertNotNull(syncApi.getTaskApi()); - } - - @Override - protected void checkFilters(final HttpRequest request) { - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java deleted file mode 100644 index dabbe55..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/AppendToPathTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link AppendToPath} binder. - */ -@Test(groups = "unit", testName = "AppendToPathTest") -public class AppendToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - AppendToPath binder = new AppendToPath(); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - public void testBindString() { - AppendToPath binder = new AppendToPath(); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - HttpRequest newRequest = binder.bindToRequest(request, "expanded/path"); - assertEquals(newRequest.getRequestLine(), "GET http://localhost/expanded/path HTTP/1.1"); - } - - public void testBindNumber() { - AppendToPath binder = new AppendToPath(); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - HttpRequest newRequest = binder.bindToRequest(request, 57); - assertEquals(newRequest.getRequestLine(), "GET http://localhost/57 HTTP/1.1"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java deleted file mode 100644 index 7ea6322..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathAndAcceptHeaderTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.net.URI; - -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.net.HttpHeaders; - -/** - * Unit tests for the {@link BindLinkToPathAndAcceptHeader} class. - */ -@Test(groups = "unit", testName = "BindLinkToPathAndAcceptHeaderTest") -public class BindLinkToPathAndAcceptHeaderTest { - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindLinkToPathAndAcceptHeader binder = new BindLinkToPathAndAcceptHeader(); - binder.addHeader(null, HttpHeaders.ACCEPT, null); - } - - public void testAddHeader() { - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - - BindLinkToPathAndAcceptHeader binder = new BindLinkToPathAndAcceptHeader(); - HttpRequest updatedRequest = binder.addHeader(request, HttpHeaders.ACCEPT, - "application/vnd.abiquo.datacenters+xml"); - - String accept = updatedRequest.getFirstHeaderOrNull(HttpHeaders.ACCEPT); - - assertNotNull(accept); - assertEquals(accept, "application/vnd.abiquo.datacenters+xml"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java deleted file mode 100644 index bd2215c..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/BindLinkToPathTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders; - -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; - -/** - * Unit tests for the {@link BindLinkToPath} class. - */ -@Test(groups = "unit", testName = "BindLinkToPathTest") -public class BindLinkToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testGetNewEnpointNullInput() { - BindLinkToPath binder = new BindLinkToPath(); - binder.getNewEndpoint(null, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testGetNewEnpointInvalidInput() { - BindLinkToPath binder = new BindLinkToPath(); - binder.getNewEndpoint(null, new Object()); - } - - public void testGetNewEnpoint() { - BindLinkToPath binder = new BindLinkToPath(); - assertEquals(binder.getNewEndpoint(null, new RESTLink("edit", "http://foo/bar")), "http://foo/bar"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java deleted file mode 100644 index 72db6ba..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders; - -import static org.jclouds.reflect.Reflection2.method; -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import javax.ws.rs.GET; -import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.MediaType; - -import org.jclouds.abiquo.rest.annotations.EndpointLink; -import org.jclouds.http.HttpRequest; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.binders.BindException; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.model.transport.SingleResourceTransportDto; -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; - -/** - * Unit tests for the {@link BindToPath} binder. - */ -@Test(groups = "unit", testName = "BindToPathTest") -public class BindToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullRequest() throws SecurityException, NoSuchMethodException { - BindToPath binder = new BindToPath(); - binder.bindToRequest(null, new Object()); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidRequestType() throws SecurityException, NoSuchMethodException { - BindToPath binder = new BindToPath(); - binder.bindToRequest(HttpRequest.builder().method("m").endpoint("http://localhost").build(), new Object()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() throws SecurityException, NoSuchMethodException { - Invokable<?, ?> withEndpointLink = method(TestEndpointLink.class, "withEndpointLink", TestDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(new TestDto()))) - .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); - - BindToPath binder = new BindToPath(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidInputType() throws SecurityException, NoSuchMethodException { - Invokable<?, ?> withEndpointLink = method(TestEndpointLink.class, "withEndpointLink", TestDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(new TestDto()))) - .method(HttpMethod.GET).endpoint(URI.create("http://localhost")).build(); - - BindToPath binder = new BindToPath(); - binder.bindToRequest(request, new Object()); - } - - @Test(expectedExceptions = BindException.class) - public void testAnnotationNotPresent() throws SecurityException, NoSuchMethodException { - TestDto dto = new TestDto(); - Invokable<?, ?> withoutEndpointLink = method(TestEndpointLink.class, "withoutEndpointLink", TestDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withoutEndpointLink, ImmutableList.<Object> of(dto))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindToPath binder = new BindToPath(); - binder.bindToRequest(request, dto); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testLinkNotPresent() throws SecurityException, NoSuchMethodException { - TestDto dto = new TestDto(); - Invokable<?, ?> withUnexistingLink = method(TestEndpointLink.class, "withUnexistingLink", TestDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withUnexistingLink, ImmutableList.<Object> of(dto))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindToPath binder = new BindToPath(); - binder.bindToRequest(request, dto); - } - - public void testBindWithoutParameters() throws SecurityException, NoSuchMethodException { - TestDto dto = new TestDto(); - Invokable<?, ?> withEndpointLink = method(TestEndpointLink.class, "withEndpointLink", TestDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(dto))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindToPath binder = new BindToPath(); - GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto); - assertEquals(newRequest.getRequestLine(), "GET http://linkuri HTTP/1.1"); - } - - public void testBindWithQueryParameters() throws SecurityException, NoSuchMethodException { - TestDto dto = new TestDto(); - Invokable<?, ?> withEndpointLink = method(TestEndpointLink.class, "withEndpointLink", TestDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(dto))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost?param=value")).build(); - - BindToPath binder = new BindToPath(); - GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto); - assertEquals(newRequest.getRequestLine(), "GET http://linkuri?param=value HTTP/1.1"); - } - - interface TestEndpointLink { - @GET - void withEndpointLink(@EndpointLink("edit") TestDto dto); - - @GET - void withUnexistingLink(@EndpointLink("unexisting") TestDto dto); - - @GET - void withoutEndpointLink(TestDto dto); - } - - static class TestDto extends SingleResourceTransportDto { - - private static final long serialVersionUID = 5381713583837345158L; - - public TestDto() { - addLink(new RESTLink("edit", "http://linkuri")); - } - - @Override - public String getMediaType() { - return MediaType.APPLICATION_XML; - } - - @Override - public String getBaseMediaType() { - return MediaType.APPLICATION_XML; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java deleted file mode 100644 index d93f78e..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindHardDiskRefsToPayloadTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.CloudResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.infrastructure.storage.DiskManagementDto; - -/** - * Unit tests for the {@link BindHardDiskRefsToPayload} binder. - */ -@Test(groups = "unit", testName = "BindHardDiskRefsToPayloadTest") -public class BindHardDiskRefsToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindEmptyArray() throws IOException { - BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new DiskManagementDto[] {}); - assertPayloadEquals(request.getPayload(), withHeader("<links/>"), LinksDto.class); - } - - public void testBindSingleHardDisk() throws IOException { - DiskManagementDto hardDisk = CloudResources.hardDiskPut(); - BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new DiskManagementDto[] { hardDisk }); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + hardDisk.getEditLink().getHref() - + "\" rel=\"" + binder.getRelToUse(hardDisk) + "\"/></links>"), LinksDto.class); - } - - public void testBindMultipleHardDisks() throws IOException { - DiskManagementDto hardDisk = CloudResources.hardDiskPut(); - BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new DiskManagementDto[] { hardDisk, hardDisk }); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + hardDisk.getEditLink().getHref() - + "\" rel=\"" + binder.getRelToUse(hardDisk) + "\"/></links>"), LinksDto.class); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java deleted file mode 100644 index c75405d..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefToPayloadTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.NetworkResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpDto; - -/** - * Unit tests for the {@link BindIpRefToPayload} binder. - */ -@Test(groups = "unit", testName = "BindIpRefToPayloadTest") -public class BindIpRefToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindIpRef() throws IOException { - PrivateIpDto ip = NetworkResources.privateIpPut(); - RESTLink selfLink = ip.searchLink("self"); - BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, ip); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + selfLink.getHref() + "\" rel=\"" - + selfLink.getTitle() + "\"/></links>"), LinksDto.class); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java deleted file mode 100644 index 4034366..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindIpRefsToPayloadTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.NetworkResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.infrastructure.network.AbstractIpDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpDto; - -/** - * Unit tests for the {@link BindIpRefsToPayload} binder. - */ -@Test(groups = "unit", testName = "BindIpRefsToPayloadTest") -public class BindIpRefsToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindEmptyArray() throws IOException { - BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new AbstractIpDto[] {}); - assertPayloadEquals(request.getPayload(), withHeader("<links/>"), LinksDto.class); - } - - public void testBindSingleIp() throws IOException { - PrivateIpDto ip = NetworkResources.privateIpPut(); - BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new AbstractIpDto[] { ip }); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + ip.searchLink("self").getHref() - + "\" rel=\"" + ip.searchLink("self").getTitle() + "\"/></links>"), LinksDto.class); - } - - public void testBindMultipleIps() throws IOException { - PrivateIpDto ip = NetworkResources.privateIpPut(); - BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new AbstractIpDto[] { ip, ip }); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + ip.searchLink("self").getHref() - + "\" rel=\"" + ip.searchLink("self").getTitle() + "\"/></links>"), LinksDto.class); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java deleted file mode 100644 index 1cf4f08..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.reflect.Reflection2.method; -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import javax.ws.rs.HttpMethod; - -import org.jclouds.abiquo.domain.CloudResources; -import org.jclouds.abiquo.features.CloudApi; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; - -/** - * Unit tests for the {@link BindMoveVolumeToPath} binder. - */ -@Test(groups = "unit", testName = "BindMoveVolumeToPathTest") -public class BindMoveVolumeToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() throws SecurityException, NoSuchMethodException { - BindMoveVolumeToPath binder = new BindMoveVolumeToPath(); - binder.getNewEndpoint(generatedHttpRequest(), null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidInputType() throws SecurityException, NoSuchMethodException { - BindMoveVolumeToPath binder = new BindMoveVolumeToPath(); - binder.getNewEndpoint(generatedHttpRequest(), new Object()); - } - - public void testGetNewEndpoint() throws SecurityException, NoSuchMethodException { - BindMoveVolumeToPath binder = new BindMoveVolumeToPath(); - String newEndpoint = binder.getNewEndpoint(generatedHttpRequest(), CloudResources.volumePut()); - assertEquals(newEndpoint, "http://localhost/api/cloud/virtualdatacenters/1/volumes/1/action/move"); - } - - private static GeneratedHttpRequest generatedHttpRequest() throws SecurityException, NoSuchMethodException { - Invokable<?, ?> withEndpointLink = method(CloudApi.class, "moveVolume", VolumeManagementDto.class, - VirtualDatacenterDto.class); - return GeneratedHttpRequest - .builder() - .invocation( - Invocation.create(withEndpointLink, - ImmutableList.<Object> of(CloudResources.volumePut(), CloudResources.virtualDatacenterPut()))) - .method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java deleted file mode 100644 index d88eb57..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; -import java.net.URI; -import java.util.NoSuchElementException; - -import javax.ws.rs.GET; -import javax.ws.rs.HttpMethod; - -import org.jclouds.abiquo.domain.CloudResources; -import org.jclouds.abiquo.domain.NetworkResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.cloud.VirtualMachineDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.reflect.Invokable; - -/** - * Unit tests for the {@link BindNetworkConfigurationRefToPayload} binder. - */ -@Test(groups = "unit", testName = "BindNetworkConfigurationRefToPayloadTest") -public class BindNetworkConfigurationRefToPayloadTest { - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullRequest() throws SecurityException, NoSuchMethodException { - BindNetworkConfigurationRefToPayload binder = new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); - binder.bindToRequest(null, new Object()); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidRequestType() throws SecurityException, NoSuchMethodException { - BindNetworkConfigurationRefToPayload binder = new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); - - binder.bindToRequest(HttpRequest.builder().method("m").endpoint("http://localhost").build(), new Object()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() throws SecurityException, NoSuchMethodException { - VirtualMachineDto vm = CloudResources.virtualMachinePut(); - - Invokable<?, ?> method = method(TestNetworkConfig.class, "withAll", VirtualMachineDto.class, VLANNetworkDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(method, Lists.<Object> newArrayList(vm, null))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindNetworkConfigurationRefToPayload binder = new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() throws SecurityException, NoSuchMethodException { - VirtualMachineDto vm = CloudResources.virtualMachinePut(); - Object network = new Object(); - - Invokable<?, ?> method = method(TestNetworkConfig.class, "withAll", VirtualMachineDto.class, VLANNetworkDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(method, ImmutableList.<Object> of(vm, network))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindNetworkConfigurationRefToPayload binder = new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); - binder.bindToRequest(request, network); - } - - @Test(expectedExceptions = NoSuchElementException.class) - public void testBindNetworkConfigurationRefWithoutVirtualMachine() throws SecurityException, NoSuchMethodException { - VLANNetworkDto network = NetworkResources.privateNetworkPut(); - - Invokable<?, ?> method = method(TestNetworkConfig.class, "withoutVirtualMachine", VLANNetworkDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(method, ImmutableList.<Object> of(network))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindNetworkConfigurationRefToPayload binder = new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); - binder.bindToRequest(request, network); - } - - public void testBindNetworkConfigurationRef() throws SecurityException, NoSuchMethodException, IOException { - VirtualMachineDto vm = CloudResources.virtualMachinePut(); - VLANNetworkDto network = NetworkResources.privateNetworkPut(); - - Invokable<?, ?> method = method(TestNetworkConfig.class, "withAll", VirtualMachineDto.class, VLANNetworkDto.class); - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(method, ImmutableList.<Object> of(vm, network))).method(HttpMethod.GET) - .endpoint(URI.create("http://localhost")).build(); - - BindNetworkConfigurationRefToPayload binder = new BindNetworkConfigurationRefToPayload(new JAXBParser("false")); - - String configLink = vm.searchLink("configurations").getHref() + "/" + network.getId(); - - GeneratedHttpRequest newRequest = binder.bindToRequest(request, network); - assertPayloadEquals(newRequest.getPayload(), withHeader("<links><link href=\"" + configLink - + "\" rel=\"network_configuration\"/></links>"), LinksDto.class); - } - - interface TestNetworkConfig { - @GET - void withoutVirtualMachine(VLANNetworkDto network); - - @GET - void withAll(VirtualMachineDto virtualMachine, VLANNetworkDto network); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java deleted file mode 100644 index 26ee2ee..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkRefToPayloadTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.NetworkResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; - -/** - * Unit tests for the {@link BindNetworkRefToPayload} binder. - */ -@Test(groups = "unit", testName = "BindNetworkRefToPayloadTest") -public class BindNetworkRefToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindNetworkRef() throws IOException { - VLANNetworkDto network = NetworkResources.privateNetworkPut(); - BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, network); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + network.getEditLink().getHref() - + "\" rel=\"internalnetwork\"/></links>"), LinksDto.class); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java deleted file mode 100644 index eefb8fb..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindUnmanagedIpRefToPayloadTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.NetworkResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; - -/** - * Unit tests for the {@link BindUnmanagedIpRefToPayload} binder. - */ -@Test(groups = "unit", testName = "BindUnmanagedIpRefToPayloadTest") -public class BindUnmanagedIpRefToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindUnmanagedIpRefToPayload binder = new BindUnmanagedIpRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindUnmanagedIpRefToPayload binder = new BindUnmanagedIpRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindUnmanagedNetworkIpRef() throws IOException { - VLANNetworkDto network = NetworkResources.unmanagedNetworkPut(); - RESTLink ipsLink = network.searchLink("ips"); - BindUnmanagedIpRefToPayload binder = new BindUnmanagedIpRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, network); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + ipsLink.getHref() - + "\" rel=\"unmanagedip\"/></links>"), LinksDto.class); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java deleted file mode 100644 index 51a4497..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVirtualDatacenterRefToPayloadTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.CloudResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.cloud.VirtualDatacenterDto; - -/** - * Unit tests for the {@link BindVirtualDatacenterRefToPayload} binder. - */ -@Test(groups = "unit", testName = "BindVirtualDatacenterRefToPayloadTest") -public class BindVirtualDatacenterRefToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindVirtualDatacenterRefToPayload binder = new BindVirtualDatacenterRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindVirtualDatacenterRefToPayload binder = new BindVirtualDatacenterRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindSingleVolume() throws IOException { - VirtualDatacenterDto vdc = CloudResources.virtualDatacenterPut(); - BindVirtualDatacenterRefToPayload binder = new BindVirtualDatacenterRefToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, vdc); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + vdc.getEditLink().getHref() - + "\" rel=\"virtualdatacenter\"/></links>"), LinksDto.class); - } -}
