Search in sources :

Example 51 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class PostgreSQLGlobalCodeNodeCommentTests method deleteGlobalCodeNodeComment6.

/**
 * This test checks if the delete of a comment in a series of comments works if the comment is a
 * comment in the middle.
 *
 * <pre>
 * Comment 1:      Comment 1:
 * Comment 2:  ->
 * Comment 3:      Comment 3:
 * </pre>
 */
@Test
public void deleteGlobalCodeNodeComment6() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getGlobalCodeNodeComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String comment1String = " Comment 1: ";
    final int comment1Id = getProvider().appendGlobalCodeNodeComment(codeNode, comment1String, user.getUserId());
    final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
    final String comment2String = " Comment 2: ";
    final int comment2Id = getProvider().appendGlobalCodeNodeComment(codeNode, comment2String, user.getUserId());
    final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
    final String comment3String = " Comment 3: ";
    final int comment3Id = getProvider().appendGlobalCodeNodeComment(codeNode, comment3String, user.getUserId());
    final IComment comment3 = new CComment(comment3Id, user, comment2, comment3String);
    final ArrayList<IComment> commentsBeforeDelete = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsBeforeDelete);
    assertEquals(storedComments.size() + 3, commentsBeforeDelete.size());
    assertTrue(commentsBeforeDelete.contains(comment1));
    assertTrue(commentsBeforeDelete.contains(comment2));
    assertTrue(commentsBeforeDelete.contains(comment3));
    assertEquals(comment3, Iterables.getLast(commentsBeforeDelete));
    assertEquals(comment2, commentsBeforeDelete.get(commentsBeforeDelete.size() - 2));
    assertEquals(comment1, commentsBeforeDelete.get(commentsBeforeDelete.size() - 3));
    getProvider().deleteGlobalCodeNodeComment(codeNode, comment2Id, user.getUserId());
    final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment2Id);
    assertNotNull(commentsAfterDelete1);
    assertTrue(commentsAfterDelete1.isEmpty());
    final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsAfterDelete2);
    assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
    final IComment comment3AfterDelete = new CComment(comment3Id, user, comment1, comment3String);
    assertTrue(commentsAfterDelete2.contains(comment3AfterDelete));
    assertTrue(commentsAfterDelete2.contains(comment1));
    assertEquals(comment3AfterDelete, Iterables.getLast(commentsAfterDelete2));
    assertEquals(comment1, commentsAfterDelete2.get(commentsAfterDelete2.size() - 2));
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 52 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class PostgreSQLGlobalCodeNodeCommentTests method appendGlobalCodeNodeComment5.

@Test
public void appendGlobalCodeNodeComment5() throws CouldntLoadDataException, CouldntSaveDataException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getGlobalCodeNodeComment();
    final int numberOfComments = storedComments.size();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String firstCommentString = " PASS GLOBAL CODE NODE COMMENT 1 ";
    final int firstCommentId = getProvider().appendGlobalCodeNodeComment(codeNode, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
    final String secondCommentString = " PASS GLOBAL CODE NODE COMMENT 2 ";
    final int secondCommentId = getProvider().appendGlobalCodeNodeComment(codeNode, secondCommentString, user.getUserId());
    final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(numberOfComments + 2, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    assertTrue(commentsFromDatabase.contains(secondComment));
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 53 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class PostgreSQLGlobalCodeNodeCommentTests method deleteGlobalCodeNodeComment5.

/**
 * This test checks if the delete of a comment in a series of comments works if the comment is the
 * last comment.
 *
 * <pre>
 * Comment 1:      Comment 1:
 * Comment 2:  ->  Comment 2:
 * Comment 3:
 * </pre>
 */
@Test
public void deleteGlobalCodeNodeComment5() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getGlobalCodeNodeComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String comment1String = " Comment 1: ";
    final int comment1Id = getProvider().appendGlobalCodeNodeComment(codeNode, comment1String, user.getUserId());
    final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
    final String comment2String = " Comment 2: ";
    final int comment2Id = getProvider().appendGlobalCodeNodeComment(codeNode, comment2String, user.getUserId());
    final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
    final String comment3String = " Comment 3: ";
    final int comment3Id = getProvider().appendGlobalCodeNodeComment(codeNode, comment3String, user.getUserId());
    final IComment comment3 = new CComment(comment3Id, user, comment2, comment3String);
    final ArrayList<IComment> commentsBeforeDelete = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsBeforeDelete);
    assertEquals(storedComments.size() + 3, commentsBeforeDelete.size());
    assertTrue(commentsBeforeDelete.contains(comment1));
    assertTrue(commentsBeforeDelete.contains(comment2));
    assertTrue(commentsBeforeDelete.contains(comment3));
    assertEquals(comment3, Iterables.getLast(commentsBeforeDelete));
    assertEquals(comment2, commentsBeforeDelete.get(commentsBeforeDelete.size() - 2));
    assertEquals(comment1, commentsBeforeDelete.get(commentsBeforeDelete.size() - 3));
    getProvider().deleteGlobalCodeNodeComment(codeNode, comment3Id, user.getUserId());
    final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsAfterDelete1);
    assertTrue(commentsAfterDelete1.isEmpty());
    final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment2Id);
    assertNotNull(commentsAfterDelete2);
    assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
    assertTrue(commentsAfterDelete2.contains(comment2));
    assertTrue(commentsAfterDelete2.contains(comment1));
    assertEquals(comment2, Iterables.getLast(commentsAfterDelete2));
    assertEquals(comment1, commentsAfterDelete2.get(commentsAfterDelete2.size() - 2));
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 54 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class PostgreSQLGlobalCodeNodeCommentTests method editGlobalCodeNodeComment6.

