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

Commit 47f362b

Browse files
committed
almost works
1 parent 8503a4b commit 47f362b

3 files changed

Lines changed: 37 additions & 21 deletions

File tree

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

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ private static boolean isArray(String key) {
4242
/**
4343
* Internal use only for provider overriding purposes
4444
*
45-
* @param basicObject Current object
45+
* @param basicObject Current object
4646
* @param collectionName Name of collection
47-
* @param way Passed way
48-
* @param <T> Adaptor type
47+
* @param way Passed way
48+
* @param <T> Adaptor type
4949
* @return return Adaptor instance
5050
* @throws DataException In case provider could not be initialized
5151
*/
@@ -54,9 +54,9 @@ private static boolean isArray(String key) {
5454
/**
5555
* Internal use only for provider overriding purposes
5656
*
57-
* @param basicObject Current object
57+
* @param basicObject Current object
5858
* @param collectionName Name of collection
59-
* @param <T> Adaptor type
59+
* @param <T> Adaptor type
6060
* @return return Adaptor instance
6161
* @throws DataException In case provider c
6262
*/
@@ -66,7 +66,7 @@ private static boolean isArray(String key) {
6666
* Internal use only for provider overriding purposes
6767
*
6868
* @param collectionName Name of collection
69-
* @param <T> Adaptor type
69+
* @param <T> Adaptor type
7070
* @return Adaptor instance
7171
* @throws DataException In case provider could not be initialized
7272
*/
@@ -296,23 +296,38 @@ public String getValue() throws DataException {
296296

297297
if (result == null) {
298298
if (this.way != null && this.way.contains(".")) {
299-
this.way = this.way.split("[.]")[this.way.split("[.]").length - 1];
299+
this.way = this.way.substring(way.lastIndexOf(".") + 1);
300300
}
301301

302-
result = this.basicObject.getString(this.way);
303-
}
304-
if (result == null) {
305-
this.basicObject.keySet().stream().forEach(s -> {
306-
try {
307-
AbstractDataProvider instance = createInstance(basicObject, collectionName, way + "." + s);
308-
instance.applyGenerator(callback);
309-
this.basicObject.put(s, instance.getValue());
310-
} catch (DataException e) {
311-
e.printStackTrace();
312-
}
302+
if (!(basicObject.get(way) instanceof BasicDBObject)) {
303+
result = basicObject.getString(way);
304+
}
313305

314-
});
315-
result = basicObject.toString();
306+
if (result == null) {
307+
308+
BasicDBObject dbObject = new BasicDBObject();
309+
310+
basicObject.keySet().stream().forEach(s -> {
311+
try {
312+
AbstractDataProvider instance = createInstance((BasicDBObject) basicObject.get(s), collectionName, way + "." + s);
313+
instance.applyGenerator(callback);
314+
dbObject.put(s, instance.getValue());
315+
} catch (ClassCastException e) {
316+
AbstractDataProvider instance = null;
317+
try {
318+
instance = createInstance((BasicDBObject) basicObject, collectionName, way + "." + s);
319+
instance.applyGenerator(callback);
320+
dbObject.put(s, instance.getValue());
321+
} catch (DataException e1) {
322+
e1.printStackTrace();
323+
}
324+
} catch (DataException e) {
325+
e.printStackTrace();
326+
}
327+
328+
});
329+
result = dbObject.toString();
330+
}
316331
}
317332
return applyCallBackData(result);
318333
}

datajack-api/src/test/java/ru/sbtqa/tag/datajack/callback/SampleDataGensCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Object call(CallbackData callbackData) {
2323
String cacheKey = callbackData.getPath();
2424
String result = callbackData.getResult();
2525

26-
if (result.startsWith("generate:")) {
26+
if (result != null && result.startsWith("generate:")) {
2727
if (!cache.containsKey("testDataCache")) {
2828
cache.put("testDataCache", new HashMap<>());
2929
} else if (((Map) cache.get("testDataCache")).containsKey(cacheKey)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public void getByPathArrayTest() throws DataException {
165165

166166
String value = testDataProvider.getByPath("$Tests{Common}").getValue();
167167
Assert.assertNotNull(value);
168+
System.out.println(value);
168169
}
169170

170171
@Test

0 commit comments

Comments
 (0)