Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package act.e2e.util;
/*-
* #%L
* ACT E2E Plugin
* %%
* Copyright (C) 2018 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import act.Act;
import act.app.App;
import act.app.DaoLocator;
import act.conf.AppConfig;
import act.db.Dao;
import act.db.sql.tx.TxContext;
import com.alibaba.fastjson.JSONObject;
import org.osgl.$;
import org.osgl.Lang;
import org.osgl.OsglConfig;
import org.osgl.exception.UnexpectedException;
import org.osgl.util.C;
import org.osgl.util.E;
import org.osgl.util.IO;
import org.osgl.util.S;
import org.yaml.snakeyaml.Yaml;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.persistence.RollbackException;
public class YamlLoader {
static Pattern keyPattern = Pattern.compile("([^(]+)\\(([^)]+)\\)");
private List modelPackages = new ArrayList<>();
private String fixtureFolder = "/e2e/fixtures/";
private ClassLoader classLoader = appClassLoader();
public YamlLoader() {
resetModelPackages();
loadConfig();
}
/**
* Add model packages to the loader.
*
* The model package can be used to concat with the type string when it
* does not contains `.`.
*
* For example, given the following yaml file:
*
* ```yaml
* User(tom)
* name: Tom
* ```
*
* The model type `User` does not contains `.`, so the loader assume it
* need a model package. Assume it has the following model packages set:
*
* * `com.xprj.util`
* * `com.xprj.model`
*
* Then it will try to use the above packages to search for the model. Firstly it
* will try `com.xprj.util.User`, if it cannot load class, then it will try `com.xprj.model.User`.
*
* If both `come.xprj.util` and `com.xprj.model` has `User` class defined, then it will
* use the first one. To specify the User in the second package, use full notation in your
* yaml file:
*
* ```yaml
* com.xproj.model.User(tom)
* name: Tom
* ```
*
* @param modelPackage
* @param modelPackages
*/
protected YamlLoader(String modelPackage, String... modelPackages) {
resetModelPackages();
loadConfig();
addModelPackages(modelPackage, modelPackages);
}
private void addModelPackage(String packageSpec) {
for (String pkg : S.fastSplit(packageSpec, ",")) {
pkg = pkg.trim();
if (S.empty(pkg)) {
continue;
}
this.modelPackages.add(S.ensure(pkg).endWith("."));
}
}
public Map loadFixture(String fixtureName, DaoLocator daoLocator) {
String content = getResourceAsString(fixtureName);
if (null == content) {
return C.Map();
}
return parse(content, daoLocator);
}
/**
* Read the data YAML file and returns List of model objects mapped to their class names
*
* @param yaml
* the yaml content
* @return the loaded data mapped to name
*/
public Map parse(String yaml, DaoLocator daoLocator) {
Object o = new Yaml().load(yaml);
Map