Browse Source

测试辅助工具

yingp 7 years ago
parent
commit
cbb1e9eefd
18 changed files with 235 additions and 94 deletions
  1. 6 0
      base-servers/account/account-server/pom.xml
  2. 2 0
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/AccountApplication.java
  3. 6 6
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/CompanyMapper.java
  4. 0 24
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/po/Resources.java
  5. 6 6
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/CompanyService.java
  6. 4 4
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/CompanyServiceImpl.java
  7. 17 2
      base-servers/account/account-server/src/main/resources/application.yml
  8. 4 1
      base-servers/account/account-server/src/main/resources/config/application-docker.yml
  9. 4 11
      base-servers/account/account-server/src/main/resources/mapper/AccountMapper.xml
  10. 14 15
      base-servers/account/account-server/src/main/resources/mapper/CompanyMapper.xml
  11. 43 0
      base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/test/CompanyTest.java
  12. 1 1
      base-servers/auth/auth-server/src/main/resources/application.yml
  13. 1 0
      framework/pom.xml
  14. 25 0
      framework/test-starter/pom.xml
  15. 18 0
      framework/test-starter/src/main/java/com.usoftchina.saas.test/DefaultContextHolderListener.java
  16. 3 0
      framework/test-starter/src/main/resources/META-INF/spring.factories
  17. 5 0
      pom.xml
  18. 76 24
      script/mysql/init/account.sql

+ 6 - 0
base-servers/account/account-server/pom.xml

@@ -43,6 +43,12 @@
             <groupId>net.logstash.logback</groupId>
             <artifactId>logstash-logback-encoder</artifactId>
         </dependency>
+        <!-- test -->
+        <dependency>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>test-starter</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 2 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/AccountApplication.java

@@ -1,5 +1,6 @@
 package com.usoftchina.saas.account;
 
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @SpringBootApplication
 @EnableEurekaClient
 @EnableTransactionManagement
