package act.test.util;

import act.app.App;
import act.app.DbServiceManager;
import org.osgl.util.C;
import org.osgl.util.E;

import javax.inject.Inject;
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.Map;

public class Fixture {

    private DbServiceManager dbServiceManager;
    private YamlLoader yamlLoader;

    @Inject
    public Fixture(App app) {
        dbServiceManager = app.dbServiceManager();
        yamlLoader = new YamlLoader();
    }

    public Map<String, Object> loadYamlFile(String yamlFile) {
        File file = new File(yamlFile);
        Map<Class, List> repo;
        if (!file.exists() && !file.canRead()) {
            URL url = getClass().getResource(yamlFile);
            if (null == url) {
                throw E.unexpected("Cannot find yaml file: %s", yamlFile);
            } else {
                return yamlLoader.load(url, "model", dbServiceManager);
            }
        } else {
            return yamlLoader.load(file, "model", dbServiceManager);
        }
    }

}

@@ -540,24 +540,158 @@
 yamlFile) %7B%0A
+        return loadYamlFile(yamlFile, %22model%22);%0A    %7D%0A%0A    public Map%3CString, Object%3E loadYamlFile(String yamlFile, String pkgName) %7B%0A
         File
@@ -1025,23 +1025,23 @@
 ad(url, 
-%22model%22
+pkgName
 , dbServ
@@ -1125,23 +1125,23 @@
 d(file, 
-%22model%22
+pkgName
 , dbServ

allow passing default package name to Fixture