-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since event subject traversal didn't filter its nodes for valid types, deletion of a subject would result in the last event link node being put in the result set, which caused a crash when we tried to serialize it.
- Loading branch information
Showing
2 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ehri-frames/src/test/java/eu/ehri/project/models/events/SystemEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package eu.ehri.project.models.events; | ||
|
||
import eu.ehri.project.definitions.EventTypes; | ||
import eu.ehri.project.models.UserProfile; | ||
import eu.ehri.project.models.base.Actioner; | ||
import eu.ehri.project.persistence.ActionManager; | ||
import eu.ehri.project.persistence.Bundle; | ||
import eu.ehri.project.persistence.BundleDAO; | ||
import eu.ehri.project.persistence.Serializer; | ||
import eu.ehri.project.test.AbstractFixtureTest; | ||
import eu.ehri.project.test.TestData; | ||
import org.junit.Test; | ||
import org.neo4j.helpers.collection.Iterables; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Mike Bryant (http://github.com/mikesname) | ||
*/ | ||
public class SystemEventTest extends AbstractFixtureTest { | ||
@Test | ||
public void testGetSubjects() throws Exception { | ||
ActionManager am = new ActionManager(graph); | ||
BundleDAO dao = new BundleDAO(graph); | ||
Serializer serializer = new Serializer(graph); | ||
// Create a user and log it | ||
Bundle userBundle = Bundle.fromData(TestData.getTestUserBundle()); | ||
UserProfile user = dao.create(userBundle, UserProfile.class); | ||
|
||
SystemEvent first = am.logEvent(user, | ||
graph.frame(validUser.asVertex(), Actioner.class), | ||
EventTypes.creation).getSystemEvent(); | ||
assertEquals(1, Iterables.count(first.getSubjects())); | ||
|
||
// Delete the user and log it | ||
SystemEvent second = am.logEvent(user, | ||
graph.frame(validUser.asVertex(), Actioner.class), | ||
EventTypes.deletion).getSystemEvent(); | ||
dao.delete(serializer.vertexFrameToBundle(user)); | ||
|
||
// First event should now have 0 subjects, since it's | ||
// been deleted. | ||
assertEquals(0, Iterables.count(first.getSubjects())); | ||
} | ||
} |