+@MapperScan(basePackages = "com.usoftchina.saas.account.mapper")
 public class AccountApplication {
     public static void main(String[] args) {
         SpringApplication.run(AccountApplication.class, args);

+ 6 - 6
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/CompanyMapper.java

@@ -44,18 +44,18 @@ public interface CompanyMapper {
     Company selectByBusinessCode(@Param("businessCode") String businessCode);
 
     /**
-     * 按二级域名查找
+     * 按个人账户ID查找全部绑定企业基础信息
      *
-     * @param domain
+     * @param accountId
      * @return
      */
-    Company selectByDomain(@Param("domain") String domain);
+    List<CompanyBaseVO> selectBaseByAccountId(@Param("accountId") Long accountId);
 
     /**
-     * 按个人账户ID查找全部绑定企业基础信息
+     * 删除
      *
-     * @param accountId
+     * @param id
      * @return
      */
-    List<CompanyBaseVO> selectBaseByAccountId(@Param("accountId") Long accountId);
+    int deleteByPrimaryKey(@Param("id") Long id);
 }

+ 0 - 24
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/po/Resources.java

@@ -37,14 +37,6 @@ public class Resources extends CommonBaseEntity implements Serializable {
      * 资源请求方式 POST/GET/PUT/DELETE
      */
     private String method;
-    /**
-     * 菜单打开方式 _self,_top,_blank,_parent
-     */
-    private String target;
-    /**
-     * 菜单图标
-     */
-    private String icon;
 
     /**
      * 排序
@@ -96,22 +88,6 @@ public class Resources extends CommonBaseEntity implements Serializable {
         this.method = method;
     }
 
-    public String getTarget() {
-        return target;
-    }
-
-    public void setTarget(String target) {
-        this.target = target;
-    }
-
-    public String getIcon() {
-        return icon;
-    }
-
-    public void setIcon(String icon) {
-        this.icon = icon;
-    }
-
     public Integer getOrderNum() {
         return orderNum;
     }

+ 6 - 6
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/CompanyService.java

@@ -35,18 +35,18 @@ public interface CompanyService {
     Company findByBusinessCode(String businessCode);
 
     /**
-     * 按二级域名查
+     * 按个人账户查找全部绑定企业
      *
-     * @param domain
+     * @param accountId
      * @return
      */
-    Company findByDomain(String domain);
+    List<CompanyBaseVO> findBaseByAccountId(Long accountId);
 
     /**
-     * 按个人账户查找全部绑定企业
+     * 删除
      *
-     * @param accountId
+     * @param id
      * @return
      */
-    List<CompanyBaseVO> findBaseByAccountId(Long accountId);
+    boolean removeByPrimaryKey(Long id);
 }

+ 4 - 4
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/CompanyServiceImpl.java

@@ -43,12 +43,12 @@ public class CompanyServiceImpl implements CompanyService{
     }
 
     @Override
-    public Company findByDomain(String domain) {
-        return companyMapper.selectByDomain(domain);
+    public List<CompanyBaseVO> findBaseByAccountId(Long accountId) {
+        return companyMapper.selectBaseByAccountId(accountId);
     }
 
     @Override
-    public List<CompanyBaseVO> findBaseByAccountId(Long accountId) {
-        return companyMapper.selectBaseByAccountId(accountId);
+    public boolean removeByPrimaryKey(Long id) {
+        return companyMapper.deleteByPrimaryKey(id) > 0;
     }
 }

+ 17 - 2
base-servers/account/account-server/src/main/resources/application.yml

@@ -7,8 +7,23 @@ spring:
     user:
       name: admin
       password: select111***
+  rabbitmq:
+    host: 192.168.0.176
+    port: 5672
+    virtual-host: dev
+    username: saas
+    password: select123***
+  zipkin:
+    sender:
+      type: rabbit
+    locator:
+      discovery:
+        enabled: true
+  sleuth:
+    sampler:
+      probability: 1.0
   datasource:
-    driver-class-name: com.mysql.jdbc.Driver
+    driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://192.168.253.12:3306/saas_account?characterEncoding=utf-8&useSSL=false
     username: root
     password: select111***
@@ -31,7 +46,7 @@ eureka:
   client:
     registryFetchIntervalSeconds: 5
     serviceUrl:
-      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@192.168.0.181:8500/eureka/
+      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@192.168.0.181:8510/eureka/
 server:
   port: 8580
   tomcat:

+ 4 - 1
base-servers/account/account-server/src/main/resources/config/application-docker.yml

@@ -4,4 +4,7 @@ eureka:
     prefer-ip-address: false
   client:
     serviceUrl:
-      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@saas-eureka-server:8500/eureka/
+      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@saas-eureka-server:8500/eureka/
+spring:
+  rabbitmq:
+    virtual-host: docker

+ 4 - 11
base-servers/account/account-server/src/main/resources/mapper/AccountMapper.xml

@@ -3,14 +3,13 @@
 <mapper namespace="com.usoftchina.saas.account.mapper.AccountMapper">
     <resultMap id="BaseResultMap" type="com.usoftchina.saas.account.po.Account">
         <id column="id" jdbcType="BIGINT" property="id"/>
-        <result column="company_id" jdbcType="BIGINT" property="companyId"/>
         <result column="username" jdbcType="VARCHAR" property="username"/>
         <result column="password" jdbcType="VARCHAR" property="password"/>
         <result column="salt" jdbcType="VARCHAR" property="salt"/>
         <result column="realname" jdbcType="VARCHAR" property="realname"/>
         <result column="email" jdbcType="VARCHAR" property="email"/>
         <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
-        <result column="type" jdbcType="INT" property="type"/>
+        <result column="type" jdbcType="INTEGER" property="type"/>
         <result column="creator_id" jdbcType="BIGINT" property="creatorId"/>
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
         <result column="updater_id" jdbcType="BIGINT" property="updaterId"/>
@@ -20,17 +19,14 @@
         id,company_id,username,password,salt,realname,email,mobile,type,creator_id,create_time,updater_id,update_time
     </sql>
     <insert id="insert" parameterType="com.usoftchina.saas.account.po.Account">
-        insert into ac_account(company_id,username,password,salt,realname,email,mobile,type,creator_id,create_time,updater_id,update_time)
-        values (#{companyId,jdbcType=BIGINT}, #{username,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR},
-        #{realname,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{type,jdbcType=INT},
+        insert into ac_account(username,password,salt,realname,email,mobile,type,creator_id,create_time,updater_id,update_time)
+        values (#{username,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR}, #{salt,jdbcType=VARCHAR},
+        #{realname,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
         #{createTime,jdbcType=TIMESTAMP}, #{updaterId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP})
     </insert>
     <insert id="insertSelective" parameterType="com.usoftchina.saas.account.po.Account">
         insert into ac_account
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="companyId != null">
-                company_id,
-            </if>
             <if test="username != null">
                 username,
             </if>
@@ -66,9 +62,6 @@
             </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="companyId != null">
-                #{companyId,jdbcType=BIGINT},
-            </if>
             <if test="username != null">
                 #{username,jdbcType=VARCHAR},
             </if>

+ 14 - 15
base-servers/account/account-server/src/main/resources/mapper/CompanyMapper.xml

@@ -6,7 +6,6 @@
         <result column="name" jdbcType="VARCHAR" property="name"/>
         <result column="business_code" jdbcType="VARCHAR" property="businessCode"/>
         <result column="address" jdbcType="VARCHAR" property="address"/>
-        <result column="domain" jdbcType="VARCHAR" property="domain"/>
         <result column="creator_id" jdbcType="BIGINT" property="creatorId"/>
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
         <result column="updater_id" jdbcType="BIGINT" property="updaterId"/>
@@ -18,12 +17,12 @@
         <result column="logo_url" jdbcType="VARCHAR" property="logoUrl"/>
     </resultMap>
     <sql id="baseColumns">
-        id,name,business_code,address,domain,creator_id,create_time,updater_id,update_time
+        id,name,business_code,address,creator_id,create_time,updater_id,update_time
     </sql>
     <insert id="insert" parameterType="com.usoftchina.saas.account.po.Company">
-        insert into ac_company(name, business_code, address, domain, creator_id, create_time, updater_id, update_time)
+        insert into ac_company(name, business_code, address, logo_url, creator_id, create_time, updater_id, update_time)
         values (#{name,jdbcType=VARCHAR}, #{businessCode,jdbcType=VARCHAR},
-        #{address,jdbcType=VARCHAR}, #{domain,jdbcType=VARCHAR}, #{creatorId,jdbcType=BIGINT},
+        #{address,jdbcType=VARCHAR}, #{logoUrl,jdbcType=VARCHAR}, #{creatorId,jdbcType=BIGINT},
         #{createTime,jdbcType=TIMESTAMP}, #{updaterId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP})
     </insert>
     <insert id="insertSelective" parameterType="com.usoftchina.saas.account.po.Company">
@@ -38,19 +37,19 @@
             <if test="address != null">
                 address,
             </if>
-            <if test="domain != null">
-                domain,
+            <if test="logoUrl != null">
+                logo_url,
             </if>
-            <if test="creator_id != null">
+            <if test="creatorId != null">
                 creator_id,
             </if>
-            <if test="create_time != null">
+            <if test="createTime != null">
                 create_time,
             </if>
-            <if test="updater_id != null">
+            <if test="updaterId != null">
                 updater_id,
             </if>
-            <if test="update_time != null">
+            <if test="updateTime != null">
                 update_time,
             </if>
         </trim>
@@ -64,8 +63,8 @@
             <if test="address != null">
                 #{address,jdbcType=VARCHAR},
             </if>
-            <if test="domain != null">
-                #{domain,jdbcType=VARCHAR},
+            <if test="logoUrl != null">
+                #{logoUrl,jdbcType=VARCHAR},
             </if>
             <if test="creatorId != null">
                 #{creatorId,jdbcType=BIGINT},
@@ -87,11 +86,11 @@
     <select id="selectByBusinessCode" parameterType="java.lang.String" resultMap="FullResultMap">
         select <include refid="baseColumns"/> from ac_company where business_code=#{businessCode}
     </select>
-    <select id="selectByDomain" parameterType="java.lang.String" resultMap="FullResultMap">
-        select <include refid="baseColumns"/> from ac_company where domain=#{domain}
-    </select>
     <select id="selectBaseByAccountId" parameterType="java.lang.Long" resultMap="BaseResultMap">
         select ac_company.id,ac_company.name,ac_company.logo_url from ac_account_company,ac_company
         where ac_account_company.company_id=ac_company.id and ac_account_company.account_id=#{accountId}
     </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+        delete from ac_company where id=#{id}
+    </delete>
 </mapper>

+ 43 - 0
base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/test/CompanyTest.java

@@ -0,0 +1,43 @@
+package com.usoftchina.saas.account.test;
+
+import com.usoftchina.saas.account.po.Company;
+import com.usoftchina.saas.account.service.CompanyService;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+/**
+ * @author yingp
+ * @date 2018/10/22
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class CompanyTest {
+
+    @Autowired
+    private CompanyService companyService;
+
+    private final String name = "spring.test";
+
+    @Test
+    public void addCompany() {
+        Company company = new Company();
+        company.setName(name);
+        company.setBusinessCode("T00000000000000000");
+        company.setAddress("深圳市南山区粤海街道高新技术产业园科技南五路英唐大厦六楼");
+        company.setLogoUrl("https://co-image.qichacha.com/CompanyImage/104eb3c232bbac93393a5e204d6a47d1.jpg?x-oss-process=style/qcc_cmp");
+
+        companyService.save(company);
+    }
+
+    @After
+    public void deleteCompany() {
+        Company company = companyService.findByName(name);
+        if (null != company) {
+            companyService.removeByPrimaryKey(company.getId());
+        }
+    }
+}

+ 1 - 1
base-servers/auth/auth-server/src/main/resources/application.yml

@@ -26,7 +26,7 @@ eureka:
   client:
     registryFetchIntervalSeconds: 5
     serviceUrl:
-      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@127.0.0.1:8500/eureka/
+      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@192.168.0.181:8510/eureka/
 server:
   port: 8580
   tomcat:

+ 1 - 0
framework/pom.xml

@@ -15,6 +15,7 @@
     <modules>
         <module>core</module>
         <module>server-starter</module>
+        <module>test-starter</module>
     </modules>
 
 </project>

+ 25 - 0
framework/test-starter/pom.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>framework</artifactId>
+        <groupId>com.usoftchina.saas</groupId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>test-starter</artifactId>
+    <description>test starter</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>core</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 18 - 0
framework/test-starter/src/main/java/com.usoftchina.saas.test/DefaultContextHolderListener.java

@@ -0,0 +1,18 @@
+package com.usoftchina.saas.test;
+
+import com.usoftchina.saas.context.BaseContextHolder;
+import org.springframework.test.context.TestContext;
+import org.springframework.test.context.support.AbstractTestExecutionListener;
+
+/**
+ * @author yingp
+ * @date 2018/10/22
+ */
+public class DefaultContextHolderListener extends AbstractTestExecutionListener {
+    @Override
+    public void beforeTestClass(TestContext testContext) throws Exception {
+        // 设置测试环境默认用户
+        BaseContextHolder.setCompanyId(1);
+        BaseContextHolder.setUserId(1);
+    }
+}

+ 3 - 0
framework/test-starter/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,3 @@
+# Test Execution Listeners
+org.springframework.test.context.TestExecutionListener=\
+com.usoftchina.saas.test.DefaultContextHolderListener

+ 5 - 0
pom.xml

@@ -281,6 +281,11 @@
                 <artifactId>document-dto</artifactId>
                 <version>${project.release.version}</version>
             </dependency>
+            <dependency>
+                <groupId>com.usoftchina.saas</groupId>
+                <artifactId>test-starter</artifactId>
+                <version>${project.release.version}</version>
+            </dependency>
             <!-- file upload -->
             <dependency>
                 <groupId>io.github.openfeign.form</groupId>

+ 76 - 24
script/mysql/init/account.sql

@@ -2,29 +2,81 @@ CREATE DATABASE `saas_account` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_c
 use `saas_account`;
 
 create table `ac_company` (
-id int unsigned primary key not null auto_increment,
-name varchar(500) not null,
-business_code varchar(100),
-address varchar(500),
-domain varchar(100) not null,
-creator_id int unsigned,
-create_time datetime,
-updater_id int unsigned,
-update_time datetime
-);
+  id int unsigned primary key not null auto_increment,
+  name varchar(500) not null comment '名称',
+  business_code varchar(100) comment '商业登记证号',
+  address varchar(500) comment '注册地址',
+  logo_url varchar(500) comment 'Logo',
+  creator_id int unsigned,
+  create_time datetime,
+  updater_id int unsigned,
+  update_time datetime
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='公司';
 
 create table `ac_account` (
-id int unsigned primary key not null auto_increment,
-username varchar(100) not null,
-password varchar(100) not null,
-salt varchar(100) not null,
-realname varchar(100) not null,
-email varchar(100) not null,
-mobile varchar(100) not null,
-type int,
-company_id int unsigned not null,
-creator_id int unsigned,
-create_time datetime,
-updater_id int unsigned,
-update_time datetime
-);
+  id int unsigned primary key not null auto_increment,
+  username varchar(100) not null comment '账号',
+  password varchar(100) not null comment '加密密码',
+  salt varchar(100) not null comment '加密盐值',
+  realname varchar(100) comment '真实姓名',
+  email varchar(100) comment '邮箱',
+  mobile varchar(100) not null comment '手机号',
+  type int comment '账户类型 0, 1',
+  creator_id int unsigned,
+  create_time datetime,
+  updater_id int unsigned,
+  update_time datetime
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='个人账户';
+
+create table `ac_account_company` (
+  company_id int unsigned,
+  account_id int unsigned
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='账户绑定企业';
+
+create table `ac_role` (
+  id int unsigned primary key not null auto_increment,
+  code varchar(100) not null comment '编号',
+  name varchar(300) not null comment '名称',
+  description varchar(1000) comment '描述',
+  company_id int unsigned,
+  creator_id int unsigned,
+  create_time datetime,
+  updater_id int unsigned,
+  update_time datetime
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色';
+
+create table `ac_account_role` (
+  account_id int unsigned,
+  role_id int unsigned
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='账户绑定角色';
+
+create table `ac_resource` (
+  id int unsigned primary key not null auto_increment,
+  code varchar(100) not null comment '编号',
+  name varchar(300) not null comment '名称',
+  description varchar(1000) comment '描述',
+  type varchar(100) comment '类型 MENU,BUTTON,API',
+  url varchar(300) comment 'URL',
+  method varchar(10) comment 'Http Method: POST/GET/PUT/DELETE',
+  order_num int,
+  company_id int unsigned,
+  creator_id int unsigned,
+  create_time datetime,
+  updater_id int unsigned,
+  update_time datetime
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色';
+
+create table `ac_role_resource` (
+  role_id int unsigned,
+  resource_id int unsigned
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色绑定资源';
+
+insert into ac_account(id,username,password,salt,realname,email,mobile,type,
+                       creator_id,create_time,updater_id,update_time)
+values (1,'18888888888','3e8451e274a8ee847872194e584a4145','18888888888','Administrator',
+          'admin@usoftchina.com', '18888888888', 0, 1, now(), 1, now());
+
+insert into ac_company(name, business_code, address, logo_url, creator_id, create_time, updater_id, update_time)
+values ('测试账套', '000000000000000000','深圳市南山区粤海街道高新技术产业园科技南五路英唐大厦六楼',
+        'https://co-image.qichacha.com/CompanyImage/104eb3c232bbac93393a5e204d6a47d1.jpg?x-oss-process=style/qcc_cmp',
+        1, now(), 1, now());