Skip to content

#12.25iMobile 后端_数量及ut测试

环境:

后端:
CloudLicenseManagementResource.java 下的addCloudLicenses          新增许可接口
LicenseComponentImpl.java									   许可实现
License.java  
我的允许可
CloudLicenseResource.java

前端:
CloudLicenseAddManageView.js      27行                              点击添加事件
CloudLicenseModel.js											前端云许可对象

数据库:

license数据库  _user表
新增一条记录
592865 null null 1210738588@qq.com null 17783116571 2019-12-23 16:42:04

因为我的云允许分配许可时:
更新:
_license 表 status 1未分配,2已分配;allocationUserId  分配的用户id
插入:
_license_status_log 日志表
没有事务
_license_status_log 表外键关联_user表,_user表id没有则外键error,so 需要插入一条记录。
OLSetting

D:\supermap\20191023online_price\ideaworksapce\MonkeyKing\modules\base-modules\cloudmgn-web\WEB-INF\cloudmanagementsetting.properties

##一、项目

二种方式:

	InsertUserLicensesParam
	/**
     * 一个订单对应了多套许可
     * (必传)
     */
     private List<License> licenses = null;
     
     1.	搞一个license包装类 新增numbers,包含license对象   实现一个订单对应了多套许可
     2.	去掉list ,新增numbers

##第一种:(可能性小,无需求)

1.前端允许可对象新增"数量"字段

js
1. CloudLicenseModel.js

define([
    "baseTypes/Class"
], function(SuperMapOnline) {
    "use strict";
    SuperMapOnline.Model.CloudLicenseModel = SuperMapOnline.Class({
        userId : null,
        serial : null,
        status : 0,
        permanent : false,
        days : 0,
        productId : null,
        moduleCode : null,
        remarks : null,
        //新增数量
        numbers:null,
        // 构造函数
        initialize : function() {
            // nothing
        },
        setCloudLicense : function(cloudLicense) {
            this.userId = cloudLicense.userId;
            this.serial = cloudLicense.serial;
            this.status = cloudLicense.status;
            this.permanent = cloudLicense.permanent;
            this.days = cloudLicense.days;
            this.productId = cloudLicense.productId;
            this.moduleCode = cloudLicense.moduleCode;
            this.remarks = cloudLicense.remarks;
            //新增数量
            this.numbers = cloudLicense.numbers;
        }
    });
  return SuperMapOnline;
});
js
2.	CloudLicenseAddManageView.js

86行
//获取选项框值
function getNumbers() {
            return $("#licNumInfo").val();
        }
        
//获取值
function updateTimeLicenseModel() {
            var cloudLicense = {
                    userId : getUserId(),
                    permanent : true,
                    productId : getProductId(),
                    moduleCode : getModuleCodes(),
                    remarks : getRemarks(),
                    //新增数量
                    numbers : getNumbers(),
            }
            cloudLicenseModel.setCloudLicense(cloudLicense);
        }

2.后端接收对象新增"数量"字段

1.	InsertUserLicensesParam 允许可接收对象
    /**
    * 一个订单对应了多套许可
    * (必传)
    */
	private List<License> licenses = null;    允许可对象

问题:
	list?; 订单是什么情况? ;管理添加只会传一个License对象!
2.	License 新增

##第二种: (使用第二种)

###1.前端允许可对象新增"数量"字段

js
CloudLicenseAddManageView.js
159行
var cloudLicenseParam = {
                    userIdOrMail: getUserId(),
    			   //新增数量
                    numbers : getNumbers(),
    			   //去掉素组 licenses: [cloudLicenseModel]
                    license: cloudLicenseModel
            };
 86-88           
 function getNumbers() {
            return $("#licNumInfo").val();
        }

###2.后端接收对象新增"数量"字段

####1.InsertUserLicensesParam

java
InsertUserLicensesParam

1.	新增数量字段
/**
 *数量
 */
 private Integer numbers;

