Java Code Examples for com.mongodb.BasicDBObject#parse()

The following examples show how to use com.mongodb.BasicDBObject#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoDbDataProviderEngine.java    From n2o-framework with Apache License 2.0 6 votes vote down vote up
private Bson getFilters(Map<String, Object> inParams) {
    Bson filters = null;
    if (inParams.containsKey(FILTERS) && inParams.get(FILTERS) != null) {
        PlaceHoldersResolver resolver = new PlaceHoldersResolver("#", "");
        List<String> filterList = (List<String>) inParams.get(FILTERS);
        List<Bson> filtersByFields = new ArrayList<>();
        for (String filter : filterList) {
            Bson f = BasicDBObject.parse(resolver.resolve(filter, PlaceHoldersResolver.replaceByJson(replaceOptional(inParams::get), mapper)));
            filtersByFields.add(f);
        }
        filters = filtersByFields.isEmpty() ? null : Filters.and(filtersByFields);
    }
    return filters;
}
 
Example 2
Source File: MultipleBuildsFeatureMergeHelperTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void featureNoScenarios() {
	final Feature feature = new Feature(BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '', 'name' : 'f1', 'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final String[] builds = { "build1", "build2" };
	final MultipleBuildsFeatureMergeHelper target = new MultipleBuildsFeatureMergeHelper(Arrays.asList(builds));
	target.addFeature(feature);
	assertEquals(target.getMergeFeature(feature.getId()).getStatuses().get(0), Statuses.UNKNOWN.getTextName());
}
 
Example 3
Source File: MultipleBuildsFeatureMergeHelperTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void orderAddedDosentMatter() {
	final Feature feature1 = new Feature(BasicDBObject
					.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3'}]},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2'},{'result' : {'status' : 'passed'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final Feature feature2 = new Feature(BasicDBObject
					.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3'}]},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2'},{'result' : {'status' : 'failed'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build2','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final String[] builds = { "build1", "build2" };
	final MultipleBuildsFeatureMergeHelper target = new MultipleBuildsFeatureMergeHelper(Arrays.asList(builds));
	target.addFeature(feature2);
	target.addFeature(feature1);
	assertEquals(target.getMergeFeature(feature1.getId()).getStatuses().get(0), Statuses.PASSED.getTextName());
}
 
Example 4
Source File: SortUtil.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
/**
 * convert order string to DBObject.
 * @param jsonString
 * @return
 */
public static DBObject getSort(String jsonString) {
    jsonString = jsonString.trim();
    if (!jsonString.startsWith("{")) {
        jsonString = "{" + jsonString;
    }
    if (!jsonString.endsWith("}")) {
        jsonString = jsonString + "}";
    }
    return BasicDBObject.parse(jsonString);
}
 
Example 5
Source File: BoolBuilder.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
public BoolBuilder and(String json1, String json2){
    this.expression = AND;
    DBObject dbo1 = BasicDBObject.parse(json1);
    DBObject dbo2 = BasicDBObject.parse(json2);
    list.add(dbo1);
    list.add(dbo2);
    return this;
}
 
Example 6
Source File: MultipleBuildsFeatureMergeHelperTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void featureAddedUndefined() {
	final Feature feature1 = new Feature(BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3'}]},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'undefined'},'name' : 's2'},{'result' : {'status' : 'passed'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final Feature feature2 = new Feature(BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'failed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3'}]},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'undefined'},'name' : 's2'},{'result' : {'status' : 'undefined'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build2','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final String[] builds = { "build1", "build2" };
	final MultipleBuildsFeatureMergeHelper target = new MultipleBuildsFeatureMergeHelper(Arrays.asList(builds));
	target.addFeature(feature1);
	target.addFeature(feature2);
	assertEquals(target.getMergeFeature(feature1.getId()).getStatuses().get(0), Statuses.UNDEFINED.getTextName());
}
 
Example 7
Source File: MultipleBuildsFeatureMergeHelperTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void featureAddedPassed() {
	final Feature feature1 = new Feature(BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3',}],},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2'},{'result' : {'status' : 'passed'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final Feature feature2 = new Feature(BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3',}],},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2'},{'result' : {'status' : 'passed'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build2','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final String[] builds = { "build1", "build2" };
	final MultipleBuildsFeatureMergeHelper target = new MultipleBuildsFeatureMergeHelper(Arrays.asList(builds));
	target.addFeature(feature1);
	target.addFeature(feature2);
	assertEquals(target.getMergeFeature(feature1.getId()).getStatuses().get(0), Statuses.PASSED.getTextName());
}
 
Example 8
Source File: MultipleBuildsFeatureMergeHelperTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void noFeatureAdded() {
	final Feature feature = new Feature(BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 'e2',},{'result' : {'status' : 'passed'},'name' : 'e3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));

	final String[] builds = { "build1", "build2" };
	final MultipleBuildsFeatureMergeHelper target = new MultipleBuildsFeatureMergeHelper(Arrays.asList(builds));
	assertNull(target.getMergeFeature(feature.getId()));
}
 
Example 9
Source File: QueryBuilderFilterQueryTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void tagSearchFilterQuery() {
	final Coordinates co = new Coordinates();
	co.setBuild("test");
	co.setMajor(1);
	co.setMinor(1);
	co.setProduct("test");
	co.setServicePack(1);
	final DBObject expected = BasicDBObject
			.parse("{ 'coordinates.product' : 'test' , 'coordinates.major' : 1 , 'coordinates.minor' : 1 , 'coordinates.servicePack' : 1 , 'coordinates.build' : 'test' , '$and' : [ { 'tags.name' : { '$regex' : '.*@this.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*is.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*a.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*test.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*tag.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*filter.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*string.*' , '$options' : 'i'}}]}");
	assertEquals(QueryBuilder.getInstance().buildFilterQuery(co, "@this is a test tag filter string", 0, 0, 0, 0, null),
			expected);
}
 
Example 10
Source File: QueryBuilderFilterQueryTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void searchFilterQuery() {
	final Coordinates co = new Coordinates();
	co.setBuild("test");
	co.setMajor(1);
	co.setMinor(1);
	co.setProduct("test");
	co.setServicePack(1);
	final DBObject expected = BasicDBObject
			.parse("{ 'coordinates.product' : 'test' , 'coordinates.major' : 1 , 'coordinates.minor' : 1 , 'coordinates.servicePack' : 1 , 'coordinates.build' : 'test' , '$and' : [ { 'name' : { '$regex' : '.*this.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*is.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*a.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*test.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*filter.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*string.*' , '$options' : 'i'}}]}");
	assertEquals(QueryBuilder.getInstance().buildFilterQuery(co, "this is a test filter string", 0, 0, 0, 0, null),
			expected);
}
 
Example 11
Source File: MultipleBuildsFeatureMergeHelperTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyBuilds() {
	final Feature feature1 = new Feature(BasicDBObject
					.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '' ,'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2',},{'result' : {'status' : 'passed'},'name' : 's3'}]},{'id' : 'e2','description' : '','name' : 's1','steps' : [{'result' : {'status' : 'passed'},'name' : 's2'},{'result' : {'status' : 'passed'},'name' : 's3',}],}],'coordinates' : {'product' : 'P1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'unknown status? - expected passed,failed or undefined','originalAutomatedStatus' : 'unknown status? - expected passed,failed or undefined'}"));
	final MultipleBuildsFeatureMergeHelper target = new MultipleBuildsFeatureMergeHelper(new ArrayList<>());
	target.addFeature(feature1);
	assertNull(target.getMergeFeature(feature1.getId()));
}
 
Example 12
Source File: QueryBuilderFilterQueryTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Test
public void noFiletersQuery() {
	final Coordinates co = new Coordinates();
	co.setBuild("test");
	co.setMajor(1);
	co.setMinor(1);
	co.setProduct("test");
	co.setServicePack(1);
	final DBObject expected = BasicDBObject
			.parse("{ 'coordinates.product' : 'test' , 'coordinates.major' : 1 , 'coordinates.minor' : 1 , 'coordinates.servicePack' : 1 , 'coordinates.build' : 'test' , '$and' : null}");
	assertEquals(QueryBuilder.getInstance().buildFilterQuery(co, "", 0, 0, 0, 0, null), expected);
}
 
Example 13
Source File: MergeBuildsTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 14
Source File: MergeBuildsTest.java    From XBDD with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	MockitoAnnotations.initMocks(this);

	this.feature1 = BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '', 'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's1',},{'result' : {'status' : 'passed'},'name' : 's2'}]}, {'id' : 'e2','description' : '','name' : 'e2','steps' : [{'result' : {'status' : 'passed'},'name' : 's1',},{'result' : {'status' : 'undefined'},'name' : 's2',}]}], 'coordinates' : {'product' : 'p1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build1','version' : '1.1.1'},'calculatedStatus' : 'undefined', 'originalAutomatedStatus' : 'undefined'}");
	this.feature2 = BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '', 'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'passed'},'name' : 's1',},{'result' : {'status' : 'failed'},'name' : 's2'}]}, {'id' : 'e2','description' : '','name' : 'e2','steps' : [{'result' : {'status' : 'failed'},'name' : 's1',},{'result' : {'status' : 'undefined'},'name' : 's2',}]}], 'coordinates' : {'product' : 'p1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build2','version' : '1.1.1'},'calculatedStatus' : 'failed', 'originalAutomatedStatus' : 'undefined'}");
	this.feature3 = BasicDBObject
			.parse("{'_id' : 'p1/f1','id' : 'f1','description' : '', 'name' : 'f1', 'elements' : [{'id' : 'e1','description' : '','name' : 'e1','steps' : [{'result' : {'status' : 'undefined'},'name' : 's1',},{'result' : {'status' : 'undefined'},'name' : 's2'}]}, {'id' : 'e2','description' : '','name' : 'e2','steps' : [{'result' : {'status' : 'passed'},'name' : 's1',},{'result' : {'status' : 'passed'},'name' : 's2',}]}], 'coordinates' : {'product' : 'p1','major' : 1,'minor' : 1,'servicePack' : 1,'build' : 'build3','version' : '1.1.1'},'calculatedStatus' : 'undefined', 'originalAutomatedStatus' : 'undefined'}");

	when(this.mongoLegacyDb.getCollection(anyString())).thenReturn(this.collection);
	when(this.collection.find(any(DBObject.class), any(DBObject.class))).thenReturn(this.cursor);
	when(this.cursor.hasNext()).thenReturn(true, true, true, false);
}
 
Example 15
Source File: BuguAggregation.java    From bugu-mongo with Apache License 2.0 4 votes vote down vote up
public BuguAggregation project(String jsonString){
    DBObject dbo = BasicDBObject.parse(jsonString);
    return project(dbo);
}
 
Example 16
Source File: BuguAggregation.java    From bugu-mongo with Apache License 2.0 4 votes vote down vote up
public BuguAggregation addFields(String jsonString){
    DBObject dbo = BasicDBObject.parse(jsonString);
    return addFields(dbo);
}
 
Example 17
Source File: CondBuilder.java    From bugu-mongo with Apache License 2.0 4 votes vote down vote up
public CondBuilder ifCondition(String json){
    DBObject ifObj = BasicDBObject.parse(json);
    dbo.put(IF, ifObj);
    return this;
}
 
Example 18
Source File: BuguAggregation.java    From bugu-mongo with Apache License 2.0 4 votes vote down vote up
public BuguAggregation group(String jsonString){
    DBObject dbo = BasicDBObject.parse(jsonString);
    return group(dbo);
}
 
Example 19
Source File: BuguAggregation.java    From bugu-mongo with Apache License 2.0 4 votes vote down vote up
public BuguAggregation lookup(String jsonString){
    DBObject dbo = BasicDBObject.parse(jsonString);
    return lookup(dbo);
}
 
Example 20
Source File: BuguQuery.java    From bugu-mongo with Apache License 2.0 2 votes vote down vote up
/**
 * @since mongoDB 3.6
 * @param jsonStr
 * @return 
 */
public BuguQuery<T> expr(String jsonStr){
    DBObject expression = BasicDBObject.parse(jsonStr);
    return expr(expression);
}