mirror of https://github.com/apache/jclouds.git
Merge pull request #523 from grkvlt/error
Issue 830: Use ResourceNotFoundException
This commit is contained in:
commit
018702a4c1
|
@ -21,6 +21,12 @@ package org.jclouds.vcloud.director.v1_5;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||||
|
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
*/
|
*/
|
||||||
|
@ -29,19 +35,19 @@ public class VCloudDirectorException extends RuntimeException {
|
||||||
/** The serialVersionUID. */
|
/** The serialVersionUID. */
|
||||||
private static final long serialVersionUID = -5292516858598372960L;
|
private static final long serialVersionUID = -5292516858598372960L;
|
||||||
|
|
||||||
private static final String MSG_FMT = "%s: %s";
|
private static final String MSG_FMT = "%s (%d) %s: %s";
|
||||||
|
|
||||||
private final Error error;
|
private final Error error;
|
||||||
private final Task task;
|
private final Task task;
|
||||||
|
|
||||||
public VCloudDirectorException(Error error) {
|
public VCloudDirectorException(Error error) {
|
||||||
super(String.format(MSG_FMT, "Error", error.getMessage()));
|
super(message(error, "Error"));
|
||||||
this.error = error;
|
this.error = error;
|
||||||
this.task = null;
|
this.task = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VCloudDirectorException(Task task) {
|
public VCloudDirectorException(Task task) {
|
||||||
super(String.format(MSG_FMT, "Task error", task.getError().getMessage()));
|
super(message(task.getError(), "Task error"));
|
||||||
this.error = task.getError();
|
this.error = task.getError();
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
@ -65,4 +71,14 @@ public class VCloudDirectorException extends RuntimeException {
|
||||||
public Task getTask() {
|
public Task getTask() {
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String message(Error error, String from) {
|
||||||
|
Iterable<String> words = Iterables.transform(Splitter.on('_').split(error.getMinorErrorCode()), new Function<String, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(String input) {
|
||||||
|
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, input);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return String.format(MSG_FMT, Joiner.on(' ').join(words), error.getMajorErrorCode(), from, error.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ public class Error {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific API error code.
|
* Specific API error code.
|
||||||
* <p/>
|
*
|
||||||
* For example - can indicate that vApp power on failed by some reason.
|
* For example - can indicate that vApp power on failed by some reason.
|
||||||
*/
|
*/
|
||||||
public String getMinorErrorCode() {
|
public String getMinorErrorCode() {
|
||||||
|
|
|
@ -26,6 +26,7 @@ import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.io.InputSuppliers;
|
import org.jclouds.io.InputSuppliers;
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
import org.jclouds.vcloud.director.v1_5.domain.Error;
|
||||||
|
|
||||||
|
@ -49,6 +50,9 @@ public class ThrowVCloudErrorOn4xx implements Function<Exception, Object> {
|
||||||
if (exception != null && exception.getResponse() != null && exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) {
|
if (exception != null && exception.getResponse() != null && exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) {
|
||||||
try {
|
try {
|
||||||
Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class);
|
Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class);
|
||||||
|
if (exception.getResponse().getStatusCode() == 403 && error.getMinorErrorCode().equals("ACCESS_TO_RESOURCE_IS_FORBIDDEN")) {
|
||||||
|
throw new ResourceNotFoundException(error.getMessage());
|
||||||
|
}
|
||||||
throw new VCloudDirectorException(error);
|
throw new VCloudDirectorException(error);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
@ -165,19 +166,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes
|
||||||
.xmlFilePayload("/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR)
|
.xmlFilePayload("/media/error403-catalog.xml", VCloudDirectorMediaType.ERROR)
|
||||||
.httpResponseBuilder().statusCode(403).build());
|
.httpResponseBuilder().statusCode(403).build());
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "No access to entity \"(com.vmware.vcloud.entity.media:e9cd3387-ac57-4d27-a481-9bee75e0690f)\".";
|
||||||
.message("No access to entity \"(com.vmware.vcloud.entity.media:e9cd3387-ac57-4d27-a481-9bee75e0690f)\".")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getMediaClient().getMedia(mediaUri);
|
client.getMediaClient().getMedia(mediaUri);
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,19 +191,15 @@ public class MediaClientExpectTest extends BaseVCloudDirectorRestClientExpectTes
|
||||||
.xmlFilePayload("/media/error403-fake.xml", VCloudDirectorMediaType.ERROR)
|
.xmlFilePayload("/media/error403-fake.xml", VCloudDirectorMediaType.ERROR)
|
||||||
.httpResponseBuilder().statusCode(403).build());
|
.httpResponseBuilder().statusCode(403).build());
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "No access to entity \"(com.vmware.vcloud.entity.media:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)\".";
|
||||||
.message("No access to entity \"(com.vmware.vcloud.entity.media:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)\".")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getMediaClient().getMedia(mediaUri);
|
client.getMediaClient().getMedia(mediaUri);
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
@ -113,19 +114,15 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
|
||||||
.xmlFilePayload("/network/error403-catalog.xml", VCloudDirectorMediaType.ERROR)
|
.xmlFilePayload("/network/error403-catalog.xml", VCloudDirectorMediaType.ERROR)
|
||||||
.httpResponseBuilder().statusCode(403).build());
|
.httpResponseBuilder().statusCode(403).build());
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "This operation is denied.";
|
||||||
.message("This operation is denied.")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getNetworkClient().getNetwork(networkUri);
|
client.getNetworkClient().getNetwork(networkUri);
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,19 +139,15 @@ public class NetworkClientExpectTest extends BaseVCloudDirectorRestClientExpectT
|
||||||
.xmlFilePayload("/network/error403-fake.xml", VCloudDirectorMediaType.ERROR)
|
.xmlFilePayload("/network/error403-fake.xml", VCloudDirectorMediaType.ERROR)
|
||||||
.httpResponseBuilder().statusCode(403).build());
|
.httpResponseBuilder().statusCode(403).build());
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "This operation is denied.";
|
||||||
.message("This operation is denied.")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getNetworkClient().getNetwork(networkUri);
|
client.getNetworkClient().getNetwork(networkUri);
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
@ -127,19 +128,15 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
|
getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
|
||||||
getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR));
|
getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR));
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "No access to entity \"com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c\".";
|
||||||
.message("No access to entity \"com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c\".")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getOrgClient().getOrg(orgUri);
|
client.getOrgClient().getOrg(orgUri);
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,19 +148,15 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
|
getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
|
||||||
getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR));
|
getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR));
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".";
|
||||||
.message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getOrgClient().getOrg(orgUri);
|
client.getOrgClient().getOrg(orgUri);
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
@ -162,20 +163,16 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse, orgRequest, orgResponse);
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".";
|
||||||
.message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getTaskClient().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"));
|
client.getTaskClient().getTaskList(URI.create("https://vcloudbeta.bluelock.com/api/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"));
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.CustomizationSection;
|
import org.jclouds.vcloud.director.v1_5.domain.CustomizationSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.FirewallRule;
|
import org.jclouds.vcloud.director.v1_5.domain.FirewallRule;
|
||||||
|
@ -119,7 +120,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
client.getVAppTemplate(uri);
|
client.getVAppTemplate(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testErrorEditVAppTemplate() {
|
public void testErrorEditVAppTemplate() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -157,7 +158,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
assertNotNull(task);
|
assertNotNull(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testConsolidateMissingVAppTemplate() {
|
public void testConsolidateMissingVAppTemplate() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -208,7 +209,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
assertNotNull(task);
|
assertNotNull(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testEnableDownloadMissingVAppTemplate() {
|
public void testEnableDownloadMissingVAppTemplate() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -274,7 +275,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
assertNotNull(task);
|
assertNotNull(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testErrorGetCustomizationSection() {
|
public void testErrorGetCustomizationSection() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -286,7 +287,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
client.getVAppTemplateCustomizationSection(uri);
|
client.getVAppTemplateCustomizationSection(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testErrorEditCustomizationSection() {
|
public void testErrorEditCustomizationSection() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -362,7 +363,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
assertNotNull(task);
|
assertNotNull(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testErrorGetLeaseSettingsSection() {
|
public void testErrorGetLeaseSettingsSection() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -374,7 +375,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
client.getVappTemplateLeaseSettingsSection(uri);
|
client.getVappTemplateLeaseSettingsSection(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testErrorEditLeaseSettingsSection() throws ParseException {
|
public void testErrorEditLeaseSettingsSection() throws ParseException {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -455,7 +456,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
assertNotNull(task);
|
assertNotNull(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testErrorGetMetadataValue() {
|
public void testErrorGetMetadataValue() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
@ -479,7 +480,7 @@ public class VAppTemplateClientExpectTest extends BaseVCloudDirectorRestClientEx
|
||||||
client.getMetadataClient().setMetadata(uri, "12345", exampleMetadataValue());
|
client.getMetadataClient().setMetadata(uri, "12345", exampleMetadataValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VCloudDirectorException.class)
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
public void testDeleteMissingMetadataValue() {
|
public void testDeleteMissingMetadataValue() {
|
||||||
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
final String templateId = "/vAppTemplate/vappTemplate-ef4415e6-d413-4cbb-9262-f9bbec5f2ea9";
|
||||||
URI uri = URI.create(endpoint + templateId);
|
URI uri = URI.create(endpoint + templateId);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
|
@ -119,17 +120,15 @@ public class VdcClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.xmlFilePayload("/vdc/error403-fake.xml", VCloudDirectorMediaType.ERROR)
|
.xmlFilePayload("/vdc/error403-fake.xml", VCloudDirectorMediaType.ERROR)
|
||||||
.httpResponseBuilder().statusCode(403).build());
|
.httpResponseBuilder().statusCode(403).build());
|
||||||
|
|
||||||
Error expected = Error.builder()
|
String message = "No access to entity \"com.vmware.vcloud.entity.vdc:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".";
|
||||||
.message("No access to entity \"com.vmware.vcloud.entity.vdc:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
|
|
||||||
.majorErrorCode(403)
|
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.getVdcClient().getVdc(URI.create(endpoint + "/vdc/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"));
|
client.getVdcClient().getVdc(URI.create(endpoint + "/vdc/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"));
|
||||||
fail("Should give HTTP 403 error");
|
fail("Should give HTTP 403 error");
|
||||||
} catch (VCloudDirectorException vde) {
|
} catch (ResourceNotFoundException rnfe) {
|
||||||
assertEquals(vde.getError(), expected);
|
assertEquals(rnfe.getMessage(), message);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("Should have thrown a ResourceNotFoundException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue