use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLLocalInstructionCommentTests method appendLocalInstructionComment5.
@Test
public void appendLocalInstructionComment5() throws CouldntLoadDataException, CouldntSaveDataException {
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 firstCommentString = " PASS LOCAL INSTRUCTION COMMENT 1 ";
final int firstCommentId = getProvider().appendLocalInstructionComment(codeNode, instruction, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
final String secondCommentString = " PASS LOCAL INSTRUCTION COMMENT 2 ";
final int secondCommentId = getProvider().appendLocalInstructionComment(codeNode, instruction, 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));
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class TypeInstanceContainerBackendTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, CouldntSaveDataException {
typeManager = new TypeManager(new TypeManagerMockBackend());
sectionContainer = new SectionContainer(new SectionContainerBackend(provider, module));
section = sectionContainer.createSection(" SECTION NAME ", new CAddress("100", 16), new CAddress("200", 16), SectionPermission.READ_WRITE_EXECUTE, new byte[] {});
typeInstancContainerBackend = new TypeInstanceContainerBackend(provider, module, typeManager, sectionContainer);
new UniqueTestUserGenerator(provider).nextActiveUser();
baseType = typeManager.getTypes().get(0);
Assert.assertNotNull(baseType);
typeInstance = typeInstancContainerBackend.createTypeInstance(" TYPE INSTANCE ", " TYPE INSTANCE COMMENT ", baseType, section, 0);
Assert.assertNotNull(typeInstancContainerBackend);
view = module.getContent().getViewContainer().getViews().get(0);
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLTypeInstancesCommentTests method deleteTypeInstanceComment6.
/**
* 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 deleteTypeInstanceComment6() throws CouldntSaveDataException, CouldntDeleteException, CouldntLoadDataException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = instanceContainer.getComments(typeInstance);
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String comment1String = " Comment 1: ";
final int comment1Id = getProvider().appendTypeInstanceComment(typeInstance.getModule().getConfiguration().getId(), typeInstance.getId(), comment1String, user.getUserId());
final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
final String comment2String = " Comment 2: ";
final int comment2Id = getProvider().appendTypeInstanceComment(typeInstance.getModule().getConfiguration().getId(), typeInstance.getId(), comment2String, user.getUserId());
final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
final String comment3String = " Comment 3: ";
final int comment3Id = getProvider().appendTypeInstanceComment(typeInstance.getModule().getConfiguration().getId(), typeInstance.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().deleteTypeInstanceComment(typeInstance.getModule().getConfiguration().getId(), typeInstance.getId(), 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));
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLTypeInstancesCommentTests method appendTypeInstanceComment3.
@Test(expected = NullPointerException.class)
public void appendTypeInstanceComment3() throws CouldntSaveDataException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
getProvider().appendTypeInstanceComment(1, 1, null, user.getUserId());
}
use of com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method editGroupNodeComment6.
@Test(expected = CouldntSaveDataException.class)
public void editGroupNodeComment6() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException {
final INaviGroupNode groupNode = setupGroupNode();
final List<IComment> comments = groupNode.getComments() == null ? new ArrayList<IComment>() : groupNode.getComments();
final IComment lastComment = comments.size() == 0 ? null : Iterables.getLast(comments);
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String commentText = " CODE NODE COMMENT TEST BEFORE EDIT ";
final Integer commentId = getProvider().appendGroupNodeComment(groupNode, 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, Iterables.getLast(newComments));
final IUser wrongUser = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
getProvider().editGroupNodeComment(groupNode, commentId, wrongUser.getUserId(), " FAIL ");
}
Aggregations