Improve formatting.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@161894 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2017-12-22 20:30:28 +00:00
parent 4dccab1032
commit 7b31392c6f
1 changed files with 28 additions and 29 deletions

View File

@ -32,7 +32,6 @@ import org.junit.runners.MethodSorters;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* Test cases for the Context methods.
*
@ -43,20 +42,19 @@ import com.fasterxml.jackson.core.JsonProcessingException;
public class RMContextTest extends JerseyTest {
private final static String contextName = "firstContext";
private final static String RR = "";
private static boolean skipTest = false;
public static final String DEFAULT_TEST_SCOPE ="";
public static final String DEFAULT_TEST_SCOPE = "";
@BeforeClass
public static void beforeClass() throws Exception{
public static void beforeClass() throws Exception {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception{
public static void setContext(String token) throws ObjectNotFound, Exception {
if (DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
@ -64,58 +62,57 @@ public class RMContextTest extends JerseyTest {
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentScope(token));
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception{
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
@Override
protected Application configure() {
return new ResourceConfig(RMContext.class);
}
/**
* Test method for marshal/unmarshal contexts.
*/
@Test
public void step0_Context() {
Context newContext = new ContextImpl(contextName);
//newContext.setParent(new ContextImpl("parent"));
// newContext.setParent(new ContextImpl("parent"));
try {
ISMapper.unmarshal(Context.class, ISMapper.marshal(newContext));
} catch (IOException e) {
e.printStackTrace();
assertFalse("Failed to unmarshal the context.", false);
}
}
/**
* Test method for
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}.
*/
@Test
public void step1_Create() {
if (skipTest) return;
if (skipTest)
return;
Context newContext = new ContextImpl(contextName);
try {
System.out.print(ISMapper.marshal(newContext));
Response create = target("context")
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
.request()
Response create = target("context").queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request()
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
assertNotNull(create);
//TODO: to restore an expected success when create is fully functional
// TODO: to restore an expected success when create is fully
// functional
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
Status.CREATED.getStatusCode(), create.getStatus());
assertEquals("Context successfully created.", (String) create.readEntity(String.class));
@ -123,24 +120,26 @@ public class RMContextTest extends JerseyTest {
assertFalse("Failed to marshal the context.", false);
}
}
/**
* Test method for
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)} when the parent does not exist.
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
* when the parent does not exist.
*/
@Test
public void step1_CreateWithInvalidParent() {
if (skipTest) return;
if (skipTest)
return;
Context newContext = new ContextImpl(contextName);
newContext.setParent(new ContextImpl("DoNotExist"));
try {
Response create = target("context").request()
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
Status.BAD_REQUEST.getStatusCode(), create.getStatus());
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
Status.BAD_REQUEST.getStatusCode(), create.getStatus());
} catch (JsonProcessingException e) {
assertFalse("Failed to marshal the context.", false);
}
}
}
}