Search in sources :

Example 1 with DataException

use of ru.sbtqa.tag.datajack.exceptions.DataException in project page-factory-2 by sbtqa.

the class DataFactory method getDataProvider.

public static TestDataProvider getDataProvider() throws DataException {
    if (testDataProvider == null) {
        String initialCollection = PROPERTIES.getDataInitialCollection();
        String dataFolder = PROPERTIES.getDataFolder();
        String dataType = PROPERTIES.getDataType();
        String dataExtension = PROPERTIES.getDataExtension();
        switch(dataType) {
            case "json":
                testDataProvider = initProvider(PROVIDERS.JSON_DATA_PROVIDER, dataFolder, initialCollection, (dataExtension.equals("")) ? "json" : dataExtension);
                break;
            case "properties":
                testDataProvider = initProvider(PROVIDERS.PROPERTIES_DATA_PROVIDER, dataFolder, initialCollection, (dataExtension.equals("")) ? "properties" : dataExtension, PROPERTIES.getDataArrayDelimiter());
                break;
            case "excel":
                testDataProvider = initProvider(PROVIDERS.EXCEL_DATA_PROVIDER, dataFolder, initialCollection);
                break;
            case "mongo":
                MongoClient mongoClient = new MongoClient(new MongoClientURI(PROPERTIES.getDataUri()));
                MongoDatabase db = mongoClient.getDatabase(PROPERTIES.getDataDb());
                testDataProvider = initProvider(PROVIDERS.MONGO_DATA_PROVIDER, db, initialCollection);
                break;
            case "stash":
                LOG.debug("Data provider isn't set. Leaving all placeholders as is.");
                break;
            default:
                LOG.debug(format("Using custom data provider %s", dataType));
                if (!dataExtension.isEmpty() && !PROPERTIES.getDataDb().isEmpty()) {
                    throw new DataException("data.extension and data.db could not be set both");
                }
                testDataProvider = initProvider(dataType, dataFolder, initialCollection, dataExtension + PROPERTIES.getDataDb());
        }
    }
    if (!PROPERTIES.getGeneratorsClass().isEmpty()) {
        String className = PROPERTIES.getGeneratorsClass();
        try {
            testDataProvider.applyGenerator((Class<? extends GeneratorCallback>) DataFactory.class.getClassLoader().loadClass(className));
        } catch (ClassNotFoundException e) {
            throw new DataException(format("Could not find generators class at classpath: %s", className));
        } catch (ClassCastException ex) {
            throw new ClassCastException(format("Class %s doesn't extend %s", className, GeneratorCallback.class.getName()));
        }
    }
    return testDataProvider;
}
Also used : MongoClient(com.mongodb.MongoClient) DataException(ru.sbtqa.tag.datajack.exceptions.DataException) MongoClientURI(com.mongodb.MongoClientURI) GeneratorCallback(ru.sbtqa.tag.datajack.callback.GeneratorCallback) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 2 with DataException

use of ru.sbtqa.tag.datajack.exceptions.DataException in project page-factory-2 by sbtqa.

the class HtmlFindUtils method getElementTypesMap.

/**
 * Specifies a type map: type attribute, type. Data is taken from the json file specified in the 'ui.types' parameter
 *
 * @return Returns a type map
 */
public Map<String, Class> getElementTypesMap() {
    Map<String, Class> elements = new HashMap<>();
    try {
        String types = PROPERTIES.geUiTypes();
        String dir = types.substring(0, types.lastIndexOf("/"));
        String name = types.substring(types.lastIndexOf("/")).replace(".json", "");
        TestDataProvider dataObject = new JsonDataProvider(dir, name);
        for (String typeAttribute : dataObject.getKeySet()) {
            elements.put(typeAttribute, Class.forName(dataObject.get(typeAttribute).getValue()));
        }
    } catch (DataException | ClassNotFoundException ex) {
        throw new AutotestError("Error while generating element search types.", ex);
    }
    return elements;
}
Also used : AutotestError(ru.sbtqa.tag.qautils.errors.AutotestError) DataException(ru.sbtqa.tag.datajack.exceptions.DataException) TestDataProvider(ru.sbtqa.tag.datajack.TestDataProvider) HashMap(java.util.HashMap) JsonDataProvider(ru.sbtqa.tag.datajack.providers.json.JsonDataProvider)

Aggregations

DataException (ru.sbtqa.tag.datajack.exceptions.DataException)2 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 HashMap (java.util.HashMap)1 TestDataProvider (ru.sbtqa.tag.datajack.TestDataProvider)1 GeneratorCallback (ru.sbtqa.tag.datajack.callback.GeneratorCallback)1 JsonDataProvider (ru.sbtqa.tag.datajack.providers.json.JsonDataProvider)1 AutotestError (ru.sbtqa.tag.qautils.errors.AutotestError)1