Authored by chenchao

add unit test

@@ -14,6 +14,7 @@ import com.yohobuy.ufo.model.order.bo.SellerTypeNode; @@ -14,6 +14,7 @@ import com.yohobuy.ufo.model.order.bo.SellerTypeNode;
14 import com.yohoufo.order.utils.SellerHelper; 14 import com.yohoufo.order.utils.SellerHelper;
15 import lombok.Getter; 15 import lombok.Getter;
16 import lombok.Setter; 16 import lombok.Setter;
  17 +import lombok.ToString;
17 import org.slf4j.Logger; 18 import org.slf4j.Logger;
18 19
19 import java.math.BigDecimal; 20 import java.math.BigDecimal;
@@ -23,6 +24,7 @@ import java.util.function.Function; @@ -23,6 +24,7 @@ import java.util.function.Function;
23 /** 24 /**
24 * Created by chao.chen on 2019/1/15. 25 * Created by chao.chen on 2019/1/15.
25 */ 26 */
  27 +@ToString
26 public class SellerWrapper { 28 public class SellerWrapper {
27 @Getter 29 @Getter
28 StoredSeller storedSeller; 30 StoredSeller storedSeller;
1 package com.yohoufo.order.service; 1 package com.yohoufo.order.service;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.alibaba.fastjson.TypeReference;
  5 +import com.github.jknack.handlebars.internal.Files;
3 import com.yohobuy.ufo.model.order.bo.SellerBo; 6 import com.yohobuy.ufo.model.order.bo.SellerBo;
4 import com.yohobuy.ufo.model.order.common.EntrySellerType; 7 import com.yohobuy.ufo.model.order.common.EntrySellerType;
  8 +import com.yohoufo.dal.order.model.StoredSeller;
5 import com.yohoufo.order.BaseWebTest; 9 import com.yohoufo.order.BaseWebTest;
  10 +import com.yohoufo.order.model.dto.BuyerPenalty;
  11 +import com.yohoufo.order.service.handler.penalty.BuyerPenaltyRuleSelectorTest;
6 import com.yohoufo.order.service.impl.SellerService; 12 import com.yohoufo.order.service.impl.SellerService;
  13 +import com.yohoufo.order.service.impl.SellerWrapper;
7 import org.junit.Assert; 14 import org.junit.Assert;
8 import org.junit.Test; 15 import org.junit.Test;
  16 +import org.slf4j.Logger;
  17 +import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
10 19
  20 +import java.io.IOException;
  21 +import java.util.List;
  22 +
11 /** 23 /**
12 * Created by chao.chen on 2019/1/9. 24 * Created by chao.chen on 2019/1/9.
13 */ 25 */
@@ -16,6 +28,8 @@ public class SellerServiceTest extends BaseWebTest { @@ -16,6 +28,8 @@ public class SellerServiceTest extends BaseWebTest {
16 @Autowired 28 @Autowired
17 private SellerService sellerService; 29 private SellerService sellerService;
18 30
  31 +
  32 +
19 @Test 33 @Test
20 public void testGetEntrySellerType(){ 34 public void testGetEntrySellerType(){
21 EntrySellerType none = sellerService.getEntrySellerType(44); 35 EntrySellerType none = sellerService.getEntrySellerType(44);
@@ -40,4 +54,9 @@ public class SellerServiceTest extends BaseWebTest { @@ -40,4 +54,9 @@ public class SellerServiceTest extends BaseWebTest {
40 SellerBo sellerBo = sellerService.getSellerWithAuth(uid); 54 SellerBo sellerBo = sellerService.getSellerWithAuth(uid);
41 System.out.println(sellerBo); 55 System.out.println(sellerBo);
42 } 56 }
  57 +
  58 +
  59 +
  60 +
  61 +
43 } 62 }
  1 +package com.yohoufo.order.service.impl;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.alibaba.fastjson.TypeReference;
  5 +import com.github.jknack.handlebars.internal.Files;
  6 +import com.yohoufo.dal.order.model.StoredSeller;
  7 +import com.yohoufo.order.service.handler.penalty.BuyerPenaltyRuleSelectorTest;
  8 +import org.junit.Test;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +
  12 +import java.io.IOException;
  13 +import java.util.List;
  14 +import java.util.function.Function;
  15 +
  16 +public class SellerWrapperTest {
  17 + private Logger logger = LoggerFactory.getLogger(getClass());
  18 + public static List<StoredSeller> initStoredSellerList() throws IOException {
  19 + String buyerPenaltyConfig = Files.read(BuyerPenaltyRuleSelectorTest.class.getResourceAsStream("/data/Seller.json"));
  20 + return JSONObject.parseObject(buyerPenaltyConfig, new TypeReference<List<StoredSeller>>(){});
  21 + }
  22 +
  23 + @Test
  24 + public void testSellerPolicy(){
  25 +
  26 + try {
  27 + List<StoredSeller> storedSellers = initStoredSellerList();
  28 + for(StoredSeller storedSeller : storedSellers){
  29 + SellerWrapper sellerWrapper = new SellerWrapper(storedSeller.getUid(),logger)
  30 + .storedSellerDataSource((uid) -> storedSeller )
  31 + .addSpecialSuperFunc((uid)->false)
  32 + .buildSellerWrapper().attachAssetPolicy();
  33 + logger.info("sellerWrapper {}", sellerWrapper);
  34 + }
  35 +
  36 + } catch (IOException e) {
  37 + e.printStackTrace();
  38 + }
  39 +
  40 + }
  41 +}
  1 +[
  2 + {"uid":1, "entryType": 0},
  3 + {"uid":11, "entryType": 1},
  4 + {"uid":12, "entryType": 2},
  5 + {"uid":13, "entryType": 3},
  6 + {"uid":14, "entryType": 4}
  7 +]