@Test public void testBuildHiddenPath() { ((PullRequestServiceImpl) service).buildHiddenPath(new PullRequestImpl(1, "source/a", "develop", "target/a", "master", PullRequestStatus.OPEN)); final URI uri = URI.create("git://PR-1-source/a/develop-master@target/a"); verify(ioService).get(eq(uri)); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(this.getClass().getSimpleName()); builder.append(" <" + this.getId() + "," + this.getStatus() + "> "); builder.append(" { "); builder.append(" source:( " + this.getSourceRepository() + "," + this.getSourceBranch() + " ) "); builder.append(" -> "); builder.append(" target:( " + this.getTargetRepository() + "," + this.getTargetBranch() + " ) "); builder.append(" } "); return builder.toString(); } }
storablePullRequest = new PullRequestImpl(generatedId, sourceRepository, sourceBranch, storablePullRequest.getId(), storablePullRequest.getTargetRepository(), storablePullRequest.getTargetBranch());
@Override public boolean equals(final Object obj) { if (obj instanceof PullRequest) { return ((PullRequest) obj).getId() == this.getId(); } else { return super.equals(obj); } }
storablePullRequest = new PullRequestImpl(generatedId, sourceSpace, sourceRepository, storablePullRequest.getId(), storablePullRequest.getTargetRepository(), storablePullRequest.getTargetBranch());
@Test public void testBuildHiddenPath() { ((PullRequestServiceImpl) service).buildHiddenPath(new PullRequestImpl(1, "test-realm", "source/a", "develop", "test-realm", "target/a", "master", PullRequestStatus.OPEN)); final URI uri = URI.create("git://PR-1-source/a/develop-master@target/a"); verify(ioService).get(eq(uri)); }
@Test public void testBuildHiddenPath() { ((PullRequestServiceImpl) service).buildHiddenPath(new PullRequestImpl(1, "test-realm", "source/a", "develop", "test-realm", "target/a", "master", PullRequestStatus.OPEN)); final URI uri = URI.create("git://PR-1-source/a/develop-master@target/a"); verify(ioService).get(eq(uri)); }
@Override public PullRequest getPullRequest(long id) { final List<PullRequest> prs = this.getPullRequests(elem -> elem.getId() == id); if (prs.size() == 0) { throw new NoSuchElementException("The Pull Request with ID #" + id + " not found"); } final PullRequest pr = prs.get(0); return new PullRequestImpl(pr.getId(), pr.getSourceSpace(), pr.getSourceRepository(), pr.getSourceBranch(), pr.getTargetSpace(), pr.getTargetRepository(), pr.getTargetBranch(), pr.getStatus()); }
@Test public void testFailToCreatePullRequest() { PullRequest pullRequest = new PullRequestImpl("child/a", "develop", "parent/a", "master"); doThrow(new RuntimeException("Mocked exception")).when(this.storage).write(any(String.class), any(GitMetadata.class)); try { pullRequest = service.createPullRequest("child/a", "develop", "parent/a", "master"); fail("Should throw exception before this point"); } catch (Exception e) { List<PullRequest> pullRequests = service.getPullRequestsByBranch(0, 0, pullRequest.getTargetRepository(), pullRequest.getTargetBranch()); assertEquals(0, pullRequests.size()); } }
@Test public void testFailToCreatePullRequest() { PullRequest pullRequest = new PullRequestImpl("test-realm", "child/a", "develop", "test-realm", "parent/a", "master"); doThrow(new RuntimeException("Mocked exception")).when(this.storage).write(any(String.class), any(GitMetadata.class)); try { pullRequest = service.createPullRequest("test-realm", "child/a", "develop", "test-realm", "parent/a", "master"); fail("Should throw exception before this point"); } catch (Exception e) { List<PullRequest> pullRequests = service.getPullRequestsByBranch(0, 0, pullRequest.getTargetRepository(), pullRequest.getTargetBranch()); assertEquals(0, pullRequests.size()); } }
@Test public void testFailToCreatePullRequest() { PullRequest pullRequest = new PullRequestImpl("test-realm", "child/a", "develop", "test-realm", "parent/a", "master"); doThrow(new RuntimeException("Mocked exception")).when(this.storage).write(any(String.class), any(GitMetadata.class)); try { pullRequest = service.createPullRequest("test-realm", "child/a", "develop", "test-realm", "parent/a", "master"); fail("Should throw exception before this point"); } catch (Exception e) { List<PullRequest> pullRequests = service.getPullRequestsByBranch(0, 0, pullRequest.getTargetRepository(), pullRequest.getTargetBranch()); assertEquals(0, pullRequests.size()); } }
@Test public void testPagination() { final PullRequestImpl pr = new PullRequestImpl(1, "source/a", "develop",
@Test public void testPagination() { final PullRequestImpl pr = new PullRequestImpl(1, "test-realm", "source/a",
@Test public void testPagination() { final PullRequestImpl pr = new PullRequestImpl(1, "test-realm", "source/a",
protected void changePullRequestStatus(final String repository, final long id, final PullRequestStatus status) { checkNotEmpty("repository", repository); checkNotNull("status", status); GitMetadata metadata = getRepositoryMetadata(repository); PullRequest pullRequest = metadata.getPullRequest(id); PullRequestImpl finalPullRequest = new PullRequestImpl(pullRequest.getId(), pullRequest.getSourceRepository(), pullRequest.getSourceBranch(), pullRequest.getTargetRepository(), pullRequest.getTargetBranch(), status); List<PullRequest> finalPullRequests = metadata.getPullRequests(elem -> elem.getId() != id); finalPullRequests.add(finalPullRequest); GitMetadata storableMetadata = new GitMetadataImpl(metadata.getName(), metadata.getOrigin(), metadata.getForks(), finalPullRequests); this.metadataStore.write(storableMetadata.getName(), storableMetadata); }
protected void changePullRequestStatus(final String repository, final long id, final PullRequestStatus status) { checkNotEmpty("repository", repository); checkNotNull("status", status); GitMetadata metadata = getRepositoryMetadata(repository); PullRequest pullRequest = metadata.getPullRequest(id); PullRequestImpl finalPullRequest = new PullRequestImpl(pullRequest.getId(), pullRequest.getSourceSpace(), pullRequest.getSourceRepository(), pullRequest.getSourceBranch(), pullRequest.getTargetSpace(), pullRequest.getTargetRepository(), pullRequest.getTargetBranch(), status); List<PullRequest> finalPullRequests = metadata.getPullRequests(elem -> elem.getId() != id); finalPullRequests.add(finalPullRequest); GitMetadata storableMetadata = new GitMetadataImpl(metadata.getName(), metadata.getOrigin(), metadata.getForks(), finalPullRequests); this.metadataStore.write(storableMetadata.getName(), storableMetadata); }