@Test(expected = CouldntSaveDataException.class)
public void editGlobalCodeNodeComment6() throws CouldntLoadDataException, CouldntSaveDataException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = codeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : codeNode.getComments().getGlobalCodeNodeComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String beforeEditCommentString = " EDIT GLOBAL COMMENT BEFORE EDIT ";
    final int editedCommentId = getProvider().appendGlobalCodeNodeComment(codeNode, beforeEditCommentString, user.getUserId());
    final IComment commentBeforeEdit = new CComment(editedCommentId, user, lastComment, beforeEditCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(editedCommentId);
    assertNotNull(commentsFromDatabase);
    assertTrue(commentsFromDatabase.contains(commentBeforeEdit));
    assertEquals(storedComments.size() + 1, commentsFromDatabase.size());
    final IUser wrongUser = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    getProvider().editGlobalCodeNodeComment(codeNode, editedCommentId, wrongUser.getUserId(), " FAIL ");
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 55 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class PostgreSQLGlobalInstructionCommentTests method deleteGlobalInstructionComment8.

/**
 * This test checks if the delete of a comment in a series of comments works if the comment is the
 * first comment.
 *
 * <pre>
 * Comment 1:
 * Comment 2:  ->  Comment 2:
 * Comment 3:      Comment 3:
 * </pre>
 */
@Test
public void deleteGlobalInstructionComment8() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = instruction.getGlobalComment() == null ? new ArrayList<IComment>() : instruction.getGlobalComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String comment1String = " Comment 1: ";
    final int comment1Id = getProvider().appendGlobalInstructionComment(instruction, comment1String, user.getUserId());
    final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
    final String comment2String = " Comment 2: ";
    final int comment2Id = getProvider().appendGlobalInstructionComment(instruction, comment2String, user.getUserId());
    final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
    final String comment3String = " Comment 3: ";
    final int comment3Id = getProvider().appendGlobalInstructionComment(instruction, comment3String, user.getUserId());
    final IComment comment3 = new CComment(comment3Id, user, comment2, comment3String);
    final ArrayList<IComment> commentsBeforeDelete = getProvider().loadCommentById(comment3Id);
    assertNotNull(commentsBeforeDelete);
    assertEquals(storedComments.size() + 3, commentsBeforeDelete.size());
    assertTrue(commentsBeforeDelete.contains(comment1));
    assertTrue(commentsBeforeDelete.contains(comment2));
    assertTrue(commentsBeforeDelete.contains(comment3));
    assertEquals(comment3, Iterables.getLast(commentsBeforeDelete));
    assertEquals(comment2, commentsBeforeDelete.get(commentsBeforeDelete.size() - 2));
    assertEquals(comment1, commentsBeforeDelete.get(commentsBeforeDelete.size() - 3));
    getProvider().deleteGlobalInstructionComment(instruction, comment1Id, user.getUserId());
    final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment1Id);
    assertNotNull(commentsAfterDelete1);
    assertTrue(commentsAfterDelete1.isEmpty());
    final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment3Id);
    final IComment comment2AfterDelete = new CComment(comment2Id, user, lastComment, comment2String);
    final IComment comment3AfterDelete = new CComment(comment3Id, user, comment2AfterDelete, comment3String);
    assertNotNull(commentsAfterDelete2);
    assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
    assertTrue(commentsAfterDelete2.contains(comment3AfterDelete));
    assertTrue(commentsAfterDelete2.contains(comment2AfterDelete));
    assertEquals(comment3AfterDelete, Iterables.getLast(commentsAfterDelete2));
    assertEquals(comment2AfterDelete, commentsAfterDelete2.get(commentsAfterDelete2.size() - 2));
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Aggregations

IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)120 Test (org.junit.Test)109 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)99 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)97 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)96 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)95 CUserManager (com.google.security.zynamics.binnavi.Gui.Users.CUserManager)11 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)9 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)8 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)6 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)4 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)3 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 ArrayList (java.util.ArrayList)3 CUser (com.google.security.zynamics.binnavi.Gui.Users.CUser)2 IUserManagerListener (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener)2