Coder Social home page Coder Social logo

defuture / data-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gongdexing/data-generator

0.0 1.0 0.0 16 KB

基于java开发,强大并且灵活的数据产生神器器,能够根据jobs.xml配置产生各种各样的数据,不用再为测试时没有数据而烦恼了

License: MIT License

Java 100.00%

data-generator's Introduction

DataGenerator

基于java开发的,强大并且灵活的数据产生神器

编译和运行

mvn package

cp jobs.xml ./target/jobs.xml

cd target

mkdir pool

mkdir output

java -jar DataGenerator-0.0.1-SNAPSHOT.jar

查看结果

cat output/test.sql

insert into test (date,author,name,hex,sn) values('2017-02-18','gdx','王五','123456_ae5b92f3c4','123456')
insert into test (date,author,name,hex,sn) values('2017-03-01','gdx','王五','123456_4ec13244c3','123456')
insert into test (date,author,name,hex,sn) values('2017-05-08','gdx','李四','123456_43e192a46f','123456')

基本使用

cat jobs.xml

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <jobs>
        <job>
            <id>1</id>
            <num>3</num>
            <table>test</table>
            <filename>test.sql</filename>
            <detail>
                <author>$var{author}</author>
                <sn>123456</sn>
                <hex>$var{sn}_$rule{hex,10}</hex>
		<name>$pool{name}</name>
		<date>$date{2017-02-01,now,yyyy-MM-dd}</date>
            </detail>
        </job>
    </jobs>
</root>

$date{startDate,endDate,format} 用法

表示按照format格式产生日期,并且日期在 [startDate, endDate] 范围内,startDateendDate 顺序可以颠倒,now表示当前日期

$var{variable} 用法

在上面的 jobs.xml$var{author} 代表引用 author 这个变量,在jar中config.properties中进行了配置

cat config.properties

#内置变量
var.author=gdx
#内置类型
rule.bin=01
rule.oct=01234567
rule.dec=0123456789
rule.hex=0123456789abcdef
rule.letter=abcdefghijklmnopqrstuvwxyz
rule.string=0123456789abcdefghijklmnopqrstuvwxyz
##内置池
pool.name=张三,李四,王五,王八
pool.sex=男,女

可以看到 var.author 被设置为 gdx ,但是 $var{sn} 并没有在config.properties中被定义,这时 $var{sn} 指的是jobs.xml中的 <sn>123456</sn> 标签,即为 123456

$rule{type,len} 用法

$rule{type,len} 中间是没有任何空格的,在jobs.xml中 $rule{hex,10} 代表从 hex 类型的数据中随机取出10个,而 hexconfig.properties 中进行了定义

rule.hex=0123456789abcdef

同样可以使用 $rule{bin,2} 表示随机产生一个十位数

$pool{name} 用法

$pool{name} 用法和 $var{variable} 类似,但是 $pool{name} 还有一种更加高级的用法,比如每次要从上百个证件号码中随机取一个,如果在 config.properties 中定义,会显得非常臃肿,这时可以在 pool 目录中添加一个 ids.csv 文件

ids.csv

  001
  002
  003
  004
  005

jobs.xml 修如下

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <jobs>
        <job>
            <id>1</id>
            <num>3</num>
            <table>test</table>
            <filename></filename>
            <detail>
                <id>$pool{ids.csv}</id>
                <author>$var{author}</author>
                <sn>123456</sn>
                <hex>$var{sn}_$rule{hex,10}</hex>
                <name>$pool{name}</name>
                <sex>$pool{sex}</sex>
            </detail>
        </job>                    
    </jobs>
</root>

再次运行

java -jar DataGenerator-0.0.1-SNAPSHOT.jar

insert into test (author,sex,name,hex,id,sn) values('gdx','','张三','123456_bc5f720d09','002','123456')
insert into test (author,sex,name,hex,id,sn) values('gdx','','李四','123456_461fd2fbdd','005','123456')
insert into test (author,sex,name,hex,id,sn) values('gdx','','王八','123456_f800f13a6f','001','123456')

data-generator's People

Contributors

dexinggong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.