ruwebframe 0.1.10

a simple webframe for rust actix-web, based on rudi and rbatis.
Documentation
use crate::database;
use crate::rubase::get_self::GetSelf;
use crate::rubase::rudto::cfgdto;
use crate::rubase::rutils::file_utils;
use crate::rubase::{BaseEntity, BaseEntitySingle};
use crate::ruconf;
use crate::rudi::difactroy::find_bean_di_factroy;
use crate::rudi::ditemplate;
use crate::rudi::ditemplate::parse_template;
use crate::domain::rudb::dbdao::userdao;
use crate::rulog::ru_log;
use chrono::{Local, Utc};
use std::sync::Arc;

#[cfg(test)]

mod tests {
    use crate::rubase::rutils;
    use crate::rudi::didto;
    use crate::rudi::difactroy::di_factroy::DiFactroy;
    use super::*;
 
 
    #[test]
    fn test_01_make_suites() {
        let factry = find_bean_di_factroy().unwrap();
        let mut f = factry.lock().unwrap();
        f.make_suites();
    }

    #[test]
    fn test_02_read_test() {
        let ret = file_utils::read_file("./tests/ruconf_test.rs");
        ru_log::info(ret.unwrap().as_str());
    }

    #[test]
    fn test_03_f_factroy() {
        let cfg = ruconf::find_bean_ru_config().unwrap();

        let file = cfg.lock().unwrap().find_base_path() + "/src/rudi/difactroy/di_factroy";
        let ret = file_utils::read_file(file.as_str());
        ru_log::info(ret.unwrap().as_str());
    }

    #[test]
    fn test_08_factroy() {
        let ret = file_utils::read_file("./src/rudi/difactroy/rusingle/ru_single");
        ru_log::info(ret.unwrap().as_str());
    }

    #[test]
    fn test_10_find_bean_parse_template() {
        let pt = ditemplate::find_bean_parse_template().unwrap();
        let template = pt.build_single_name("RuSingle");
        ru_log::info(template.as_str());
    }

    #[test]
    fn test_11_parse_all_files() {
        let factry = find_bean_di_factroy().unwrap();
        let mut di_factroy = factry.lock().unwrap();
        di_factroy.parse_all_files(rutils::project_path_src().to_str().unwrap());
        for stru in di_factroy.structs.iter() {
            ru_log::info2("struct file:===", stru.to_json().unwrap().as_str());
        }
    }

    #[test]
    fn test_12_find_dirs() {
        let files = file_utils::find_dir("./src", "ruenc");
        for file in files {
            ru_log::info2("find_dirs:", file.to_str().unwrap());
        }
    }
    //
    #[test]
    fn test_15_find_dirs() {
        let files =
            file_utils::find_dir("C:\\Users\\leijmdas\\.cargo\\registry\\src", "rudi-0.8.3");
        for file in files {
            ru_log::info2("find_dirs:", file.to_str().unwrap());
        }
    }

    #[test]
    fn test_16_parse_template_file() {
        let template = parse_template::ParseTemplate::parse_template_file();
        ru_log::info2("parse_template_file:\r\n", template.as_str());
    }

    #[test]
    fn test_19_parse_all_files() {
        let f = find_bean_di_factroy().unwrap();
        let mut factry = f.lock().unwrap();
        factry.fill_template();
        for stru in factry.get_structs().iter() {
            ru_log::info2("struct file:===", stru.to_json().unwrap());
        }
        ru_log::info2(factry.get_structs().len(), factry.get_self().notShowExist);
        ru_log::info2(factry.get_self().notShowExist, factry.get_template());
    }
    #[test]
    fn test_20() {
        let redisdb = database::find_bean_redis_client().unwrap().get_self();
        ru_log::info2("redisdb:\r\n", redisdb);
    }
    #[test]
    fn test_21_write_filemake_di_all() {
        let ret = file_utils::write_file("e:/opt/1.txt", "dd");
        println!("{:?}", ret);
        assert!(ret.is_ok());
        assert!(file_utils::check_file_exist(&"e:/opt/1.txt".to_string()));
    }

    #[test]
    fn test_22_make_di_one() {
        let diFacty = find_bean_di_factroy().unwrap();

        let ret = diFacty.lock().unwrap().make_di_one_dir("./src", "UsersDao");
        println!("{:?}", ret);
    }
    #[test]
    fn test_24_make_di_one() {
        let diFacty = find_bean_di_factroy().unwrap();

        let ret = diFacty
            .lock()
            .unwrap()
            .make_di_one_dir("./src", "RedisClient");
        println!("{:?}", ret);
    }
    #[test]
    fn test_25_make_di_one() {
        let dao = userdao::find_bean_user_dao().unwrap();
        let ret = dao.execute();
        println!("{:?}", ret);
    }

    #[test]
    fn test_26_make_di_force() {
        let diFacty = find_bean_di_factroy().unwrap();


    }

    #[test]
    fn test_29_make_di() {
        let diFacty = find_bean_di_factroy().unwrap();
        diFacty.lock().unwrap().make_di();
    }