2.	去掉List,改为一个订单对应一套许可
/**
     * 一个订单对应了多套许可
     * (必传)
     */
    private List<License> licenses = null;

	private License license = null;

2.LicenseComponentImpl.java

###3.test修改测试用例

####1.InsertUserLicensesParamTest包装类

java
InsertUserLicensesParamTest.java

@Test
	public void test() {
		InsertUserLicensesParam insertLicenseParam=new InsertUserLicensesParam();
//		去掉list
//		List<License> licenses=null;
//		新增
		License license = null;
		insertLicenseParam.setLicense(license);
		insertLicenseParam.setSn("112ad");
		insertLicenseParam.setUserIdOrMail("123456");
//		新增数量
		insertLicenseParam.setNumbers(2);
//		去掉
//		Assert.assertEquals(insertLicenseParam.getLicenses(), licenses);
//		新增
		Assert.assertEquals(insertLicenseParam.getLicense(), license);
		Assert.assertEquals(insertLicenseParam.getSn(), "112ad");
		Assert.assertEquals(insertLicenseParam.getUserIdOrMail(), "123456");
//		新增数量
		Assert.assertEquals(Long.valueOf(insertLicenseParam.getNumbers()), Long.valueOf(2));
	}

2.CloudLicenseManagementResourceTest.java

java
testAddCloudLicenses方法

@Test
    public void testAddCloudLicenses() {
        InsertUserLicensesParam param = new InsertUserLicensesParam();
//        List<License> licenses = new ArrayList<License>();
        License license = new License();
        license.setDays(10);
        license.setModuleCode("1009");
        license.setProductId("1001080");
        license.setPermanent(false);
//        licenses.add(license);
//        param.setLicenses(licenses);
//		新增
        param.setLicense(license);
        param.setUserIdOrMail("yangwanyu@supermap.com");
        param.setNumbers(1);
        LicenseResult value = new LicenseResult();
        value.setCode(0);
        Mockito.when(licenseComponent.insertUserLicenses(param)).thenReturn(value);
        LicenseResult result = resource.addCloudLicenses(licenseComponent, param);
        Assert.assertEquals(value, result);
    }
java
@Test
    public void testAddCloudLicenses_UserId_IsEmpty() {
        InsertUserLicensesParam param = new InsertUserLicensesParam();
//        List<License> licenses = new ArrayList<License>();
        License license = new License();
        license.setDays(10);
        license.setModuleCode("1009");
        license.setProductId("1001080");
        license.setPermanent(false);
//        licenses.add(license);
//        param.setLicenses(licenses);
        //新增
        param.setLicense(license);
        param.setUserIdOrMail("");
        param.setNumbers(2);
        LicenseResult result = resource.addCloudLicenses(licenseComponent, param);
        Assert.assertEquals(LicenseResourceConfig.USERID_IS_NULL, result.getCode());
    }

3.CloudLicenseResourceTest.java

java

testInsertUserLicenses方法
@Test
    public void testInsertUserLicenses() {
        InsertUserLicensesParam param = new InsertUserLicensesParam();
//        去掉list
        List<License> licenses = new ArrayList<License>();
        License license = new License();
        license.setDays(10);
        license.setModuleCode("1009");
        license.setProductId("1001080");
        license.setPermanent(false);
        licenses.add(license);
//        param.setLicenses(licenses);
//		新增set
        param.setLicense(license);
        LicenseResult value = new LicenseResult();
        value.setCode(0);
        Mockito.when(liccompont.insertUserLicenses(param)).thenReturn(value);
        String userIdOrMail = "yangwanyu@supermap.com";
        param.setUserIdOrMail(userIdOrMail);
        LicenseResult result = resource.insertUserLicenses(param, liccompont);
        Assert.assertEquals(value, result);
    }

4.LicenseComponentImplTest.java

