Browse Source

修改单元测试

yingp 7 years ago
parent
commit
afa19fdf0b
18 changed files with 181 additions and 27 deletions
  1. 2 0
      README.md
  2. 6 0
      applications/commons/commons-server/pom.xml
  3. 4 2
      applications/document/document-server/pom.xml
  4. 1 1
      applications/document/document-server/src/test/java/com/usoftchina/saas/document/service/WarehouseTest.java
  5. 3 2
      applications/purchase/purchase-server/pom.xml
  6. 6 5
      applications/storage/storage-server/pom.xml
  7. 26 0
      base-servers/account/account-dto/src/main/java/com/usoftchina/saas/account/constant/AccountType.java
  8. 7 0
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountCompanyMapper.java
  9. 8 0
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountMapper.java
  10. 7 0
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountRoleMapper.java
  11. 8 0
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/AccountService.java
  12. 7 0
      base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/AccountServiceImpl.java
  13. 3 0
      base-servers/account/account-server/src/main/resources/mapper/AccountCompanyMapper.xml
  14. 9 6
      base-servers/account/account-server/src/main/resources/mapper/AccountMapper.xml
  15. 3 0
      base-servers/account/account-server/src/main/resources/mapper/AccountRoleMapper.xml
  16. 57 0
      base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/service/AccountServiceTest.java
  17. 14 11
      base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/service/CompanyServiceTest.java
  18. 10 0
      pom.xml

+ 2 - 0
README.md

@@ -53,6 +53,8 @@
 │  │
 │  ├─framework--------------------------------框架部分
 │  |  ├─core----------------------------------框架基础
+│  |  ├─server-starter------------------------服务启动辅助工具
+│  |  ├─test-starter--------------------------测试启动辅助工具
 │  │
 │  ├─frontend---------------------------------前端
 │  |  ├─web-----------------------------------web前端(vue + element-ui)

+ 6 - 0
applications/commons/commons-server/pom.xml

@@ -59,6 +59,12 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-openfeign</artifactId>
         </dependency>
+        <!-- test -->
+        <dependency>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>test-starter</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

+ 4 - 2
applications/document/document-server/pom.xml

@@ -30,9 +30,11 @@
             <groupId>org.mybatis.spring.boot</groupId>
             <artifactId>mybatis-spring-boot-starter</artifactId>
         </dependency>
+        <!-- test -->
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>test-starter</artifactId>
+            <scope>test</scope>
         </dependency>
         <!-- sleuth -->
         <dependency>

+ 1 - 1
applications/document/document-server/src/test/java/com/usoftchina/saas/document/service/WarehouseTest.java

@@ -27,7 +27,7 @@ public class WarehouseTest {
         map.put("commitid", null);
         map.put("companyid", null);
         map.put("result", null);                      //输出结果
-        warehouseService.callProcedure(map);
+        warehouseService.post(map);
         //输出返回值
         System.out.println("result:" + map.get("result"));
     }

+ 3 - 2
applications/purchase/purchase-server/pom.xml

@@ -32,8 +32,9 @@
 
         <!--test-->
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>test-starter</artifactId>
+            <scope>test</scope>
         </dependency>
 
         <!-- db -->

+ 6 - 5
applications/storage/storage-server/pom.xml

@@ -29,10 +29,6 @@
             <groupId>org.mybatis.spring.boot</groupId>
             <artifactId>mybatis-spring-boot-starter</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-        </dependency>
         <!-- sleuth -->
         <dependency>
             <groupId>org.springframework.cloud</groupId>
@@ -67,7 +63,12 @@
         <dependency>
             <groupId>com.usoftchina.saas</groupId>
             <artifactId>storage-dto</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        <!-- test -->
+        <dependency>
+            <groupId>com.usoftchina.saas</groupId>
+            <artifactId>test-starter</artifactId>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 

+ 26 - 0
base-servers/account/account-dto/src/main/java/com/usoftchina/saas/account/constant/AccountType.java

