Fixed test for non active contexts
This commit is contained in:
parent
4a557031d6
commit
26aa96ae37
|
@ -13,9 +13,13 @@ import org.gcube.informationsystem.serialization.ElementMapper;
|
|||
import org.gcube.informationsystem.tree.Tree;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ContextStateTest extends ContextManagementTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextManagementTest.class);
|
||||
|
||||
public <R extends Resource> ResourceManagement getResourceManagement(R r) throws Exception {
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(r.getTypeName());
|
||||
|
@ -26,7 +30,7 @@ public class ContextStateTest extends ContextManagementTest {
|
|||
return resourceManagement;
|
||||
}
|
||||
|
||||
@Test(expected = ForbiddenException.class)
|
||||
@Test()
|
||||
public void testNonActiveContext() throws Exception {
|
||||
ContextTest.setContextByName(GCUBE);
|
||||
|
||||
|
@ -46,7 +50,13 @@ public class ContextStateTest extends ContextManagementTest {
|
|||
return;
|
||||
}
|
||||
|
||||
FakeSecretUtility.setFakeSecret("noroles.json", rootContext+"/"+contextA1.getName());
|
||||
String newContext = rootContext+"/"+contextA1.getName();
|
||||
|
||||
boolean resourceCreated = false;
|
||||
EService createdEservice = null;
|
||||
|
||||
try {
|
||||
FakeSecretUtility.setFakeSecret("noroles.json", newContext);
|
||||
|
||||
EService eService = ERManagementTest.instantiateValidEService();
|
||||
ResourceManagement resourceManagement = getResourceManagement(eService);
|
||||
|
@ -54,15 +64,152 @@ public class ContextStateTest extends ContextManagementTest {
|
|||
String json = null;
|
||||
try {
|
||||
json = resourceManagement.create();
|
||||
}catch (Exception e) {
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if(json!=null) {
|
||||
resourceManagement.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FakeSecretUtility.setFakeSecret("infrastructure-manager.json", newContext);
|
||||
|
||||
try {
|
||||
json = null;
|
||||
resourceManagement = getResourceManagement(eService);
|
||||
json = resourceManagement.create();
|
||||
resourceCreated = true;
|
||||
} catch (Exception e) {
|
||||
if(json != null) {
|
||||
resourceManagement.delete();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
createdEservice = ElementMapper.unmarshal(EService.class, json);
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.read();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.update();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
FakeSecretUtility.setFakeSecret("noroles.json", newContext);
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.read();
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.update();
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
resourceManagement.delete();
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
FakeSecretUtility.setFakeSecret("is-manager.json", newContext);
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.read();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.update();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
FakeSecretUtility.setFakeSecret("noroles.json", newContext);
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.read();
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
json = resourceManagement.update();
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
resourceManagement.delete();
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
FakeSecretUtility.setFakeSecret("is-manager.json", newContext);
|
||||
|
||||
try {
|
||||
resourceManagement = getResourceManagement(createdEservice);
|
||||
resourceManagement.delete();
|
||||
resourceCreated = false;
|
||||
} catch (ForbiddenException e) {
|
||||
logger.info("As expected the no role user cannot operate in non active context", e);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
} finally {
|
||||
ContextTest.setContextByName(newContext);
|
||||
|
||||
if(resourceCreated) {
|
||||
ResourceManagement resourceManagement = getResourceManagement(createdEservice);
|
||||
try {
|
||||
resourceManagement.delete();
|
||||
}catch (Exception e) {
|
||||
logger.error("Unable to delete resource {}", createdEservice);
|
||||
}
|
||||
}
|
||||
|
||||
ContextTest.setContextByName(rootContext);
|
||||
|
||||
delete(contextA1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue