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

Commit d104c11

Browse files
Сидоченко Виктор ВикторовичСидоченко Виктор Викторович
authored andcommitted
array deep reference fix
1 parent 268f388 commit d104c11

7 files changed

Lines changed: 85 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ private Object parseArray(BasicDBObject basicO, String key) throws DataException
209209
}
210210
String arrayKey = key.split("\\[")[0];
211211
String arrayIndex = key.split("\\[")[1].split("\\]")[0];
212+
if (basicO.get(arrayKey) instanceof BasicDBObject && isReference((BasicDBObject) basicO.get(arrayKey))) {
213+
basicO = ((AbstractDataProvider) get(arrayKey)).basicObject;
214+
arrayKey = basicO.keySet().iterator().next();
215+
way = key;
216+
} else {
217+
way += "." + key;
218+
}
212219
Object listCandidate = basicO.get(arrayKey);
213220

214221
if (!(listCandidate instanceof BasicDBList)) {
@@ -230,6 +237,7 @@ private BasicDBObject parseComplexDBObject(String key) throws DataException {
230237

231238
if (isArray(partialKey)) {
232239
currentBasicObject = (BasicDBObject) parseArray(currentBasicObject, partialKey);
240+
partialBuiltPath.append(".");
233241
continue;
234242
}
235243

@@ -241,6 +249,7 @@ private BasicDBObject parseComplexDBObject(String key) throws DataException {
241249
}
242250

243251
Object currentValue = currentBasicObject.get(partialKey);
252+
this.way += "." + partialKey;
244253
if (!(currentValue instanceof BasicDBObject)) {
245254
if (null == currentValue || i < keys.length - 1) {
246255
String lastKey = keys[keys.length - 1];

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ public void arrayReferenceTest() throws DataException {
7575
testDataProvider.get("array[3].ref").getValue());
7676
}
7777

78+
@Test
79+
public void arrayReferencedTest() throws DataException {
80+
String collectionName = "DataBlocks";
81+
TestDataProvider testDataProvider = new JsonDataProvider(JSON_DATA_PATH, collectionName);
82+
83+
assertEquals("a",
84+
testDataProvider.get("ref array[0]").getValue());
85+
}
86+
87+
@Test
88+
public void arrayDeepReferencedTest() throws DataException {
89+
String collectionName = "DataBlocks";
90+
TestDataProvider testDataProvider = new JsonDataProvider(JSON_DATA_PATH, collectionName);
91+
92+
assertEquals("1",
93+
testDataProvider.get("ref array[2].b[0].b.c").getValue());
94+
}
95+
96+
@Test
97+
public void arrayDeepReferencedToReferenceTest() throws DataException {
98+
String collectionName = "DataBlocks";
99+
TestDataProvider testDataProvider = new JsonDataProvider(JSON_DATA_PATH, collectionName);
100+
101+
assertEquals("123qwe",
102+
testDataProvider.get("ref array[2].b[0].b.d").getValue());
103+
}
104+
105+
78106
@Test
79107
public void arrayGeneratorTest() throws DataException {
80108
String collectionName = "Tests";

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,11 @@
6363
"nestedObjectValue": {
6464
"innerValue": "This is string from nested object"
6565
}
66+
},
67+
"ref array": {
68+
"value": {
69+
"collection": "Tests",
70+
"path": "array"
71+
}
6672
}
6773
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@
3737
"b": [
3838
{
3939
"b": {
40-
"c": 1
40+
"c": 1,
41+
"d": {
42+
"value": {
43+
"collection": "DataBlocks",
44+
"path": "Params Group 1.password"
45+
}
46+
}
4147
}
4248
}
4349
]

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,34 @@ public void arrayReferenceTest() throws DataException {
7979
dataProvider.get("array[3].ref").getValue());
8080
}
8181

82+
83+
@Test
84+
public void arrayReferencedTest() throws DataException {
85+
String collectionName = "DataBlocks";
86+
TestDataProvider testDataProvider = new PropertiesDataProvider(this.propertiesDataPath, collectionName);
87+
88+
assertEquals("a",
89+
testDataProvider.get("ref array[0]").getValue());
90+
}
91+
92+
@Test
93+
public void arrayDeepReferencedTest() throws DataException {
94+
String collectionName = "DataBlocks";
95+
TestDataProvider testDataProvider = new PropertiesDataProvider(this.propertiesDataPath, collectionName);
96+
97+
assertEquals("1",
98+
testDataProvider.get("ref array[2].b[0].b.c").getValue());
99+
}
100+
101+
@Test
102+
public void arrayDeepReferencedToReferenceTest() throws DataException {
103+
String collectionName = "DataBlocks";
104+
TestDataProvider testDataProvider = new PropertiesDataProvider(this.propertiesDataPath, collectionName);
105+
106+
assertEquals("123qwe",
107+
testDataProvider.get("ref array[2].b[0].b.d").getValue());
108+
}
109+
82110
@Test
83111
public void arrayGeneratorTest() throws DataException {
84112
String collectionName = "Tests";

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ MapTests.doubleValue=42.01
3131
MapTests.nestedObjectValue.innerValue=This is string from nested object
3232
MapTests.ref.value.collection=DataBlocks
3333
MapTests.ref.value.path=MapTests.stringValue
34-
MapTests.ref.value.comment=Пароль пользователя
34+
MapTests.ref.value.comment=Пароль пользователя
35+
ref\ array.value.collection= Tests
36+
ref\ array.value.path = array

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ comment=Some comment
1212
array[0]=a
1313
array[1].b=1
1414
array[2].b[0].b.c=1
15+
array[2].b[0].b.d.value.collection=DataBlocks
16+
array[2].b[0].b.d.value.path=Params Group 1.password
1517
array[3].ref.value.collection=DataBlocks
1618
array[3].ref.value.path=Params Group 1.password
1719
array[3].genRef.value.collection=DataBlocks
1820
array[3].genRef.value.path=Common.gen gen.gendata
19-
array[3].refObj.value.collection=DataBlocks
20-
array[3].refObj.value.path=Common
21+
array[4].refObj.value.collection=DataBlocks
22+
array[4].refObj.value.path=Common

0 commit comments

Comments
 (0)