@@ -0,0 +1,26 @@
+package com.usoftchina.saas.account.constant;
+
+/**
+ * @author yingp
+ * @date 2018/10/23
+ */
+public enum AccountType {
+    /**
+     * 管理员
+     */
+    ADMIN(0),
+    /**
+     * 普通用户
+     */
+    NORMAL(1);
+
+    private final int type;
+
+    AccountType(int type) {
+        this.type = type;
+    }
+
+    public int getType() {
+        return type;
+    }
+}

+ 7 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountCompanyMapper.java

@@ -24,4 +24,11 @@ public interface AccountCompanyMapper {
      * @param companyId
      */
     void delete(@Param("accountId") Long accountId, @Param("companyId") Long companyId);
+
+    /**
+     * 按账户删除
+     *
+     * @param accountId
+     */
+    void deleteByAccountId(@Param("accountId") Long accountId);
 }

+ 8 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountMapper.java

@@ -47,4 +47,12 @@ public interface AccountMapper {
      * @return
      */
     Account selectByEmail(@Param("email") String email);
+
+    /**
+     * 删除
+     *
+     * @param id
+     * @return
+     */
+    int deleteByPrimaryKey(@Param("id") Long id);
 }

+ 7 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/AccountRoleMapper.java

@@ -23,4 +23,11 @@ public interface AccountRoleMapper {
      * @param roleId
      */
     void delete(@Param("accountId") Long accountId, @Param("roleId") Long roleId);
+
+    /**
+     * 按账户删除
+     *
+     * @param accountId
+     */
+    void deleteByAccountId(@Param("accountId") Long accountId);
 }

+ 8 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/AccountService.java

@@ -89,4 +89,12 @@ public interface AccountService {
      */
     void unbindRole(Long accountId, Long roleId);
 
+    /**
+     * 删除
+     *
+     * @param id
+     * @return
+     */
+    boolean removeByPrimaryKey(Long id);
+
 }

+ 7 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/AccountServiceImpl.java

@@ -81,4 +81,11 @@ public class AccountServiceImpl implements AccountService {
     public void unbindRole(Long accountId, Long roleId) {
         accountRoleMapper.delete(accountId, roleId);
     }
+
+    @Override
+    public boolean removeByPrimaryKey(Long id) {
+        accountRoleMapper.deleteByAccountId(id);
+        accountCompanyMapper.deleteByAccountId(id);
+        return accountMapper.deleteByPrimaryKey(id) > 0;
+    }
 }

+ 3 - 0
base-servers/account/account-server/src/main/resources/mapper/AccountCompanyMapper.xml

@@ -7,4 +7,7 @@
     <delete id="delete">
         delete from ac_account_company where account_id=#{accountId} and companyId=#{companyId}
     </delete>
+    <delete id="deleteByAccountId" parameterType="java.lang.Long">
+        delete from ac_account_company where account_id=#{accountId}
+    </delete>
 </mapper>

+ 9 - 6
base-servers/account/account-server/src/main/resources/mapper/AccountMapper.xml

@@ -16,13 +16,13 @@
         <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
     </resultMap>
     <sql id="baseColumns">
-        id,company_id,username,password,salt,realname,email,mobile,type,creator_id,create_time,updater_id,update_time
+        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(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})
+        #{creatorId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updaterId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP})
     </insert>
     <insert id="insertSelective" parameterType="com.usoftchina.saas.account.po.Account">
         insert into ac_account
@@ -48,16 +48,16 @@
             <if test="type != null">
                 type,
             </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>
@@ -106,4 +106,7 @@
     <select id="selectByEmail" parameterType="java.lang.String" resultMap="BaseResultMap">
         select <include refid="baseColumns"/> from ac_account where email=#{email}
     </select>
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+        delete from ac_account where id=#{id}
+    </delete>
 </mapper>

+ 3 - 0
base-servers/account/account-server/src/main/resources/mapper/AccountRoleMapper.xml