java
testInsertLicenses方法
@Test
    public void testInsertLicenses() {

        InsertManagerLicensesParam param = new InsertManagerLicensesParam();
        LicenseResult result = impl.insertUserLicenses(param);

        Assert.assertTrue(LicenseResourceConfig.NO_LOGIN == result.getCode());

        param.setUserIdOrMail(managerMail);
        param.setSn("55b26fd6-beb4-9999-9c8f-qqqqfc127fe7");
        param.setNumbers(1);
        result = impl.insertUserLicenses(param);
        Assert.assertTrue(LicenseResourceConfig.LICENSE_NULL == result.getCode());

        License lic = new License();
        param.setLicense(lic);

        SsoUser managerSsoUser = new SsoUser();
        managerSsoUser.setEmail(managerMail);
        managerSsoUser.setUserid(managerId);
        Mockito.when(ssoUserServer.getSsoUser(managerMail)).thenReturn(managerSsoUser);
        result = impl.insertUserLicenses(param);
        Assert.assertTrue(LicenseResourceConfig.NO_USABLELICENSE == result.getCode());

        License license = new License();
        license.setDays(90);
        license.setProductId("1001078");
        license.setModuleCode("1009,1010");
        param.setLicense(license);
        result = impl.insertUserLicenses(param);
        Assert.assertTrue(LicenseResourceConfig.USERLICENSE_NULL == result.getCode());

        Product product = new Product();
        product.setType("50000");
        product.setVersion("8C");
        Mockito.when(productDao.selectProduct(license.getProductId())).thenReturn(product);
        result = impl.insertUserLicenses(param);
        Assert.assertTrue(LicenseResourceConfig.SUCCEED == result.getCode());
    }

####5.iportal最大连接数

java
ProductWithMaxloginsEnum
	   /**
         *  iportal标准版默认100
         */
        STANDARD(creatUnmodifiableProducts("1001067", "1001078", "9004001","10004001"), 100),
        /**
         * iportal专业版默认200
         */
        PROFESSIONAL(creatUnmodifiableProducts("1001068", "1001079", "9004002","10004002"), 200),
        /**
         * IPORTAL高级版默认500
         */
        ADVANCED(creatUnmodifiableProducts("1001069", "1001080", "9004003","10004003"), 500);

###4.配置事务

xml
cloudLicenseBean.xml 

<!-- 事务管理器 -->
  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="ilicensedataSource"></property>
  </bean>
  <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>

##二、暂时去掉

  1. 购买页面,imobile数量可甜
        if (productId === "10008001" || productId === "10008002") {
            //此处用户iMobile 选择许可数量时可以输入
            $("#licNumInfo").removeAttr("readonly");
        }else {
            $("#licNumInfo").attr("readonly",true).val("1");
        }

2.管理界面,所有数量可甜

 function bindEvent() {
            $("#addCloudLicenseOK").on("click", function() {
                addCloudLicense();
            });
            $("#productCategory").on("change", function() {
               var category = $("#productCategory input[name=category]:checked").val();
               // if(category == 9){
               //     $("#licNumInfo").removeAttr("readonly");
               // }else {
               //     $("#licNumInfo").attr("readonly",true).val("1");
               // }
               timeLicensePricingResource.getProducts(category, function(products) {
                   fillProductNamesSelect(products);
                   refreshModulesView();
               }, null);
            });
            $("#productNames").on("change", function() {
                refreshModulesView();
                // if ($(this).val() === "10008001" || $(this).val() === "10008002") {
                    $("#licNumInfo").val("1");
                // }
            });
            // 扩展模块选中样式
            $("#productModule").on("click", ".licModuleCheck", function() {
                if ($(this).hasClass("radio")) {
                    $(".moduleCheckbox").removeClass("licModuleCheckAfter");
                    $(".radio").addClass("licModuleCheckAfter");
                } else if ($(this).hasClass("moduleCheckbox")) {
                    $(".radio").removeClass("licModuleCheckAfter");
                    var name = this.getAttribute("name");
                    $(".moduleCheckbox[name='" + name + "']").toggleClass("licModuleCheckAfter");
                }
            });
        }