Search in sources :

Example 1 with AssetFile

use of com.centurylink.mdw.dataaccess.file.AssetFile in project mdw-designer by CenturyLinkCloud.

the class GroovyTestCaseRun method getAsset.

TestCaseAsset getAsset(String path) throws TestException {
    try {
        int lastSlash = path.lastIndexOf('/');
        String name = path;
        String pkg = null;
        if (lastSlash >= 0) {
            pkg = path.substring(0, lastSlash);
            name = name.substring(lastSlash + 1);
        }
        if (pkg == null && testcase.isLegacy())
            throw new TestException("Asset path must be fully-qualified for legacy tests");
        if (testcase.isLegacy() || !testCaseAsset.isVcs()) {
            int lastDot = name.lastIndexOf('.');
            if (lastDot < 0)
                throw new TestException("Asset format must be inferable from extension: " + name);
            String language = RuleSetVO.getLanguage(name.substring(lastDot));
            RuleSetVO ruleSet = dao.getRuleSet(name, language, 0);
            if (ruleSet == null) {
                // placeholder
                ruleSet = new RuleSetVO();
                ruleSet.setName(name);
            }
            ruleSet.setPackageName(pkg == null ? testCaseAsset.getPackageName() : pkg);
            return new TestCaseAsset(ruleSet);
        } else {
            // VCS
            PackageDir pkgDir = testCaseAsset.getPackageDir();
            if (pkg != null && !pkg.equals(pkgDir.getPackageName()))
                pkgDir = new PackageDir(dao.getVcsBase(), new File(dao.getVcsBase() + "/" + pkg.replace('.', '/')), dao.getVersionControl());
            if (!pkgDir.exists())
                return null;
            AssetFile assetFile = pkgDir.getAssetFile(new File(pkgDir + "/" + name));
            return new TestCaseAsset(pkgDir, assetFile);
        }
    } catch (Exception ex) {
        throw new TestException("Cannot load " + path, ex);
    }
}
Also used : PackageDir(com.centurylink.mdw.dataaccess.file.PackageDir) AssetFile(com.centurylink.mdw.dataaccess.file.AssetFile) File(java.io.File) AssetFile(com.centurylink.mdw.dataaccess.file.AssetFile) JSONException(org.json.JSONException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) RuleSetVO(com.centurylink.mdw.model.value.attribute.RuleSetVO)

Aggregations

DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 AssetFile (com.centurylink.mdw.dataaccess.file.AssetFile)1 PackageDir (com.centurylink.mdw.dataaccess.file.PackageDir)1 RuleSetVO (com.centurylink.mdw.model.value.attribute.RuleSetVO)1 File (java.io.File)1 IOException (java.io.IOException)1 XmlException (org.apache.xmlbeans.XmlException)1 JSONException (org.json.JSONException)1