Fixed tests
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-context-client@171262 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d924a790a2
commit
a8a9b35e98
|
@ -31,7 +31,7 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
|
||||
protected ResourceRegistryContextClient resourceRegistryContextClient;
|
||||
|
||||
public ResourceRegistryContextClientTest(){
|
||||
public ResourceRegistryContextClientTest() {
|
||||
resourceRegistryContextClient = ResourceRegistryContextClientFactory.create();
|
||||
}
|
||||
|
||||
|
@ -43,47 +43,47 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
String user = org.gcube.informationsystem.model.embedded.Header.UNKNOWN_USER;
|
||||
try {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
if(token!=null) {
|
||||
if(token != null) {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
if (authorizationEntry != null) {
|
||||
if(authorizationEntry != null) {
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
String clientId = clientInfo.getId();
|
||||
if (clientId != null && clientId.compareTo("") != 0) {
|
||||
if(clientId != null && clientId.compareTo("") != 0) {
|
||||
user = clientId;
|
||||
} else {
|
||||
throw new Exception("Username null or empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
logger.error("Unable to retrieve user. {} will be used", user);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void checkHeader(ER er, UUID uuid, boolean create) {
|
||||
Assert.assertTrue(er.getHeader()!=null);
|
||||
Assert.assertTrue(er.getHeader().getUUID()!=null);
|
||||
Assert.assertTrue(er.getHeader() != null);
|
||||
Assert.assertTrue(er.getHeader().getUUID() != null);
|
||||
|
||||
if(uuid!=null) {
|
||||
Assert.assertTrue(er.getHeader().getUUID().compareTo(uuid)==0);
|
||||
if(uuid != null) {
|
||||
Assert.assertTrue(er.getHeader().getUUID().compareTo(uuid) == 0);
|
||||
}
|
||||
|
||||
String user = getUser();
|
||||
Assert.assertTrue(er.getHeader().getModifiedBy().compareTo(user)==0);
|
||||
String user = getUser();
|
||||
Assert.assertTrue(er.getHeader().getModifiedBy().compareTo(user) == 0);
|
||||
|
||||
if(create){
|
||||
Assert.assertTrue(er.getHeader().getCreator().compareTo(user)==0);
|
||||
Assert.assertTrue(er.getHeader().getCreationTime().compareTo(er.getHeader().getLastUpdateTime())==0);
|
||||
}else {
|
||||
if(create) {
|
||||
Assert.assertTrue(er.getHeader().getCreator().compareTo(user) == 0);
|
||||
Assert.assertTrue(er.getHeader().getCreationTime().compareTo(er.getHeader().getLastUpdateTime()) == 0);
|
||||
} else {
|
||||
Assert.assertTrue(er.getHeader().getCreationTime().before(er.getHeader().getLastUpdateTime()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void assertions(Context pre, Context post, boolean checkParent, boolean create) {
|
||||
if (checkParent) {
|
||||
if (pre.getHeader() != null) {
|
||||
if(checkParent) {
|
||||
if(pre.getHeader() != null) {
|
||||
checkHeader(post, pre.getHeader().getUUID(), create);
|
||||
} else {
|
||||
checkHeader(post, null, create);
|
||||
|
@ -91,7 +91,7 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
}
|
||||
|
||||
Assert.assertTrue(pre.getName().compareTo(post.getName()) == 0);
|
||||
if (checkParent && pre.getParent() != null && post.getParent() != null) {
|
||||
if(checkParent && pre.getParent() != null && post.getParent() != null) {
|
||||
Context preParent = pre.getParent().getSource();
|
||||
Context postParent = post.getParent().getSource();
|
||||
assertions(preParent, postParent, false, false);
|
||||
|
@ -100,9 +100,9 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
|
||||
protected Context read(UUID uuid) throws ResourceRegistryException, IOException {
|
||||
Context c = resourceRegistryContextClient.read(uuid);
|
||||
Assert.assertTrue(c.getHeader()!=null);
|
||||
Assert.assertTrue(c.getHeader().getUUID()!=null);
|
||||
Assert.assertTrue(c.getHeader().getUUID().compareTo(uuid)==0);
|
||||
Assert.assertTrue(c.getHeader() != null);
|
||||
Assert.assertTrue(c.getHeader().getUUID() != null);
|
||||
Assert.assertTrue(c.getHeader().getUUID().compareTo(uuid) == 0);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
try {
|
||||
Context c = create(context);
|
||||
throw new RuntimeException(ISMapper.marshal(c) + " was created successfully. This is not what we expected");
|
||||
} catch (ContextAlreadyPresentException e) {
|
||||
} catch(ContextAlreadyPresentException e) {
|
||||
logger.debug("As expected {} cannot be created.", ISMapper.marshal(context));
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
try {
|
||||
Context c = update(context);
|
||||
throw new RuntimeException(ISMapper.marshal(c) + " was updated successfully. This is not what we expected");
|
||||
} catch (ContextAlreadyPresentException e) {
|
||||
} catch(ContextAlreadyPresentException e) {
|
||||
logger.debug("As expected {} cannot be updated.", ISMapper.marshal(context));
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
try {
|
||||
delete(context);
|
||||
throw new RuntimeException(contextString + " was deleted successfully. This is not what we expected");
|
||||
} catch (ContextException e) {
|
||||
} catch(ContextException e) {
|
||||
logger.debug("As expected {} cannot be deleted.", contextString);
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,6 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
logger.debug(ISMapper.marshal(gcube));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void completeTest() throws Exception {
|
||||
Context contextA1 = new ContextImpl(CTX_NAME_A);
|
||||
|
@ -337,7 +336,7 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
|
||||
try {
|
||||
delete(contextA5);
|
||||
} catch (ContextNotFoundException e) {
|
||||
} catch(ContextNotFoundException e) {
|
||||
logger.debug("The context with uuid {} was not found. (Was already deleted)",
|
||||
contextA5.getHeader().getUUID());
|
||||
}
|
||||
|
@ -365,6 +364,29 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDissertationContext() throws Exception {
|
||||
Context d4science = new ContextImpl("d4science");
|
||||
d4science = create(d4science);
|
||||
|
||||
Context soBigData = new ContextImpl("SoBigData");
|
||||
soBigData.setParent(d4science);
|
||||
soBigData = create(soBigData);
|
||||
|
||||
Context tagMe = new ContextImpl("TagMe");
|
||||
tagMe.setParent(soBigData);
|
||||
tagMe = create(tagMe);
|
||||
|
||||
Context blueBRIDGE = new ContextImpl("BlueBRIDGE");
|
||||
blueBRIDGE.setParent(d4science);
|
||||
blueBRIDGE = create(blueBRIDGE);
|
||||
|
||||
Context biodiversityLab = new ContextImpl("Biodiversity Lab");
|
||||
biodiversityLab.setParent(blueBRIDGE);
|
||||
biodiversityLab = create(biodiversityLab);
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void createDevContext() throws Exception {
|
||||
Context gcube = new ContextImpl("gcube");
|
||||
|
@ -417,11 +439,11 @@ public class ResourceRegistryContextClientTest extends ScopedTest {
|
|||
UUID d4ResearchUUID = UUID.fromString("8b926d1c-4460-4d7a-adab-c75ad2770a21");
|
||||
UUID farmUUID = UUID.fromString("dbafdb3e-f7f9-4039-ad1c-3432c041f53c");
|
||||
|
||||
Map<String, UUID> contexts = new HashMap<>();
|
||||
Map<String,UUID> contexts = new HashMap<>();
|
||||
contexts.put("ICES_FIACO2017", d4ResearchUUID);
|
||||
contexts.put("D4STeam", farmUUID);
|
||||
|
||||
for (String contextName : contexts.keySet()) {
|
||||
for(String contextName : contexts.keySet()) {
|
||||
Context parent = read(contexts.get(contextName));
|
||||
Context context = new ContextImpl(contextName);
|
||||
context.setParent(parent);
|
||||
|
|
Loading…
Reference in New Issue