Skip to content
Snippets Groups Projects
Commit 54b455a2 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

SSDM-11859 : openBIS core : reverting a deletion via coreUI or ELN is very inefficient - fix tests

parent 60f26685
No related branches found
No related tags found
No related merge requests found
...@@ -57,7 +57,7 @@ public abstract class DeletionTechIdCollectionPredicateSystemTest extends Common ...@@ -57,7 +57,7 @@ public abstract class DeletionTechIdCollectionPredicateSystemTest extends Common
{ {
for (TechId object : objects) for (TechId object : objects)
{ {
if (object != null) if (object != null && !object.equals(this.createNonexistentObject(param)))
{ {
getCommonService().untrash(object.getId()); getCommonService().untrash(object.getId());
} }
...@@ -70,31 +70,31 @@ public abstract class DeletionTechIdCollectionPredicateSystemTest extends Common ...@@ -70,31 +70,31 @@ public abstract class DeletionTechIdCollectionPredicateSystemTest extends Common
protected CommonPredicateSystemTestAssertions<TechId> getAssertions() protected CommonPredicateSystemTestAssertions<TechId> getAssertions()
{ {
return new CommonPredicateSystemTestAssertionsDelegate<TechId>(super.getAssertions()) return new CommonPredicateSystemTestAssertionsDelegate<TechId>(super.getAssertions())
{
@Override
public void assertWithNullObject(ProjectAuthorizationUser user, Throwable t, Object param)
{ {
@Override if (user.isDisabledProjectUser())
public void assertWithNullObject(ProjectAuthorizationUser user, Throwable t, Object param)
{ {
if (user.isDisabledProjectUser()) assertAuthorizationFailureExceptionThatNoRoles(t);
{ } else
assertAuthorizationFailureExceptionThatNoRoles(t); {
} else assertException(t, NullPointerException.class, null);
{
assertException(t, NullPointerException.class, null);
}
} }
}
@Override @Override
public void assertWithNullCollection(ProjectAuthorizationUser user, Throwable t, Object param) public void assertWithNullCollection(ProjectAuthorizationUser user, Throwable t, Object param)
{
if (user.isDisabledProjectUser())
{ {
if (user.isDisabledProjectUser()) assertAuthorizationFailureExceptionThatNoRoles(t);
{ } else
assertAuthorizationFailureExceptionThatNoRoles(t); {
} else assertException(t, UserFailureException.class, "No deletion technical id specified.");
{
assertException(t, UserFailureException.class, "No deletion technical id specified.");
}
} }
}; }
};
} }
} }
\ No newline at end of file
...@@ -57,7 +57,7 @@ public abstract class RevertDeletionPredicateSystemTest extends CommonPredicateS ...@@ -57,7 +57,7 @@ public abstract class RevertDeletionPredicateSystemTest extends CommonPredicateS
{ {
for (TechId object : objects) for (TechId object : objects)
{ {
if (object != null) if (object != null && !object.equals(this.createNonexistentObject(param)))
{ {
getCommonService().untrash(object.getId()); getCommonService().untrash(object.getId());
} }
...@@ -70,35 +70,35 @@ public abstract class RevertDeletionPredicateSystemTest extends CommonPredicateS ...@@ -70,35 +70,35 @@ public abstract class RevertDeletionPredicateSystemTest extends CommonPredicateS
protected CommonPredicateSystemTestAssertions<TechId> getAssertions() protected CommonPredicateSystemTestAssertions<TechId> getAssertions()
{ {
return new CommonPredicateSystemTestAssertionsDelegate<TechId>(super.getAssertions()) return new CommonPredicateSystemTestAssertionsDelegate<TechId>(super.getAssertions())
{
@Override
public void assertWithNullObject(ProjectAuthorizationUser user, Throwable t, Object param)
{ {
@Override if (user.isDisabledProjectUser())
public void assertWithNullObject(ProjectAuthorizationUser user, Throwable t, Object param)
{ {
if (user.isDisabledProjectUser()) assertAuthorizationFailureExceptionThatNoRoles(t);
{ } else if (user.isInstanceUser())
assertAuthorizationFailureExceptionThatNoRoles(t); {
} else if (user.isInstanceUser()) assertNoException(t);
{ } else
assertNoException(t); {
} else assertException(t, NullPointerException.class, null);
{
assertException(t, NullPointerException.class, null);
}
} }
}
@Override @Override
public void assertWithNullCollection(ProjectAuthorizationUser user, Throwable t, Object param) public void assertWithNullCollection(ProjectAuthorizationUser user, Throwable t, Object param)
{
if (user.isDisabledProjectUser())
{ {
if (user.isDisabledProjectUser()) assertAuthorizationFailureExceptionThatNoRoles(t);
{ } else
assertAuthorizationFailureExceptionThatNoRoles(t); {
} else assertException(t, UserFailureException.class, "No revert deletion technical id specified.");
{
assertException(t, UserFailureException.class, "No revert deletion technical id specified.");
}
} }
}
}; };
} }
} }
\ No newline at end of file
...@@ -57,7 +57,7 @@ public abstract class V3DeletionIdPredicateSystemTest extends CommonPredicateSys ...@@ -57,7 +57,7 @@ public abstract class V3DeletionIdPredicateSystemTest extends CommonPredicateSys
{ {
for (IDeletionId object : objects) for (IDeletionId object : objects)
{ {
if (object != null) if (object != null && !object.equals(this.createNonexistentObject(param)))
{ {
getCommonService().untrash(((DeletionTechId) object).getTechId()); getCommonService().untrash(((DeletionTechId) object).getTechId());
} }
...@@ -70,32 +70,32 @@ public abstract class V3DeletionIdPredicateSystemTest extends CommonPredicateSys ...@@ -70,32 +70,32 @@ public abstract class V3DeletionIdPredicateSystemTest extends CommonPredicateSys
protected CommonPredicateSystemTestAssertions<IDeletionId> getAssertions() protected CommonPredicateSystemTestAssertions<IDeletionId> getAssertions()
{ {
return new CommonPredicateSystemTestAssertionsDelegate<IDeletionId>(super.getAssertions()) return new CommonPredicateSystemTestAssertionsDelegate<IDeletionId>(super.getAssertions())
{
@Override
public void assertWithNullObject(ProjectAuthorizationUser user, Throwable t, Object param)
{ {
@Override if (user.isDisabledProjectUser())
public void assertWithNullObject(ProjectAuthorizationUser user, Throwable t, Object param)
{ {
if (user.isDisabledProjectUser()) assertAuthorizationFailureExceptionThatNoRoles(t);
{ } else
assertAuthorizationFailureExceptionThatNoRoles(t); {
} else assertException(t, NullPointerException.class, null);
{
assertException(t, NullPointerException.class, null);
}
} }
}
@Override @Override
public void assertWithNullCollection(ProjectAuthorizationUser user, Throwable t, Object param) public void assertWithNullCollection(ProjectAuthorizationUser user, Throwable t, Object param)
{
if (user.isDisabledProjectUser())
{ {
if (user.isDisabledProjectUser()) assertAuthorizationFailureExceptionThatNoRoles(t);
{ } else
assertAuthorizationFailureExceptionThatNoRoles(t); {
} else assertException(t, UserFailureException.class, "No v3 deletion id object specified.");
{
assertException(t, UserFailureException.class, "No v3 deletion id object specified.");
}
} }
}
}; };
} }
} }
\ No newline at end of file
...@@ -37,6 +37,7 @@ public class ServerInterfaceRegressionTest extends AnnotationAppliedTestCase ...@@ -37,6 +37,7 @@ public class ServerInterfaceRegressionTest extends AnnotationAppliedTestCase
{ {
List<String> exemptMethods = new ArrayList<String>(); List<String> exemptMethods = new ArrayList<String>();
exemptMethods.add("getDisabledText"); exemptMethods.add("getDisabledText");
exemptMethods.add("revertDeletions");
assertMandatoryMethodAnnotations(ICommonServer.class, CommonServer.class, assertMandatoryMethodAnnotations(ICommonServer.class, CommonServer.class,
"getLastModificationState: Transactional\n", exemptMethods); "getLastModificationState: Transactional\n", exemptMethods);
......
...@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -33,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import ch.ethz.sis.openbis.generic.asapi.v3.exceptions.UnauthorizedObjectAccessException;
import ch.systemsx.cisd.common.exceptions.AuthorizationFailureException; import ch.systemsx.cisd.common.exceptions.AuthorizationFailureException;
import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.common.test.AssertionUtil; import ch.systemsx.cisd.common.test.AssertionUtil;
...@@ -76,7 +77,6 @@ import ch.systemsx.cisd.openbis.systemtest.PropertyHistory; ...@@ -76,7 +77,6 @@ import ch.systemsx.cisd.openbis.systemtest.PropertyHistory;
import ch.systemsx.cisd.openbis.systemtest.SystemTestCase; import ch.systemsx.cisd.openbis.systemtest.SystemTestCase;
import ch.systemsx.cisd.openbis.systemtest.authorization.ProjectAuthorizationUser; import ch.systemsx.cisd.openbis.systemtest.authorization.ProjectAuthorizationUser;
import ch.systemsx.cisd.openbis.util.GeneralInformationServiceUtil; import ch.systemsx.cisd.openbis.util.GeneralInformationServiceUtil;
import junit.framework.Assert; import junit.framework.Assert;
/** /**
...@@ -117,7 +117,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -117,7 +117,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
localCommonServer.assignPropertyType(sessionToken, new NewETPTAssignment(EntityKind.SAMPLE, localCommonServer.assignPropertyType(sessionToken, new NewETPTAssignment(EntityKind.SAMPLE,
"GENDER", "CELL_PLATE", false, null, null, 1L, false, false, null, true, false)); "GENDER", "CELL_PLATE", false, null, null, 1L, false, false, null, true, false));
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), " assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]", + "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]",
localCommonServer.getSampleInfo(sessionToken, id).getParent()); localCommonServer.getSampleInfo(sessionToken, id).getParent());
HashMap<String, String> properties = new HashMap<String, String>(); HashMap<String, String> properties = new HashMap<String, String>();
properties.put("SIZE", "42"); properties.put("SIZE", "42");
...@@ -132,7 +132,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -132,7 +132,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
assertProperties("[ANY_MATERIAL: 1 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), " assertProperties("[ANY_MATERIAL: 1 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, DESCRIPTION: hello example, GENDER: FEMALE, " + "COMMENT: extremely simple stuff, DESCRIPTION: hello example, GENDER: FEMALE, "
+ "ORGANISM: DOG, SIZE: 42]", localCommonServer.getSampleInfo(sessionToken, id) + "ORGANISM: DOG, SIZE: 42]", localCommonServer.getSampleInfo(sessionToken, id)
.getParent()); .getParent());
List<PropertyHistory> history = getSamplePropertiesHistory(id.getId()); List<PropertyHistory> history = getSamplePropertiesHistory(id.getId());
assertEquals( assertEquals(
...@@ -147,7 +147,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -147,7 +147,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
TechId id = new TechId(1043L); TechId id = new TechId(1043L);
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent(); ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), " assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]", + "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]",
sampleBefore); sampleBefore);
NewETPTAssignment newETPTAssignment = new NewETPTAssignment(); NewETPTAssignment newETPTAssignment = new NewETPTAssignment();
newETPTAssignment.setEntityKind(EntityKind.SAMPLE); newETPTAssignment.setEntityKind(EntityKind.SAMPLE);
...@@ -164,7 +164,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -164,7 +164,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
Session hibernateSession = getHibernateSession(); Session hibernateSession = getHibernateSession();
hibernateSession.clear(); hibernateSession.clear();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), " assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, GENDER: FEMALE, ORGANISM: GORILLA, SIZE: 321]", + "COMMENT: extremely simple stuff, GENDER: FEMALE, ORGANISM: GORILLA, SIZE: 321]",
localCommonServer.getSampleInfo(sessionToken, id).getParent()); localCommonServer.getSampleInfo(sessionToken, id).getParent());
List<Vocabulary> listVocabularies = generalInformationService.listVocabularies(sessionToken); List<Vocabulary> listVocabularies = generalInformationService.listVocabularies(sessionToken);
...@@ -187,7 +187,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -187,7 +187,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
replacement.setReplacementCode("MALE"); replacement.setReplacementCode("MALE");
localCommonServer.deleteVocabularyTerms(sessionToken, new TechId(genderVocab.getId()), localCommonServer.deleteVocabularyTerms(sessionToken, new TechId(genderVocab.getId()),
Collections.<VocabularyTerm> emptyList(), Arrays.asList(replacement)); Collections.<VocabularyTerm>emptyList(), Arrays.asList(replacement));
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleAfter = localCommonServer.getSampleInfo(sessionToken, id) ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleAfter = localCommonServer.getSampleInfo(sessionToken, id)
.getParent(); .getParent();
...@@ -205,7 +205,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -205,7 +205,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
TechId id = new TechId(1043L); TechId id = new TechId(1043L);
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent(); ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), " assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]", + "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]",
sampleBefore); sampleBefore);
NewETPTAssignment newETPTAssignment = new NewETPTAssignment(); NewETPTAssignment newETPTAssignment = new NewETPTAssignment();
newETPTAssignment.setEntityKind(EntityKind.SAMPLE); newETPTAssignment.setEntityKind(EntityKind.SAMPLE);
...@@ -238,7 +238,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -238,7 +238,7 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
TechId id = new TechId(1043L); TechId id = new TechId(1043L);
ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent(); ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample sampleBefore = localCommonServer.getSampleInfo(sessionToken, id).getParent();
assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), " assertProperties("[ANY_MATERIAL: 2 (GENE), BACTERIUM: BACTERIUM-Y (BACTERIUM), "
+ "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]", + "COMMENT: extremely simple stuff, ORGANISM: GORILLA, SIZE: 321]",
sampleBefore); sampleBefore);
localCommonServer.unassignPropertyType(sessionToken, EntityKind.SAMPLE, "COMMENT", "CELL_PLATE"); localCommonServer.unassignPropertyType(sessionToken, EntityKind.SAMPLE, "COMMENT", "CELL_PLATE");
getHibernateSession().clear(); getHibernateSession().clear();
...@@ -1025,8 +1025,15 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase ...@@ -1025,8 +1025,15 @@ public class GeneralInformationChangingServiceTest extends SystemTestCase
{ {
generalInformationChangingService.revertDeletions(session, Arrays.asList(deletion.getId())); generalInformationChangingService.revertDeletions(session, Arrays.asList(deletion.getId()));
fail(); fail();
} catch (AuthorizationFailureException e) } catch (UserFailureException e)
{ {
if (e.getCause() instanceof AuthorizationFailureException || e.getCause() instanceof UnauthorizedObjectAccessException)
{
// expected
} else
{
throw e;
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment