mirror of https://github.com/apache/jclouds.git
Merge pull request #275 from jsonking/695-Terremark
Issue 695: CREATE and REMOVE on InternetService plus DnsSettings in XML for createVM
This commit is contained in:
commit
0db26708fe
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds 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.tmrk.enterprisecloud.binders;
|
||||||
|
|
||||||
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For use with {@see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#createInternetService}
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BindCreateInternetServiceToXmlPayload extends BindInternetServiceToXmlPayload {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BindCreateInternetServiceToXmlPayload(BindToStringPayload stringBinder) {
|
||||||
|
super(stringBinder, "CreateInternetService");
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,9 +24,7 @@ import org.jclouds.rest.Binder;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.*;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -135,14 +133,17 @@ public class BindCreateVirtualMachineKeyToXmlPayload implements Binder {
|
||||||
in = in.e("LinuxCustomization")
|
in = in.e("LinuxCustomization")
|
||||||
.e("NetworkSettings")
|
.e("NetworkSettings")
|
||||||
.e("NetworkAdapterSettings");
|
.e("NetworkAdapterSettings");
|
||||||
|
|
||||||
for(NetworkAdapterSetting setting:linuxCustomization.getNetworkSettings().getNetworkAdapterSettings().getNetworkAdapterSettings()) {
|
for(NetworkAdapterSetting setting:linuxCustomization.getNetworkSettings().getNetworkAdapterSettings().getNetworkAdapterSettings()) {
|
||||||
in = networkAdapterSetting(in,setting);
|
in = networkAdapterSetting(in,setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO DNS Settings
|
in = in.up();
|
||||||
|
in = dnsSettings(in, linuxCustomization.getNetworkSettings().getDnsSettings());
|
||||||
|
|
||||||
String href = linuxCustomization.getSshKey().getHref().toString();
|
String href = linuxCustomization.getSshKey().getHref().toString();
|
||||||
String type = linuxCustomization.getSshKey().getType();
|
String type = linuxCustomization.getSshKey().getType();
|
||||||
return in.up().up().e("SshKey").a("href",href).a("type",type).up().up();
|
return in.up().e("SshKey").a("href",href).a("type",type).up().up();
|
||||||
}
|
}
|
||||||
|
|
||||||
private XMLBuilder networkAdapterSetting(XMLBuilder builder, NetworkAdapterSetting setting) {
|
private XMLBuilder networkAdapterSetting(XMLBuilder builder, NetworkAdapterSetting setting) {
|
||||||
|
@ -155,6 +156,18 @@ public class BindCreateVirtualMachineKeyToXmlPayload implements Binder {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private XMLBuilder dnsSettings(XMLBuilder in, DnsSettings dnsSettings) {
|
||||||
|
if(dnsSettings==null)return in;
|
||||||
|
final String primary = dnsSettings.getPrimaryDns();
|
||||||
|
final String secondary = dnsSettings.getSecondaryDns();
|
||||||
|
|
||||||
|
in = in.e("DnsSettings").e("PrimaryDns").t(primary).up();
|
||||||
|
if(secondary!=null && !secondary.isEmpty()) {
|
||||||
|
in = in.e("SecondaryDns").t(secondary).up();
|
||||||
|
}
|
||||||
|
return in.up();
|
||||||
|
}
|
||||||
|
|
||||||
private XMLBuilder windowsCustomization(XMLBuilder builder, CreateVirtualMachine vmData) {
|
private XMLBuilder windowsCustomization(XMLBuilder builder, CreateVirtualMachine vmData) {
|
||||||
WindowsCustomization windowsCustomization = vmData.getWindowsCustomization();
|
WindowsCustomization windowsCustomization = vmData.getWindowsCustomization();
|
||||||
if(windowsCustomization==null) return builder;
|
if(windowsCustomization==null) return builder;
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.Binder;
|
import org.jclouds.rest.Binder;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
|
||||||
|
|
||||||
|
@ -36,17 +37,23 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For use with {@see VirtualMachineClient#createVirtualMachineFromTemplate}
|
* For use with {@see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#editInternetService}
|
||||||
* @author Jason King
|
* @author Jason King
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class BindInternetServiceToXmlPayload implements Binder {
|
public class BindInternetServiceToXmlPayload implements Binder {
|
||||||
|
|
||||||
private final BindToStringPayload stringBinder;
|
private final BindToStringPayload stringBinder;
|
||||||
|
private final String rootElement;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BindInternetServiceToXmlPayload(BindToStringPayload stringBinder) {
|
BindInternetServiceToXmlPayload(BindToStringPayload stringBinder) {
|
||||||
|
this(stringBinder,"InternetService");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BindInternetServiceToXmlPayload(BindToStringPayload stringBinder, String rootElement) {
|
||||||
this.stringBinder = stringBinder;
|
this.stringBinder = stringBinder;
|
||||||
|
this.rootElement = rootElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,6 +72,8 @@ public class BindInternetServiceToXmlPayload implements Binder {
|
||||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||||
|
|
||||||
final String name = checkNotNull(data.getName(), "name");
|
final String name = checkNotNull(data.getName(), "name");
|
||||||
|
final Protocol protocol = data.getProtocol();
|
||||||
|
final int port = data.getPort();
|
||||||
final String enabled = Boolean.toString(data.isEnabled());
|
final String enabled = Boolean.toString(data.isEnabled());
|
||||||
final String description = data.getDescription();
|
final String description = data.getDescription();
|
||||||
final InternetServicePersistenceType persistence = data.getPersistence();
|
final InternetServicePersistenceType persistence = data.getPersistence();
|
||||||
|
@ -72,19 +81,30 @@ public class BindInternetServiceToXmlPayload implements Binder {
|
||||||
final NamedResource trustedNetworkGroup = data.getTrustedNetworkGroup();
|
final NamedResource trustedNetworkGroup = data.getTrustedNetworkGroup();
|
||||||
final NamedResource backupInternetService = data.getBackupInternetService();
|
final NamedResource backupInternetService = data.getBackupInternetService();
|
||||||
|
|
||||||
|
XMLBuilder builder = XMLBuilder.create(rootElement).a("name", name);
|
||||||
|
|
||||||
|
if(protocol!=null) {
|
||||||
|
builder = builder.e("Protocol").t(protocol.value()).up();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(port>0) {
|
||||||
|
builder = builder.e("Port").t(Integer.toString(port)).up();
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.e("Enabled").t(enabled).up();
|
||||||
|
|
||||||
XMLBuilder builder = XMLBuilder.create("InternetService").a("name", name)
|
|
||||||
.e("Enabled").t(enabled).up();
|
|
||||||
if(description!=null) {
|
if(description!=null) {
|
||||||
builder = builder.e("Description").t(description).up();
|
builder = builder.e("Description").t(description).up();
|
||||||
}
|
}
|
||||||
|
//TODO: Public IP
|
||||||
builder = persistence(builder,persistence);
|
builder = persistence(builder,persistence);
|
||||||
|
|
||||||
if(redirectUrl!=null) {
|
if(redirectUrl!=null) {
|
||||||
builder = builder.e("RedirectUrl").t(redirectUrl);
|
builder = builder.e("RedirectUrl").t(redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Monitor
|
||||||
|
|
||||||
if(trustedNetworkGroup!=null) {
|
if(trustedNetworkGroup!=null) {
|
||||||
final String href = trustedNetworkGroup.getHref().toString();
|
final String href = trustedNetworkGroup.getHref().toString();
|
||||||
String groupName = trustedNetworkGroup.getName();
|
String groupName = trustedNetworkGroup.getName();
|
||||||
|
@ -99,6 +119,8 @@ public class BindInternetServiceToXmlPayload implements Binder {
|
||||||
builder = builder.e("BackupInternetService").a("href",href).a("name",groupName).a("type",type).up();
|
builder = builder.e("BackupInternetService").a("href",href).a("name",groupName).a("type",type).up();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: NodeServices
|
||||||
|
|
||||||
return builder.asString(outputProperties);
|
return builder.asString(outputProperties);
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
|
@ -6,21 +6,39 @@ import javax.xml.bind.annotation.XmlEnumValue;
|
||||||
@XmlEnum
|
@XmlEnum
|
||||||
public enum Protocol {
|
public enum Protocol {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HyperText Transfer Protocol
|
||||||
|
*/
|
||||||
@XmlEnumValue("HTTP")
|
@XmlEnumValue("HTTP")
|
||||||
HTTP,
|
HTTP,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HyperText Transfer Protocol Secure
|
||||||
|
*/
|
||||||
@XmlEnumValue("HTTPS")
|
@XmlEnumValue("HTTPS")
|
||||||
HTTPS,
|
HTTPS,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transmission Control Protocol
|
||||||
|
*/
|
||||||
@XmlEnumValue("TCP")
|
@XmlEnumValue("TCP")
|
||||||
TCP,
|
TCP,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User Datagram Protocol
|
||||||
|
*/
|
||||||
@XmlEnumValue("UDP")
|
@XmlEnumValue("UDP")
|
||||||
UDP,
|
UDP,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internet Protocol security
|
||||||
|
*/
|
||||||
@XmlEnumValue("IPSEC")
|
@XmlEnumValue("IPSEC")
|
||||||
IPSEC,
|
IPSEC,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File Transfer Protocol
|
||||||
|
*/
|
||||||
@XmlEnumValue("FTP")
|
@XmlEnumValue("FTP")
|
||||||
FTP,
|
FTP,
|
||||||
|
|
||||||
|
@ -31,4 +49,8 @@ public enum Protocol {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name();
|
return name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return name();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -22,13 +22,14 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.*;
|
import org.jclouds.rest.annotations.*;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.binders.BindCreateInternetServiceToXmlPayload;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.binders.BindInternetServiceToXmlPayload;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
||||||
import org.jclouds.tmrk.enterprisecloud.functions.URISource;
|
import org.jclouds.tmrk.enterprisecloud.functions.URISource;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,8 +59,29 @@ public interface InternetServiceAsyncClient {
|
||||||
* @see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#editInternetService
|
* @see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#editInternetService
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
|
@Produces(MediaType.APPLICATION_XML)
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.task")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Task> editInternetService(@EndpointParam(parser = URISource.GetURI.class) @BinderParam(BindInternetServiceToXmlPayload.class) InternetService internetService);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#editInternetService
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_XML)
|
||||||
@Consumes("application/vnd.tmrk.cloud.internetService")
|
@Consumes("application/vnd.tmrk.cloud.internetService")
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Task> editInternetService(@EndpointParam(parser = URISource.GetURI.class) InternetService internetService);
|
ListenableFuture<InternetService> createInternetService(@EndpointParam URI uri, @BinderParam(BindCreateInternetServiceToXmlPayload.class)InternetService data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.jclouds.tmrk.enterprisecloud.features.InternetServiceClient#removeInternetService
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@Consumes("application/vnd.tmrk.cloud.task")
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Task> removeInternetService(@EndpointParam URI uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public interface InternetServiceClient {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getInternetService call returns information regarding a specified Internet service defined in an environment.
|
* The getInternetService call returns information regarding a specified Internet service defined in an environment.
|
||||||
* @param uri the uri of the internet service
|
* @param uri the uri of the internet service
|
||||||
* e.g. /cloudapi/ecloud/internetservices/{internet service id}
|
* e.g. /cloudapi/ecloud/internetservices/{internet service id}
|
||||||
* @return the internet service
|
* @return the internet service
|
||||||
|
@ -75,4 +75,37 @@ public interface InternetServiceClient {
|
||||||
* @return the Task representing the create action
|
* @return the Task representing the create action
|
||||||
*/
|
*/
|
||||||
Task editInternetService(InternetService service);
|
Task editInternetService(InternetService service);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The createInternetService call creates an Internet service on a public IP address in an environment.
|
||||||
|
* If successful, the call returns information regarding the Internet service that was created.
|
||||||
|
* Input InternetService object Properties:
|
||||||
|
* The name is required and may not be that of another Internet service.
|
||||||
|
* Protocol is required.
|
||||||
|
* Port is required and must be in the range of 1 to 65535.
|
||||||
|
* Enabled is required.
|
||||||
|
* Type refers to the method for persisting a connection session.
|
||||||
|
* If Timeout is absent with a type of SourceIp then Timeout defaults to 2 minutes.
|
||||||
|
* Omit Timeout if type is None.
|
||||||
|
*
|
||||||
|
* Note: The href of the InternetService data parameter is not used.
|
||||||
|
* When creating the input object you may use any value or an empty URI
|
||||||
|
* e.g. java.net.URI.create("")
|
||||||
|
*
|
||||||
|
* @param uri The uri of the call based on the public IP identifier
|
||||||
|
* e.g. /cloudapi/ecloud/internetServices/publicIps/{public IP identifier}/action/createInternetService
|
||||||
|
* @param data The input internet service data used to create the service
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
InternetService createInternetService(URI uri, InternetService data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The removeInternetService call removes an Internet service from an environment.
|
||||||
|
* If successful, the call returns the task that removed the Internet service.
|
||||||
|
* Note: The Internet service must have no node services associated to remove.
|
||||||
|
* @param uri the uri of the call based on the internet service
|
||||||
|
* e.g. /cloudapi/ecloud/internetServices/{internet service identifier}
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Task removeInternetService(URI uri);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds 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.tmrk.enterprisecloud.predicates;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.features.TaskClient;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Predicates relating to a task
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
public class TaskPredicates {
|
||||||
|
|
||||||
|
private TaskClient client;
|
||||||
|
|
||||||
|
public static Predicate<Task> completeOrSuccess(final TaskClient client) {
|
||||||
|
return new Predicate<Task>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(Task task) {
|
||||||
|
checkNotNull(task,"task cannot be null");
|
||||||
|
if(client!=null) {
|
||||||
|
task = client.getTask(task.getURI());
|
||||||
|
}
|
||||||
|
switch(task.getStatus()) {
|
||||||
|
case QUEUED:
|
||||||
|
case RUNNING:
|
||||||
|
return false;
|
||||||
|
case COMPLETE:
|
||||||
|
case SUCCESS:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Task Failed:"+task.getHref()+", Status:"+task.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "completeOrSuccess";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds 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.tmrk.enterprisecloud.binders;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code BindCreateInternetServiceToXmlPayload}
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "BindCreateInternetServiceToXmlPayloadTest")
|
||||||
|
public class BindCreateInternetServiceToXmlPayloadTest {
|
||||||
|
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public void testPayloadMinimalXmlContent() throws IOException {
|
||||||
|
String expected =
|
||||||
|
"<CreateInternetService name='testName'>" +
|
||||||
|
"<Protocol>HTTP</Protocol>" +
|
||||||
|
"<Port>2020</Port>" +
|
||||||
|
"<Enabled>true</Enabled>" +
|
||||||
|
"<Persistence>" +
|
||||||
|
"<Type>None</Type>" +
|
||||||
|
"</Persistence>" +
|
||||||
|
"</CreateInternetService>";
|
||||||
|
|
||||||
|
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||||
|
BindInternetServiceToXmlPayload binder = injector
|
||||||
|
.getInstance(BindCreateInternetServiceToXmlPayload.class);
|
||||||
|
|
||||||
|
InternetService.Builder builder = InternetService.builder()
|
||||||
|
.href(URI.create(""))
|
||||||
|
.name("testName")
|
||||||
|
.protocol(Protocol.HTTP)
|
||||||
|
.port(2020)
|
||||||
|
.enabled(true)
|
||||||
|
.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build());
|
||||||
|
|
||||||
|
binder.bindToRequest(request, builder.build());
|
||||||
|
assertEquals(request.getPayload().getRawContent(), expected.replaceAll("'","\""));
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,10 +26,7 @@ import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
|
import org.jclouds.tmrk.enterprisecloud.domain.network.*;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSettings;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkSettings;
|
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -67,6 +64,10 @@ public class BindCreateVirtualMachineKeyToXmlPayloadTest {
|
||||||
"<IpAddress>10.146.204.68</IpAddress>" +
|
"<IpAddress>10.146.204.68</IpAddress>" +
|
||||||
"</NetworkAdapter>" +
|
"</NetworkAdapter>" +
|
||||||
"</NetworkAdapterSettings>" +
|
"</NetworkAdapterSettings>" +
|
||||||
|
"<DnsSettings>" +
|
||||||
|
"<PrimaryDns>1.2.3.4</PrimaryDns>" +
|
||||||
|
"<SecondaryDns>5.6.7.8</SecondaryDns>" +
|
||||||
|
"</DnsSettings>" +
|
||||||
"</NetworkSettings>" +
|
"</NetworkSettings>" +
|
||||||
"<SshKey href='/cloudapi/ecloud/admin/sshkeys/77' type='application/vnd.tmrk.cloud.admin.sshKey'/>" +
|
"<SshKey href='/cloudapi/ecloud/admin/sshkeys/77' type='application/vnd.tmrk.cloud.admin.sshKey'/>" +
|
||||||
"</LinuxCustomization>" +
|
"</LinuxCustomization>" +
|
||||||
|
@ -102,7 +103,9 @@ public class BindCreateVirtualMachineKeyToXmlPayloadTest {
|
||||||
|
|
||||||
NetworkAdapterSettings adapterSettings = NetworkAdapterSettings.builder()
|
NetworkAdapterSettings adapterSettings = NetworkAdapterSettings.builder()
|
||||||
.addNetworkAdapterSetting(adapterSetting).build();
|
.addNetworkAdapterSetting(adapterSetting).build();
|
||||||
NetworkSettings networkSettings = NetworkSettings.builder().networkAdapterSettings(adapterSettings).build();
|
NetworkSettings networkSettings = NetworkSettings.builder().networkAdapterSettings(adapterSettings)
|
||||||
|
.dnsSettings(DnsSettings.builder().primaryDns("1.2.3.4").secondaryDns("5.6.7.8").build())
|
||||||
|
.build();
|
||||||
|
|
||||||
LinuxCustomization linuxCustomization = LinuxCustomization.builder()
|
LinuxCustomization linuxCustomization = LinuxCustomization.builder()
|
||||||
.sshKey(sshKey)
|
.sshKey(sshKey)
|
||||||
|
|
|
@ -23,9 +23,13 @@ import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -39,6 +43,21 @@ import java.net.URISyntaxException;
|
||||||
@Test(groups = "unit", testName = "LayoutAsyncClientTest")
|
@Test(groups = "unit", testName = "LayoutAsyncClientTest")
|
||||||
public class InternetServiceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<InternetServiceAsyncClient> {
|
public class InternetServiceAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<InternetServiceAsyncClient> {
|
||||||
|
|
||||||
|
private URI uri = URI.create("/cloudapi/ecloud/internetservices/797");
|
||||||
|
private InternetServicePersistenceType persistenceType;
|
||||||
|
private InternetService service;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() {
|
||||||
|
|
||||||
|
persistenceType = InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build();
|
||||||
|
|
||||||
|
service = InternetService.builder().href(uri)
|
||||||
|
.name("testName")
|
||||||
|
.enabled(true)
|
||||||
|
.persistence(persistenceType).build();
|
||||||
|
}
|
||||||
|
|
||||||
public void testGetInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
public void testGetInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
Method method = InternetServiceAsyncClient.class.getMethod("getInternetService", URI.class);
|
Method method = InternetServiceAsyncClient.class.getMethod("getInternetService", URI.class);
|
||||||
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/internetservices/797"));
|
HttpRequest httpRequest = processor.createRequest(method, URI.create("/cloudapi/ecloud/internetservices/797"));
|
||||||
|
@ -58,15 +77,54 @@ public class InternetServiceAsyncClientTest extends BaseTerremarkEnterpriseCloud
|
||||||
public void testEditInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
public void testEditInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
Method method = InternetServiceAsyncClient.class.getMethod("editInternetService", InternetService.class);
|
Method method = InternetServiceAsyncClient.class.getMethod("editInternetService", InternetService.class);
|
||||||
|
|
||||||
URI uri = URI.create("/cloudapi/ecloud/internetservices/797");
|
|
||||||
InternetService service = InternetService.builder().href(uri).build();
|
|
||||||
|
|
||||||
HttpRequest httpRequest = processor.createRequest(method, service);
|
HttpRequest httpRequest = processor.createRequest(method, service);
|
||||||
|
|
||||||
String requestLine = "PUT https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/internetservices/797 HTTP/1.1";
|
String requestLine = "PUT https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/internetservices/797 HTTP/1.1";
|
||||||
|
String payload = "<InternetService name='testName'><Enabled>true</Enabled><Persistence><Type>None</Type></Persistence></InternetService>".replaceAll("'","\"");
|
||||||
|
assertRequestLineEquals(httpRequest, requestLine);
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
|
||||||
|
assertPayloadEquals(httpRequest, payload, MediaType.APPLICATION_XML, false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testCreateInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
Method method = InternetServiceAsyncClient.class.getMethod("createInternetService", URI.class, InternetService.class);
|
||||||
|
|
||||||
|
URI uri = URI.create("/cloudapi/ecloud/internetServices/publicIps/123/action/createInternetService");
|
||||||
|
InternetService createData = service.toBuilder().href(URI.create("")).protocol(Protocol.HTTP).port(2020).build();
|
||||||
|
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, uri, createData);
|
||||||
|
|
||||||
|
String requestLine = "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/internetServices/publicIps/123/action/createInternetService HTTP/1.1";
|
||||||
|
String payload = "<CreateInternetService name='testName'><Protocol>HTTP</Protocol><Port>2020</Port><Enabled>true</Enabled><Persistence><Type>None</Type></Persistence></CreateInternetService>".replaceAll("'","\"");
|
||||||
assertRequestLineEquals(httpRequest, requestLine);
|
assertRequestLineEquals(httpRequest, requestLine);
|
||||||
assertNonPayloadHeadersEqual(httpRequest,
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
"Accept: application/vnd.tmrk.cloud.internetService\nx-tmrk-version: 2011-07-01\n");
|
"Accept: application/vnd.tmrk.cloud.internetService\nx-tmrk-version: 2011-07-01\n");
|
||||||
|
assertPayloadEquals(httpRequest, payload, MediaType.APPLICATION_XML, false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRemoveInternetService() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||||
|
Method method = InternetServiceAsyncClient.class.getMethod("removeInternetService", URI.class);
|
||||||
|
|
||||||
|
URI uri = URI.create("/cloudapi/ecloud/internetServices/123");
|
||||||
|
|
||||||
|
HttpRequest httpRequest = processor.createRequest(method, uri);
|
||||||
|
|
||||||
|
String requestLine = "DELETE https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/internetServices/123 HTTP/1.1";
|
||||||
|
assertRequestLineEquals(httpRequest, requestLine);
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/vnd.tmrk.cloud.task\nx-tmrk-version: 2011-07-01\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||||
|
|
|
@ -18,15 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.features;
|
package org.jclouds.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.jclouds.tmrk.enterprisecloud.predicates.TaskPredicates.completeOrSuccess;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code InternetServiceClient}
|
* Tests behavior of {@code InternetServiceClient}
|
||||||
|
@ -39,43 +42,48 @@ public class InternetServiceClientLiveTest extends BaseTerremarkEnterpriseCloudC
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
client = context.getApi().getInternetServiceClient();
|
client = context.getApi().getInternetServiceClient();
|
||||||
|
taskClient = context.getApi().getTaskClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
private InternetServiceClient client;
|
private InternetServiceClient client;
|
||||||
|
private TaskClient taskClient;
|
||||||
|
|
||||||
public void testGetInternetService() throws Exception {
|
public void testInternetServiceCalls() {
|
||||||
//TODO: The URI should come from the environment
|
InternetService service = InternetService.builder()
|
||||||
//TODO: Should create a new service edit it then delete it.
|
.name("live test")
|
||||||
//TODO: Need a retryable predicate to wait until the task is done.
|
.href(URI.create(""))
|
||||||
URI uri = URI.create("/cloudapi/ecloud/internetservices/797");
|
.protocol(Protocol.TCP)
|
||||||
InternetService internetService = client.getInternetService(uri);
|
.port(2020)
|
||||||
assertNotNull(internetService);
|
.enabled(true)
|
||||||
/*
|
.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build())
|
||||||
final String originalName = internetService.getName();
|
.build();
|
||||||
final String newName = originalName+"edited";
|
|
||||||
boolean enable = !internetService.isEnabled();
|
|
||||||
|
|
||||||
// Change the name and enabled flag
|
// TODO: Fetch a public ip from the environment
|
||||||
testEditInternetService(internetService.getHref(),newName,enable);
|
// This has a method not allowed error - needs debugging.
|
||||||
internetService = client.getInternetService(uri);
|
URI uri = URI.create("/cloudapi/ecloud/publicips/3929");
|
||||||
assertEquals(internetService.getName(),newName);
|
InternetService internetService = client.createInternetService(uri, service);
|
||||||
assertEquals(internetService.isEnabled(),enable);
|
System.out.println("service:"+internetService);
|
||||||
|
|
||||||
// Change it back again
|
InternetService editServiceData = InternetService.builder().href(uri).name("testName").enabled(false).build();
|
||||||
enable = !internetService.isEnabled();
|
|
||||||
testEditInternetService(internetService.getHref(),originalName,enable);
|
Task editTask = client.editInternetService(editServiceData);
|
||||||
assertEquals(internetService.getName(),originalName);
|
System.out.println("Task:"+editTask);
|
||||||
assertEquals(internetService.isEnabled(),enable);
|
RetryablePredicate retryablePredicate = new RetryablePredicate(completeOrSuccess(taskClient), 1000*60);
|
||||||
*/
|
if (!retryablePredicate.apply(editTask)) {
|
||||||
|
fail("Did not manage to edit service:"+editTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
InternetService editedService = client.getInternetService(internetService.getHref());
|
||||||
|
assertEquals(editedService.getName(),"testName");
|
||||||
|
assertFalse(editedService.isEnabled());
|
||||||
|
|
||||||
|
Task removeTask = client.removeInternetService(internetService.getHref());
|
||||||
|
if (!retryablePredicate.apply(removeTask)) {
|
||||||
|
fail("Did not manage to remove service:"+removeTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMissingInternetService() {
|
public void testGetMissingInternetService() {
|
||||||
assertNull(client.getInternetService(URI.create("/cloudapi/ecloud/internetservices/-1")));
|
assertNull(client.getInternetService(URI.create("/cloudapi/ecloud/internetservices/-1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testEditInternetService(URI uri, String name, boolean enable) {
|
|
||||||
InternetService service = InternetService.builder().href(uri).name(name).enabled(enable).build();
|
|
||||||
Task task = client.editInternetService(service);
|
|
||||||
//TODO: Wait for task to complete.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds 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.tmrk.enterprisecloud.predicates;
|
||||||
|
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
import static org.jclouds.tmrk.enterprisecloud.predicates.TaskPredicates.completeOrSuccess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jason King
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "TaskPredicatesTest")
|
||||||
|
public class TaskPredicatesTest {
|
||||||
|
|
||||||
|
private Task task;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() {
|
||||||
|
task = Task.builder().href(URI.create("")).name("test")
|
||||||
|
.operation("no-op")
|
||||||
|
.impactedItem(NamedResource.builder().href(URI.create("")).build())
|
||||||
|
.startTime(new Date())
|
||||||
|
.initiatedBy(NamedResource.builder().href(URI.create("")).build())
|
||||||
|
.status(Task.Status.UNRECOGNIZED)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCompleteOrSuccess() {
|
||||||
|
assertTrue(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.COMPLETE).build()));
|
||||||
|
assertTrue(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.SUCCESS).build()));
|
||||||
|
assertFalse(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.RUNNING).build()));
|
||||||
|
assertFalse(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.QUEUED).build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
|
public void testCompleteOrSuccessWhenNull() {
|
||||||
|
TaskPredicates.completeOrSuccess(null).apply(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
|
public void testCompleteOrSuccessWhenFailure() {
|
||||||
|
TaskPredicates.completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.FAILED).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
|
public void testCompleteOrSuccessWhenError() {
|
||||||
|
TaskPredicates.completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.ERROR).build());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue