SimpleMergeRequestManager implements MergeRequestManager { @Override public void acceptMergeRequest(Resource requestId, User user) { try (RepositoryConnection conn = configProvider.getRepository().getConnection()) { acceptMergeRequest(requestId, user, conn); } }  @Override List<MergeRequest> getMergeRequests(MergeRequestFilterParams params); @Override List<MergeRequest> getMergeRequests(MergeRequestFilterParams params, RepositoryConnection conn); @Override MergeRequest createMergeRequest(MergeRequestConfig config, Resource localCatalog); @Override MergeRequest createMergeRequest(MergeRequestConfig config, Resource localCatalog,
                                           RepositoryConnection conn); @Override void addMergeRequest(MergeRequest request); @Override void addMergeRequest(MergeRequest request, RepositoryConnection conn); @Override Optional<MergeRequest> getMergeRequest(Resource requestId); @Override Optional<MergeRequest> getMergeRequest(Resource requestId, RepositoryConnection conn); @Override void updateMergeRequest(Resource requestId, MergeRequest request); @Override void updateMergeRequest(Resource requestId, MergeRequest request, RepositoryConnection conn); @Override void deleteMergeRequest(Resource requestId); @Override void deleteMergeRequest(Resource requestId, RepositoryConnection conn); @Override void acceptMergeRequest(Resource requestId, User user); @Override void acceptMergeRequest(Resource requestId, User user,  RepositoryConnection conn); @Override void deleteMergeRequestsWithRecordId(Resource recordId); @Override void deleteMergeRequestsWithRecordId(Resource recordId, RepositoryConnection conn); @Override void cleanMergeRequests(Resource recordId, Resource branchId); @Override void cleanMergeRequests(Resource recordId, Resource branchId, RepositoryConnection conn); @Override Comment createComment(Resource requestId, User user, String commentStr); @Override Comment createComment(Resource requestId, User user, String commentStr, Resource parentCommentId); @Override List<List<Comment>> getComments(Resource requestId); @Override Optional<Comment> getComment(Resource commentId); @Override Optional<Comment> getComment(Resource commentId, RepositoryConnection conn); @Override void updateComment(Resource commentId, Comment comment); @Override void deleteComment(Resource commentId); @Override void deleteCommentsWithRequestId(Resource requestId);  }
@Test public void acceptMergeRequestTest() { try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(utilsService).getConflicts(eq(sourceCommit1.getResource()), eq(targetCommit1.getResource()), any(RepositoryConnection.class)); verify(versioningManager).merge(LOCAL_CATALOG_IRI, RECORD_1_IRI, SOURCE_BRANCH_1_IRI, TARGET_BRANCH_1_IRI, user1, null, null); verify(utilsService).updateObject(argThat(matches((AcceptedMergeRequest r) -> { boolean hasResource = r.getResource().equals(request1.getResource()); boolean hasNoSourceBranch = !r.getSourceBranch_resource().isPresent(); boolean hasNoTargetBranch = !r.getTargetBranch_resource().isPresent(); boolean hasNoRemoveSource = !r.getRemoveSource().isPresent(); boolean hasSourceTitle = r.getSourceBranchTitle().isPresent() && r.getSourceBranchTitle().get().equals(SOURCE_BRANCH_TITLE); boolean hasTargetTitle = r.getTargetBranchTitle().isPresent() && r.getTargetBranchTitle().get().equals(TARGET_BRANCH_TITLE); boolean hasSourceCommit = r.getSourceCommit_resource().isPresent() && r.getSourceCommit_resource().get().equals(sourceCommit1.getResource()); boolean hasTargetCommit = r.getTargetCommit_resource().isPresent() && r.getTargetCommit_resource().get().equals(targetCommit1.getResource()); return hasResource && hasNoSourceBranch && hasNoTargetBranch && hasNoRemoveSource && hasSourceTitle && hasTargetTitle && hasSourceCommit && hasTargetCommit ; })), any(RepositoryConnection.class)); }
@Test public void acceptMergeRequestWithoutRecordTest() { thrown.expect(IllegalStateException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request3.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test public void acceptMergeRequestWithNoSourceTest() { request1.removeProperty(SOURCE_BRANCH_1_IRI, VALUE_FACTORY.createIRI(MergeRequest.sourceBranch_IRI)); thrown.expect(IllegalStateException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test public void acceptMergeRequestWithNoTargetTest() { request1.removeProperty(TARGET_BRANCH_1_IRI, VALUE_FACTORY.createIRI(MergeRequest.targetBranch_IRI)); thrown.expect(IllegalArgumentException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test public void acceptMergeRequestWithNoSourceHeadTest() { sourceBranch1.removeProperty(sourceCommit1.getResource(), VALUE_FACTORY.createIRI(Branch.head_IRI)); thrown.expect(IllegalStateException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test public void acceptMergeRequestWithNoTargetHeadTest() { targetBranch1.removeProperty(targetCommit1.getResource(), VALUE_FACTORY.createIRI(Branch.head_IRI)); thrown.expect(IllegalStateException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test public void acceptMergeRequestWithConflictsTest() { when(utilsService.getConflicts(any(Resource.class), any(Resource.class), any(RepositoryConnection.class))).thenReturn(Collections.singleton(conflict)); thrown.expect(IllegalArgumentException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(utilsService).getConflicts(eq(sourceCommit1.getResource()), eq(targetCommit1.getResource()), any(RepositoryConnection.class)); verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); verify(utilsService, never()).updateObject(any(), any(RepositoryConnection.class)); }
@Test public void acceptMergeRequestWithNoSourceTitleTest() { sourceBranch1.removeProperty(null, VALUE_FACTORY.createIRI(_Thing.title_IRI)); thrown.expect(IllegalStateException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test public void acceptMergeRequestWithNoTargetTitleTest() { targetBranch1.removeProperty(null, VALUE_FACTORY.createIRI(_Thing.title_IRI)); thrown.expect(IllegalStateException.class); try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request1.getResource(), user1, conn); } verify(versioningManager, never()).merge(any(Resource.class), any(Resource.class), any(Resource.class), any(Resource.class), any(User.class), any(), any()); }
@Test(expected = IllegalArgumentException.class) public void acceptMergeRequestAlreadyAcceptedTest() { try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(request4.getResource(), user1, conn); } }
@Test(expected = IllegalArgumentException.class) public void acceptMergeRequestThatDoesNotExistTest() { try (RepositoryConnection conn = repo.getConnection()) { manager.acceptMergeRequest(VALUE_FACTORY.createIRI("urn:test"), user1, conn); } }