33import com .mongodb .BasicDBObject ;
44import org .slf4j .Logger ;
55import org .slf4j .LoggerFactory ;
6+ import pl .jalokim .propertiestojson .resolvers .primitives .BooleanJsonTypeResolver ;
7+ import pl .jalokim .propertiestojson .resolvers .primitives .ObjectFromTextJsonTypeResolver ;
8+ import pl .jalokim .propertiestojson .resolvers .primitives .PrimitiveArrayJsonTypeResolver ;
9+ import pl .jalokim .propertiestojson .resolvers .primitives .StringJsonTypeResolver ;
610import pl .jalokim .propertiestojson .util .PropertiesToJsonConverter ;
711import ru .sbtqa .tag .datajack .TestDataProvider ;
812import ru .sbtqa .tag .datajack .exceptions .CollectionNotFoundException ;
@@ -26,6 +30,7 @@ public class PropertiesDataProvider extends AbstractDataProvider {
2630 private static final String DEFAULT_EXTENSION = "properties" ;
2731 private static final String REF_TPL = "$ref" ;
2832 private final String extension ;
33+ private String arrayDelimiter = "," ;
2934 private String testDataFolder ;
3035
3136 /**
@@ -50,12 +55,13 @@ public PropertiesDataProvider(String testDataFolder, String collectionName) thro
5055 *
5156 * @param testDataFolder path to data folder
5257 * @param collectionName properties file name
53- * @param extension custom file extension
58+ * @param extension custom file extension
59+ * @param arrayDelimiter custom value array delimiter
5460 * @throws DataException if file not found in testDataFolder
5561 */
56- public PropertiesDataProvider (String testDataFolder , String collectionName , String extension ) throws DataException {
62+ public PropertiesDataProvider (String testDataFolder , String collectionName , String extension , String arrayDelimiter ) throws DataException {
5763 this .extension = extension ;
58-
64+ this . arrayDelimiter = arrayDelimiter ;
5965 String json = readFile (testDataFolder , collectionName );
6066
6167 BasicDBObject parsed = parse (json );
@@ -64,43 +70,45 @@ public PropertiesDataProvider(String testDataFolder, String collectionName, Stri
6470 this .collectionName = collectionName ;
6571 }
6672
67- private PropertiesDataProvider (String testDataFolder , BasicDBObject obj , String collectionName , String extension ) {
73+ private PropertiesDataProvider (String testDataFolder , BasicDBObject obj , String collectionName , String extension , String arrayDelimiter ) {
6874 this .extension = extension ;
6975 this .testDataFolder = testDataFolder ;
7076 this .basicObject = obj ;
7177 this .collectionName = collectionName ;
78+ this .arrayDelimiter =arrayDelimiter ;
7279 }
7380
74- private PropertiesDataProvider (String testDataFolder , BasicDBObject obj , String collectionName , String way , String extension ) {
81+ private PropertiesDataProvider (String testDataFolder , BasicDBObject obj , String collectionName , String way , String extension , String arrayDelimiter ) {
7582 this .extension = extension ;
7683 this .testDataFolder = testDataFolder ;
7784 this .basicObject = obj ;
7885 this .way = way ;
7986 this .collectionName = collectionName ;
87+ this .arrayDelimiter =arrayDelimiter ;
8088 }
8189
8290 /**
8391 * {@inheritDoc}
8492 */
8593 @ Override
8694 protected PropertiesDataProvider createInstance (String collectionName ) throws DataException {
87- return new PropertiesDataProvider (testDataFolder , collectionName , extension );
95+ return new PropertiesDataProvider (testDataFolder , collectionName , extension , arrayDelimiter );
8896 }
8997
9098 /**
9199 * {@inheritDoc}
92100 */
93101 @ Override
94102 protected PropertiesDataProvider createInstance (BasicDBObject obj , String collectionName , String way ) {
95- return new PropertiesDataProvider (testDataFolder , obj , collectionName , way , extension );
103+ return new PropertiesDataProvider (testDataFolder , obj , collectionName , way , extension , arrayDelimiter );
96104 }
97105
98106 /**
99107 * {@inheritDoc}
100108 */
101109 @ Override
102110 protected PropertiesDataProvider createInstance (BasicDBObject obj , String collectionName ) {
103- return new PropertiesDataProvider (testDataFolder , obj , collectionName , extension );
111+ return new PropertiesDataProvider (testDataFolder , obj , collectionName , extension , arrayDelimiter );
104112 }
105113
106114 /**
@@ -129,7 +137,7 @@ public TestDataProvider getReference() throws DataException {
129137 }
130138 String refValue = this .basicObject .getString (REF_TPL );
131139 String referencedCollection = refValue .contains (":" ) ? refValue .split (":" )[0 ] : this .collectionName ;
132- String collectionPrefix = refValue .startsWith ("/" ) ? "" :this .collectionName .substring (0 , this .collectionName .lastIndexOf ("/" ) + 1 );
140+ String collectionPrefix = refValue .startsWith ("/" ) ? "" : this .collectionName .substring (0 , this .collectionName .lastIndexOf ("/" ) + 1 );
133141 this .path = refValue .contains (":" ) ? refValue .split (":" )[1 ] : refValue ;
134142 AbstractDataProvider reference = (AbstractDataProvider ) this .fromCollection (collectionPrefix + referencedCollection );
135143 reference .setRootObject (this .rootObject , collectionPrefix + referencedCollection + "." + this .path );
@@ -155,7 +163,12 @@ private String readFile(String testDataFolder, String collectionName) throws Col
155163 try {
156164 File targetFile = new File (testDataFolder + separator + collectionName + "." + this .extension );
157165 Properties properties = getProperties (targetFile );
158- json = new PropertiesToJsonConverter ().parseToJson (properties );
166+ json = new PropertiesToJsonConverter (
167+ new PrimitiveArrayJsonTypeResolver (arrayDelimiter ),
168+ new ObjectFromTextJsonTypeResolver (),
169+ new BooleanJsonTypeResolver (),
170+ new StringJsonTypeResolver ()
171+ ).parseToJson (properties );
159172
160173 } catch (DataException ex ) {
161174 throw new CollectionNotFoundException (String .format ("File %s.%s not found in %s" ,
0 commit comments