use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLFunctionCommentTests method deleteFunctionComment4.
@Test
public void deleteFunctionComment4() throws CouldntLoadDataException, CouldntSaveDataException, CouldntDeleteException {
final List<IComment> comments = function.getGlobalComment() == null ? new ArrayList<IComment>() : function.getGlobalComment();
final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
final String commentString = " TEST DELETE FUNCTION COMMENT ";
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final int commentId = getProvider().appendFunctionComment(function, 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().deleteFunctionComment(function, 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 PostgreSQLFunctionCommentTests method appendFunctionComment4.
@Test
public void appendFunctionComment4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
final INaviModule module = getProvider().loadModules().get(0);
module.load();
final INaviFunction function = module.getContent().getFunctionContainer().getFunctions().get(123);
function.load();
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final java.util.List<IComment> storedComments = function.getGlobalComment() == null ? new ArrayList<IComment>() : function.getGlobalComment();
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String firstCommentString = " PASS FUNCTION NODE COMMENT 1 ";
final int firstCommentId = getProvider().appendFunctionComment(function, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
final String secondCommentString = " PASS FUNCTION NODE COMMENT 2 ";
final int secondCommentId = getProvider().appendFunctionComment(function, secondCommentString, user.getUserId());
final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
assertNotNull(commentsFromDatabase);
assertEquals(storedComments.size() + 2, commentsFromDatabase.size());
assertTrue(commentsFromDatabase.contains(firstComment));
assertTrue(commentsFromDatabase.contains(secondComment));
function.close();
module.close();
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLFunctionCommentTests method appendFunctionComment3.
@Test(expected = NullPointerException.class)
public void appendFunctionComment3() throws CouldntSaveDataException {
getProvider().appendFunctionComment(function, " FAIL ", null);
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
getProvider().appendFunctionComment(function, " PASS FUNCTION NODE COMMENT ", user.getUserId());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLFunctionCommentTests method editFunctionComment6.
@Test(expected = CouldntSaveDataException.class)
public void editFunctionComment6() throws CouldntLoadDataException, CouldntSaveDataException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = function.getGlobalComment() == null ? new ArrayList<IComment>() : function.getGlobalComment();
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String beforeEditCommentString = " EDIT COMMENT BEFORE EDIT ";
final int editedCommentId = getProvider().appendFunctionComment(function, 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().editFunctionComment(function, editedCommentId, wrongUser.getUserId(), " FAIL ");
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLFunctionNodeCommentTests method editFunctionNodeComment6.
@Test(expected = CouldntSaveDataException.class)
public void editFunctionNodeComment6() throws CouldntLoadDataException, CouldntSaveDataException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = functionNode.getLocalFunctionComment() == null ? new ArrayList<IComment>() : functionNode.getLocalFunctionComment();
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String beforeEditCommentString = " EDIT LOCAL COMMENT BEFORE EDIT ";
final int editedCommentId = getProvider().appendFunctionNodeComment(functionNode, 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().editFunctionNodeComment(functionNode, editedCommentId, wrongUser.getUserId(), " FAIL ");
}
Aggregations