@@ -7,4 +7,7 @@
     <delete id="delete">
         delete from ac_account_role where account_id=#{accountId} and role_id=#{roleId}
     </delete>
+    <delete id="deleteByAccountId" parameterType="java.lang.Long">
+        delete from ac_account_role where account_id=#{accountId}
+    </delete>
 </mapper>

+ 57 - 0
base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/service/AccountServiceTest.java

@@ -0,0 +1,57 @@
+package com.usoftchina.saas.account.service;
+
+import com.usoftchina.saas.account.constant.AccountType;
+import com.usoftchina.saas.account.po.Account;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@FixMethodOrder(MethodSorters.JVM)
+public class AccountServiceTest {
+
+    @Autowired
+    private AccountService accountService;
+
+    private final String mobile = "13500000000";
+
+    private final String password = "select111***";
+
+    @Test
+    public void save() throws Exception {
+        Account account = new Account();
+        account.setMobile(mobile);
+        account.setUsername(mobile);
+        account.setSalt(mobile);
+        account.setEmail("mayun@mxhichina.com");
+        account.setPassword(accountService.getEncryptedPassword(password, account.getSalt()));
+        account.setRealname("Jack Ma");
+        account.setType(AccountType.ADMIN.getType());
+
+        boolean saved = accountService.save(account);
+        Assert.assertTrue(saved);
+    }
+
+    @Test
+    public void checkPwd() throws Exception {
+        Account account = accountService.findByMobile(mobile);
+        Assert.assertNotNull(account);
+        boolean checked = accountService.checkPwd(account, password);
+        Assert.assertTrue(checked);
+    }
+
+    @Test
+    public void removeByPrimaryKey() throws Exception {
+        Account account = accountService.findByMobile(mobile);
+        Assert.assertNotNull(account);
+        boolean removed = accountService.removeByPrimaryKey(account.getId());
+        Assert.assertTrue(removed);
+    }
+
+}

+ 14 - 11
base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/test/CompanyTest.java → base-servers/account/account-server/src/test/java/com/usoftchina/saas/account/service/CompanyServiceTest.java

@@ -1,10 +1,11 @@
-package com.usoftchina.saas.account.test;
+package com.usoftchina.saas.account.service;
 
 import com.usoftchina.saas.account.po.Company;
-import com.usoftchina.saas.account.service.CompanyService;
-import org.junit.After;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
@@ -15,7 +16,8 @@ import org.springframework.test.context.junit4.SpringRunner;
  */
 @RunWith(SpringRunner.class)
 @SpringBootTest
-public class CompanyTest {
+@FixMethodOrder(MethodSorters.JVM)
+public class CompanyServiceTest {
 
     @Autowired
     private CompanyService companyService;
@@ -23,21 +25,22 @@ public class CompanyTest {
     private final String name = "spring.test";
 
     @Test
-    public void addCompany() {
+    public void save() {
         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);
+        boolean saved = companyService.save(company);
+        Assert.assertTrue(saved);
     }
 
-    @After
-    public void deleteCompany() {
+    @Test
+    public void removeByPrimaryKey() {
         Company company = companyService.findByName(name);
-        if (null != company) {
-            companyService.removeByPrimaryKey(company.getId());
-        }
+        Assert.assertNotNull(company);
+        boolean removed = companyService.removeByPrimaryKey(company.getId());
+        Assert.assertTrue(removed);
     }
 }

+ 10 - 0
pom.xml

@@ -281,6 +281,16 @@
                 <artifactId>document-dto</artifactId>
                 <version>${project.release.version}</version>
             </dependency>
+            <dependency>
+                <groupId>com.usoftchina.saas</groupId>
+                <artifactId>storage-api</artifactId>
+                <version>${project.release.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.usoftchina.saas</groupId>
+                <artifactId>storage-dto</artifactId>
+                <version>${project.release.version}</version>
+            </dependency>
             <dependency>
                 <groupId>com.usoftchina.saas</groupId>
                 <artifactId>test-starter</artifactId>