BranchContainerImpl extends BluePipelineContainer { @Override public BluePipeline get(String name) { Job job = pipeline.mbp.getItem(name); if (job == null) { return null; } BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(job); if (organization == null) { return null; } return new BranchImpl(organization, job, getLink()); } BranchContainerImpl(MultiBranchPipelineImpl pipeline, Link self); @Override BluePipeline get(String name); @Override Iterator<BluePipeline> iterator(); @Override @SuppressWarnings("unchecked") Iterator<BluePipeline> iterator(int start, int limit); @Override Link getLink();  }
@Test public void testBranchOrdering() throws Exception { j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); hudson.model.User user = User.get("alice"); user.setFullName("Alice Cooper"); WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p"); mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0]))); for (SCMSource source : mp.getSCMSources()) { assertEquals(mp, source.getOwner()); } WorkflowJob p = scheduleAndFindBranchProject(mp, "master"); j.waitUntilNoActivity(); String token = getJwtToken(j.jenkins, "alice", "alice"); new RequestBuilder(baseUrl) .put("/organizations/jenkins/pipelines/p/branches/feature2/favorite") .jwtToken(token) .data(ImmutableMap.of("favorite", true)) .build(Map.class); new RequestBuilder(baseUrl) .put("/organizations/jenkins/pipelines/p/branches/feature4/favorite") .jwtToken(token) .data(ImmutableMap.of("favorite", true)) .build(Map.class); List l = request().get("/organizations/jenkins/pipelines/p/branches/") .jwtToken(token) .build(List.class); Assert.assertEquals(4,l.size()); Map o = (Map)l.get(1); Map o2 = (Map)l.get(0); WorkflowJob j1 = findBranchProject(mp, (String)o.get("name")); j.waitForCompletion(j1.getLastBuild()); j.waitForCompletion(j1.scheduleBuild2(0).waitForStart()); WorkflowJob j2 = findBranchProject(mp, (String)o2.get("name")); j.waitForCompletion(j2.getLastBuild()); List l2 = request().get("/organizations/jenkins/pipelines/p/branches/") .jwtToken(token) .build(List.class); Assert.assertEquals(4,l.size()); Map o1 = (Map)l2.get(0); Map o3 = (Map)l2.get(1); Assert.assertEquals(o2.get("name"), o1.get("name")); }