Authored by LUOXC

refactor

1 package com.yohoufo.order.service.handler.penalty; 1 package com.yohoufo.order.service.handler.penalty;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.github.jknack.handlebars.internal.Files;
4 import com.yohobuy.ufo.model.order.common.OrderAttributes; 5 import com.yohobuy.ufo.model.order.common.OrderAttributes;
5 import com.yohobuy.ufo.model.order.common.OrderStatus; 6 import com.yohobuy.ufo.model.order.common.OrderStatus;
6 import com.yohoufo.order.model.dto.BuyerPenalty; 7 import com.yohoufo.order.model.dto.BuyerPenalty;
  8 +import org.apache.commons.io.FileUtils;
7 import org.junit.Assert; 9 import org.junit.Assert;
8 import org.junit.BeforeClass; 10 import org.junit.BeforeClass;
9 import org.junit.Test; 11 import org.junit.Test;
10 12
  13 +import java.io.File;
  14 +import java.io.IOException;
  15 +import java.io.InputStream;
11 import java.math.BigDecimal; 16 import java.math.BigDecimal;
  17 +import java.net.URI;
  18 +import java.net.URL;
12 19
13 import static org.junit.Assert.*; 20 import static org.junit.Assert.*;
14 21
15 public class BuyerPenaltyRuleSelectorTest { 22 public class BuyerPenaltyRuleSelectorTest {
  23 +
16 static BuyerPenalty buyerPenalty; 24 static BuyerPenalty buyerPenalty;
17 - static String buyerPenaltyConfig = "{\"stockCaseMap\":{\"goodsInStock\":{\"stockTypeName\":\"goodsInStock\",\"triggerCaseMap\":{\"beforeSellerDeliver\":{\"name\":\"beforeSellerDeliver\",\"stagedCollection\":[{\"index\":1,\"moneyRange\":{\"min\":18},\"rate\":0.01,\"timeRange\":{\"max\":3600,\"min\":0}},{\"index\":2,\"moneyRange\":{\"min\":38},\"rate\":0.02,\"timeRange\":{\"min\":3600}}]},\"beforeDepotReceive\":{\"name\":\"beforeDepotReceive\",\"stagedCollection\":[{\"moneyRange\":{\"min\":68},\"rate\":0.03}]}}},\"advanceSale\":{\"stockTypeName\":\"advanceSale\",\"triggerCaseMap\":{\"beforeSellerDeliver\":{\"name\":\"beforeSellerDeliver\",\"stagedCollection\":[{\"index\":1,\"moneyRange\":{\"min\":0},\"rate\":0,\"timeRange\":{\"max\":86400,\"min\":0}},{\"index\":2,\"moneyRange\":{\"min\":0},\"rate\":0.08,\"timeRange\":{\"min\":86400}}]},\"beforeDepotReceive\":{\"name\":\"beforeDepotReceive\",\"stagedCollection\":[{\"moneyRange\":{\"min\":68},\"rate\":0.03}]}}}}}";  
18 25
19 @BeforeClass 26 @BeforeClass
20 - public static void init() { 27 + public static void init() throws IOException {
  28 + String buyerPenaltyConfig = Files.read(BuyerPenaltyRuleSelectorTest.class.getResourceAsStream("/data/buyer_penalty.json"));
21 buyerPenalty = JSONObject.parseObject(buyerPenaltyConfig, BuyerPenalty.class); 29 buyerPenalty = JSONObject.parseObject(buyerPenaltyConfig, BuyerPenalty.class);
22 } 30 }
23 31
  1 +package com.yohoufo.order.service.handler.penalty;
  2 +
  3 +import org.junit.Before;
  4 +import org.junit.Test;
  5 +
  6 +import static org.junit.Assert.*;
  7 +
  8 +public class SellerEarnestMoney2BuyerPenaltyCalculatorTest {
  9 +
  10 + @Before
  11 + public void setUp() throws Exception {
  12 + }
  13 +
  14 + @Test
  15 + public void calculate() {
  16 + }
  17 +
  18 +}
  1 +{
  2 + "stockCaseMap": {
  3 + "goodsInStock": {
  4 + "stockTypeName": "goodsInStock",
  5 + "triggerCaseMap": {
  6 + "beforeSellerDeliver": {
  7 + "name": "beforeSellerDeliver",
  8 + "stagedCollection": [
  9 + {
  10 + "index": 1,
  11 + "moneyRange": {
  12 + "min": 0.2
  13 + },
  14 + "rate": 0.01,
  15 + "timeRange": {
  16 + "max": 3600,
  17 + "min": 0
  18 + }
  19 + },
  20 + {
  21 + "index": 2,
  22 + "moneyRange": {
  23 + "min": 0.3
  24 + },
  25 + "rate": 0.02,
  26 + "timeRange": {
  27 + "min": 3600
  28 + }
  29 + }
  30 + ]
  31 + },
  32 + "beforeDepotReceive": {
  33 + "name": "beforeDepotReceive",
  34 + "stagedCollection": [
  35 + {
  36 + "moneyRange": {
  37 + "min": 0.5
  38 + },
  39 + "rate": 0.03
  40 + }
  41 + ]
  42 + }
  43 + }
  44 + },
  45 + "advanceSale": {
  46 + "stockTypeName": "advanceSale",
  47 + "triggerCaseMap": {
  48 + "beforeSellerDeliver": {
  49 + "name": "beforeSellerDeliver",
  50 + "stagedCollection": [
  51 + {
  52 + "index": 1,
  53 + "moneyRange": {
  54 + "min": 0
  55 + },
  56 + "rate": 0,
  57 + "timeRange": {
  58 + "max": 86400,
  59 + "min": 0
  60 + }
  61 + },
  62 + {
  63 + "index": 2,
  64 + "moneyRange": {
  65 + "min": 0
  66 + },
  67 + "rate": 0.08,
  68 + "timeRange": {
  69 + "min": 86400
  70 + }
  71 + }
  72 + ]
  73 + },
  74 + "beforeDepotReceive": {
  75 + "name": "beforeDepotReceive",
  76 + "stagedCollection": [
  77 + {
  78 + "moneyRange": {
  79 + "min": 0.5
  80 + },
  81 + "rate": 0.03
  82 + }
  83 + ]
  84 + }
  85 + }
  86 + }
  87 + }
  88 +}