    #[test]
    fn test_31_list_date_format() {
        pub fn local_now2str_rfc3339() -> String {
            Local::now().format("%Y-%m-%dT%H:%M:%S%z").to_string()
        }
        pub fn utc_now2str_rfc3339() -> String {
            Utc::now().format("%Y-%m-%dT%H:%M:%S%z").to_string()
        }

        println!("{}", local_now2str_rfc3339());
        println!("{}", utc_now2str_rfc3339());
    }
    #[test]
    fn test_32_list_di() {}
    #[test]
    fn test_33_single_case() {
        let bean1 = find_bean_di_factroy().unwrap();
        let bean2 = find_bean_di_factroy().unwrap();

        let addr1 = Arc::as_ptr(&bean1);
        let addr2 = Arc::as_ptr(&bean2);
        println!("DiFactroy 地址: {:p} {:p}", addr1, addr2);
        assert_eq!(addr1, addr2);
        println!("bean1=bean2 ? {:?}", addr1 == addr2);
    }
    #[test]
    fn test_34_multi_case() {
        let bean1 = cfgdto::find_bean_gorm().unwrap();
        let bean2 = cfgdto::find_bean_gorm().unwrap();

        let addr1 = Arc::as_ptr(&bean1);
        let addr2 = Arc::as_ptr(&bean2);
        println!("DiFactroy 地址: {:p} {:p}", addr1, addr2);
        assert_ne!(addr1, addr2);
        println!("bean1!=bean2 ? {:?}", addr1 != addr2);
    }

    #[test]
    fn test_35_make_di() {
        let diFacty = find_bean_di_factroy().unwrap();

        diFacty.lock().unwrap().make_di();
    }
    #[test]
    fn test_36_make_di_one() {
        let diFacty = find_bean_di_factroy().unwrap();

        diFacty.lock().unwrap().make_di_one("RuConfig");
    }
    #[test]
    fn test_37_make_di_force_one() {
        let diFacty = find_bean_di_factroy().unwrap();

        diFacty.lock().unwrap().make_di_force_one("RuConfig");
    }
    #[test]
    fn test_38_make_suites() {
        let factory = find_bean_di_factroy().unwrap();
        let mut g = factory.lock().unwrap();
        g.notShowExist = true;
        println!("{:?}", g);
        g.make_suites();
    }
    #[test]
    fn test_40_new() {
        let f = DiFactroy::new();
        assert!(f.template.is_empty());
        assert!(f.template_suite.is_empty());
        assert!(f.structs.is_empty());
        assert!(!f.notShowExist);
    }

    #[test]
    fn test_41_new_mutex() {
        let m = DiFactroy::new_mutex();
        let f = m.lock().unwrap();
        assert!(f.template.is_empty());
        assert!(f.template_suite.is_empty());
        assert!(f.structs.is_empty());
    }

    #[test]
    fn test_42_fill_template() {
        let mut f = DiFactroy::new();
        f.fill_template();
        assert!(!f.template.is_empty());
        ru_log::info2("fill_template result:", f.template.as_str());
    }

    #[test]
    fn test_43_fill_template_suite() {
        let mut f = DiFactroy::new();
        f.fill_template_suite();
        assert!(!f.template_suite.is_empty());
        ru_log::info2("fill_template_suite result:", f.template_suite.as_str());
    }

    #[test]
    fn test_44_get_self() {
        let f = DiFactroy::new();
        let s = f.get_self();
        assert!(s.template.is_empty());
        assert!(s.structs.is_empty());
    }

    #[test]
    fn test_45_get_template() {
        let mut f = DiFactroy::new();
        assert!(f.get_template().is_empty());
        f.fill_template();
        assert!(!f.get_template().is_empty());
    }

    #[test]
    fn test_46_get_structs() {
        let mut f = DiFactroy::new();
        assert!(f.get_structs().is_empty());
        f.parse_all_files(rutils::project_path_src().to_str().unwrap());
        let structs = f.get_structs();
        ru_log::info2("get_structs count:", structs.len());
        assert!(!structs.is_empty());
    }

    #[test]
    fn test_47_build_init() {
        let mut f = DiFactroy::new();
        f.fill_template();
        let stru = didto::StructInfo::new();
        let content = f.build_init(&stru);
        assert!(!content.is_empty());
        ru_log::info2("build_init result:", content.as_str());
    }

    #[test]
    fn test_48_list_di() {
        let factry = find_bean_di_factroy().unwrap();
        let mut f = factry.lock().unwrap();
        f.list_di();
    }

    #[test]
    fn test_49_make_di_pkg() {
        let factry = find_bean_di_factroy().unwrap();
        let mut f = factry.lock().unwrap();
        f.make_di_pkg("rudi");
    }

    #[test]
    fn test_50_make_di_force() {
        let factry = find_bean_di_factroy().unwrap();
        let mut f = factry.lock().unwrap();
        f.make_di_force(rutils::project_path_src().to_str().unwrap());
    }

    #[test]
    fn test_51_make_di_suite() {
        let factry = find_bean_di_factroy().unwrap();
        let mut f = factry.lock().unwrap();
        f.make_di_suite(rutils::project_path_src().to_str().unwrap(), "RuConfig");
    }

    #[test]
    fn test_52_make_di_suites() {
        let factry = find_bean_di_factroy().unwrap();
        let mut f = factry.lock().unwrap();
        f.make_di_suites(rutils::project_path_src().to_str().unwrap());
    }

    #[test]
    fn test_53_build_suite() {
        let mut f = DiFactroy::new();
        f.fill_template_suite();
        let stru = didto::StructInfo::new();
        let content = f.build_suite(&stru);
        ru_log::info2("build_suite result:", content.as_str());
    }

    #[test]
    fn test_54_not_show_exist_default() {
        let f = DiFactroy::new();
        assert!(!f.notShowExist);
        let default_f = DiFactroy::default();
        assert!(!default_f.notShowExist);
    }
    #[test]
    fn test_55_build_suite() {
        let mut f = DiFactroy::new();
        f.make_di();
    }
}