Add plain CodeException to use internally in the webapp. WebCodeExceptions can be created from plain exceptions now. New test cases for exceptions.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@161932 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
8aff6e850e
commit
2240582f2c
|
@ -0,0 +1,29 @@
|
|||
|
||||
package org.gcube.resourcemanagement.manager.io.exceptions;
|
||||
|
||||
/**
|
||||
* A local exception wrapping an {@link ErrorCode}.
|
||||
*
|
||||
* @author Manuele Simi (ISTI CNR)
|
||||
*
|
||||
*/
|
||||
public class CodeException extends Exception implements ErrorCode {
|
||||
|
||||
private static final long serialVersionUID = 1872093579811881630L;
|
||||
private final int id;
|
||||
private final String message;
|
||||
|
||||
public CodeException(ErrorCode code) {
|
||||
super();
|
||||
this.id = code.getId();
|
||||
this.message = code.getMessage();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.gcube.resourcemanagement.manager.io.exceptions;
|
||||
|
||||
/**
|
||||
* Don't forget to comment!
|
||||
* An {@link ErrorCode} that can be serialized in a {@link WebCodeException}.
|
||||
*
|
||||
* @author Manuele Simi (ISTI CNR)
|
||||
*
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.resourcemanagement.manager.io.exceptions;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMCode;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Don't forget to comment!
|
||||
*
|
||||
* @author Manuele Simi (ISTI CNR)
|
||||
*
|
||||
*/
|
||||
public class LocalCodeExceptionTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link org.gcube.resourcemanagement.manager.io.exceptions.CodeException#CodeException(org.gcube.resourcemanagement.manager.io.exceptions.ErrorCode)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCodeException() {
|
||||
CodeException exception = new CodeException(RMCode.GENERIC_ERROR_FROM_RR);
|
||||
assertTrue("Unexpected id", exception.getId() == RMCode.GENERIC_ERROR_FROM_RR.getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -11,21 +11,23 @@ import org.junit.runner.RunWith;
|
|||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebCodeException}s
|
||||
*
|
||||
* Tests for {@link WebCodeException}s
|
||||
*
|
||||
* @author Manuele Simi (ISTI CNR)
|
||||
*
|
||||
*/
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public class CodeExceptionTest {
|
||||
public class WebCodeExceptionTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link org.gcube.resourcemanagement.manager.io.exceptions.WebCodeException#CodeException(org.gcube.resourcemanagement.manager.io.rs.RMCode)}.
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.io.exceptions.WebCodeException#CodeException(org.gcube.resourcemanagement.manager.io.rs.RMCode)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCodeException() {
|
||||
public void testWebCodeException() {
|
||||
WebCodeException exception = new WebCodeException(RMCode.CONTEXT_ALREADY_EXIST);
|
||||
//unfortunately, we cannot test the response readEntity method on an outbound response
|
||||
// unfortunately, we cannot test the response readEntity method on an
|
||||
// outbound response
|
||||
assertTrue("Unexpected code", Objects.nonNull(exception.getResponse()));
|
||||
|
||||
}
|
Loading…
Reference in New Issue