Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit e2608bf

Browse files
fix issue 311
1 parent 5024277 commit e2608bf

8 files changed

Lines changed: 48 additions & 5 deletions

File tree

datajack-api/src/main/java/ru/sbtqa/tag/datajack/providers/AbstractDataProvider.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,17 @@ private BasicDBObject parseComplexDBObject(String key) throws DataException {
256256
partialBuiltPath.append(partialKey);
257257

258258
if (isArray(partialKey)) {
259-
currentBasicObject = (BasicDBObject) parseArray(currentBasicObject, partialKey);
259+
Object basicObject = parseArray(currentBasicObject, partialKey);
260+
currentBasicObject = !(basicObject instanceof BasicDBObject)
261+
? new BasicDBObject(partialKey, basicObject)
262+
: (BasicDBObject) basicObject;
260263
partialBuiltPath.append(".");
261264
continue;
262265
}
263266

264267
if (isReference(currentBasicObject)) {
265268
AbstractDataProvider dataProvider = (AbstractDataProvider) createInstance(currentBasicObject, collectionName);
266-
currentBasicObject = ((AbstractDataProvider)dataProvider.getReference()).basicObject;
269+
currentBasicObject = ((AbstractDataProvider) dataProvider.getReference()).basicObject;
267270
}
268271

269272
Object currentValue = currentBasicObject.get(partialKey);
3.65 KB
Binary file not shown.

providers/json-provider/src/test/java/ru/sbtqa/tag/datajack/providers/json/JsonDataTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,15 @@ public void relativeParentTest() throws DataException {
425425
String expected = "20.91";
426426
Assert.assertEquals(expected, relativeValue);
427427
}
428+
429+
@Test
430+
public void containsArrayTest() throws DataException {
431+
String collectionName = "Tests";
432+
TestDataProvider tdo = new JsonDataProvider(JSON_DATA_PATH, collectionName);
433+
434+
assertEquals("a",
435+
tdo.get("containsArray.array[0]").getValue());
436+
assertEquals("1",
437+
tdo.get("containsArray.array[1]").getValue());
438+
}
428439
}

providers/json-provider/src/test/resources/json/Tests.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@
4747
"$ref": "DataBlocks:Common.gen gen.gendata"
4848
}
4949
}
50-
]
50+
],
51+
"containsArray": {
52+
"array": [
53+
"a",
54+
1
55+
]
56+
}
5157
}

providers/mongo-provider/src/test/java/ru/sbtqa/tag/datajack/providers/mongo/MongoDataTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,15 @@ public void getJsonTest() throws DataException {
325325
String expectedJson = "{ \"login\" : 123 , \"password\" : 123}";
326326
assertEquals(expectedJson, stringJson);
327327
}
328+
329+
@Test
330+
public void containsArrayTest() throws DataException {
331+
String collectionName = "Tests";
332+
TestDataProvider tdo = new MongoDataProvider(mongoDb, collectionName);
333+
334+
assertEquals("a",
335+
tdo.get("containsArray.array[0]").getValue());
336+
assertEquals("1",
337+
tdo.get("containsArray.array[1]").getValue());
338+
}
328339
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"_id": "5785f724ecbafd5014e6dfd8" , "Common": { "ref object data":{ "value": { "collection": "DataBlocks", "path": "Common" } }, "ref data": { "value": { "collection": "DataBlocks", "refId": "57a94a160a279ec293f61665" , "path": "testId" } }, "ref data gen": { "value": { "collection": "DataBlocks", "refId": "57a94a160a279ec293f61665" , "path": "Common.gen gen.gendata" } }, "ref cyclic refid": { "value": { "path": "Common.failCyclicReferenceDifferentCollectionWithRefId", "collection": "DataBlocks", "refId": "57a94a160a279ec293f61665" } }, "gendata": "generate:Numeric:16", "gen gen": { "gendata": { "value": { "collection": "DataBlocks", "path": "Common.gen gen.gendata" } } } }, "id": 123123, "client": 123123123, "dataBlocks": { "Common": { "login": { "value": "2login", "comment": "Ну еще один паоль" }, "password": 123 } }, "comment": "Some comment" }
1+
{"_id": "5785f724ecbafd5014e6dfd8" , "Common": { "ref object data":{ "value": { "collection": "DataBlocks", "path": "Common" } }, "ref data": { "value": { "collection": "DataBlocks", "refId": "57a94a160a279ec293f61665" , "path": "testId" } }, "ref data gen": { "value": { "collection": "DataBlocks", "refId": "57a94a160a279ec293f61665" , "path": "Common.gen gen.gendata" } }, "ref cyclic refid": { "value": { "path": "Common.failCyclicReferenceDifferentCollectionWithRefId", "collection": "DataBlocks", "refId": "57a94a160a279ec293f61665" } }, "gendata": "generate:Numeric:16", "gen gen": { "gendata": { "value": { "collection": "DataBlocks", "path": "Common.gen gen.gendata" } } } }, "id": 123123, "client": 123123123, "dataBlocks": { "Common": { "login": { "value": "2login", "comment": "Ну еще один паоль" }, "password": 123 } }, "comment": "Some comment","containsArray": { "array": [ "a", 1 ]} }

providers/properties-provider/src/test/java/ru/sbtqa/tag/datajack/providers/properties/PropertiesDataTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,15 @@ public void issue290Test() throws Exception {
442442
Assert.assertArrayEquals(expectedValues, stringValues.toArray(new String[0]));
443443

444444
}
445+
446+
@Test
447+
public void containsArrayTest() throws DataException {
448+
String collectionName = "Tests";
449+
TestDataProvider dataProvider = new PropertiesDataProvider(this.propertiesDataPath, collectionName);
450+
451+
assertEquals("a",
452+
dataProvider.get("containsArray.array[0]").getValue());
453+
assertEquals("1",
454+
dataProvider.get("containsArray.array[1]").getValue());
455+
}
445456
}

providers/properties-provider/src/test/resources/properties/Tests.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ array[2].b[0].b.c=1
1313
array[2].b[0].b.d.$ref=DataBlocks:Params Group 1.password
1414
array[3].ref.$ref=DataBlocks:Params Group 1.password
1515
array[3].genRef.$ref=DataBlocks:Common.gen gen.gendata
16-
array[4].refObj.$ref=DataBlocks:Common
16+
array[4].refObj.$ref=DataBlocks:Common
17+
containsArray.array=a,1

0 commit comments

Comments
 (0)