MergeBuilds { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public DBObject getMergedBuilds(final Merge merge) { final DBCollection collection = this.mongoLegacyDb.getCollection("features"); final List<Feature> featureList = new ArrayList<>(); final List<DBObject> or = new ArrayList<>(); for (final String element : merge.builds) { final Pattern regex = Pattern.compile("^" + merge.product + "/" + merge.version + "/" + (element) + "/"); or.add(new BasicDBObject("_id", regex)); } final DBCursor temp = collection.find(new BasicDBObject("$or", or), new BasicDBObject("id", 1).append("name", 1) .append("calculatedStatus", 1).append("elements", 1).append("coordinates", 1)); final MultipleBuildsFeatureMergeHelper buildMerge = new MultipleBuildsFeatureMergeHelper(merge.builds); while (temp.hasNext()) { final Feature feature = new Feature((BasicDBObject) temp.next()); if (feature.getCoordinates().getBuild().equals(merge.builds.get(0))) { featureList.add(feature); } buildMerge.addFeature(feature); } final DBObject buildObject = new BasicDBObject(); final List<DBObject> resultList = new ArrayList<>(); for (final Feature feature : featureList) { resultList.add(buildMerge.getMergeFeature(feature.getId()).toDBObject()); } merge.builds.add(0, "Merged"); buildObject.put("features", resultList); buildObject.put("builds", merge.builds); return buildObject; }  @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) DBObject getMergedBuilds(final Merge merge);  }
@Test public void test() { final Merge merge = new Merge(); final String[] builds = { "build1", "build2", "build3" }; merge.builds = new ArrayList<String>(); merge.builds.addAll(Arrays.asList(builds)); when(this.cursor.next()).thenReturn(this.feature1, this.feature2, this.feature3); final DBObject result = BasicDBObject .parse("{'features' : [{'id' : 'f1', 'name' : 'f1', 'elements' : [ { 'id' : 'e1', 'name' : 'e1', 'statuses' : [ 'passed' , 'passed', 'failed', 'undefined']} , {'id' : 'e2', 'name' : 'e2', 'statuses' : ['failed', 'undefined' , 'failed', 'passed']}], 'statuses' : ['failed', 'undefined', 'failed', 'undefined'], 'url': 'reports/p1/1.1.1/{{BUILD_NAME}}/f1'}], 'builds':['Merged', 'build1', 'build2', 'build3']}"); assertEquals(this.mergeBuilds.getMergedBuilds(merge), result); }