use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLLocalInstructionCommentTests method deleteLocalInstructionComment5.
@Test
public void deleteLocalInstructionComment5() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
final List<IComment> comments = codeNode.getComments().getLocalInstructionComment(instruction) == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalInstructionComment(instruction);
final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
final String commentString = " TEST DELETE LOCAL INSTRUCTION COMMENT ";
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final int commentId = getProvider().appendLocalInstructionComment(codeNode, instruction, commentString, user.getUserId());
final IComment newComment = new CComment(commentId, user, lastComment, commentString);
final ArrayList<IComment> storedComments = getProvider().loadCommentById(commentId);
assertNotNull(storedComments);
assertEquals(comments.size() + 1, storedComments.size());
assertEquals(newComment, storedComments.get(storedComments.size() - 1));
getProvider().deleteLocalInstructionComment(codeNode, instruction, commentId, newComment.getUser().getUserId());
final ArrayList<IComment> commentsAfterDelete = getProvider().loadCommentById(commentId);
assertNotNull(commentsAfterDelete);
assertTrue(commentsAfterDelete.isEmpty());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLLocalInstructionCommentTests method deleteLocalInstructionComment8.
/**
* 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 deleteLocalInstructionComment8() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = codeNode.getComments().getLocalInstructionComment(instruction) == null ? new ArrayList<IComment>() : codeNode.getComments().getLocalInstructionComment(instruction);
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String comment1String = " Comment 1: ";
final int comment1Id = getProvider().appendLocalInstructionComment(codeNode, instruction, comment1String, user.getUserId());
final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
final String comment2String = " Comment 2: ";
final int comment2Id = getProvider().appendLocalInstructionComment(codeNode, instruction, comment2String, user.getUserId());
final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
final String comment3String = " Comment 3: ";
final int comment3Id = getProvider().appendLocalInstructionComment(codeNode, 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().deleteLocalInstructionComment(codeNode, 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));
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLSectionCommentTests method deleteSectionComment7.
/**
* 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 deleteSectionComment7() throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = section.getComments() == null ? new ArrayList<IComment>() : section.getComments();
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String comment1String = " Comment 1: ";
final int comment1Id = getProvider().appendSectionComment(section.getModule().getConfiguration().getId(), section.getId(), comment1String, user.getUserId());
final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
final String comment2String = " Comment 2: ";
final int comment2Id = getProvider().appendSectionComment(section.getModule().getConfiguration().getId(), section.getId(), comment2String, user.getUserId());
final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
final String comment3String = " Comment 3: ";
final int comment3Id = getProvider().appendSectionComment(section.getModule().getConfiguration().getId(), section.getId(), 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().deleteSectionComment(section.getModule().getConfiguration().getId(), section.getId(), 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));
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLSectionCommentTests method editSectionComment5.
@Test
public void editSectionComment5() throws CouldntSaveDataException, CouldntLoadDataException {
final List<IComment> comments = section.getComments() == null ? new ArrayList<IComment>() : section.getComments();
final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String commentText = " SECTION COMMENT TEST BEFORE EDIT ";
final Integer commentId = getProvider().appendSectionComment(section.getModule().getConfiguration().getId(), section.getId(), commentText, user.getUserId());
final IComment newComment = new CComment(commentId, user, lastComment, commentText);
final ArrayList<IComment> newComments = getProvider().loadCommentById(commentId);
assertNotNull(newComments);
assertEquals(comments.size() + 1, newComments.size());
assertEquals(newComment, newComments.get(newComments.size() - 1));
final String commentAfterEdit = " Section COMMENT TEST AFTER EDIT ";
getProvider().editSectionComment(section.getModule().getConfiguration().getId(), section.getId(), commentId, user.getUserId(), commentAfterEdit);
final ArrayList<IComment> commentsAfterEdit = getProvider().loadCommentById(commentId);
assertEquals(commentAfterEdit, Iterables.getLast(commentsAfterEdit).getComment());
assertEquals(commentsAfterEdit.size(), newComments.size());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLSectionCommentTests method editSectionComment6.
@Test(expected = CouldntSaveDataException.class)
public void editSectionComment6() throws CouldntSaveDataException, CouldntLoadDataException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = section.getComments() == null ? new ArrayList<IComment>() : section.getComments();
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String beforeEditCommentString = " EDIT COMMENT BEFORE EDIT ";
final int editedCommentId = getProvider().appendSectionComment(section.getModule().getConfiguration().getId(), section.getId(), 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().editSectionComment(section.getModule().getConfiguration().getId(), section.getId(), editedCommentId, wrongUser.getUserId(), " FAIL ");
}
Aggregations