|
| 1 | +/* |
| 2 | + * Copyright 1999-2018 Alibaba Group Holding Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.alibaba.csp.sentinel.slots.block.flow.param; |
| 17 | + |
| 18 | +import java.util.Collections; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | +import com.alibaba.csp.sentinel.command.CommandRequest; |
| 22 | +import com.alibaba.csp.sentinel.command.CommandResponse; |
| 23 | +import com.alibaba.csp.sentinel.command.handler.ModifyParamFlowRulesCommandHandler; |
| 24 | +import com.alibaba.fastjson.JSON; |
| 25 | +import org.junit.After; |
| 26 | +import org.junit.Test; |
| 27 | + |
| 28 | +import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertTrue; |
| 30 | + |
| 31 | +public class ModifyParamFlowRulesCommandHandlerTest { |
| 32 | + |
| 33 | + @After |
| 34 | + public void tearDown() { |
| 35 | + ParamFlowRuleManager.loadRules(Collections.<ParamFlowRule>emptyList()); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testHandleDecodedDataPreservesPlusInParamFlowItem() { |
| 40 | + ParamFlowRule rule = new ParamFlowRule("test-resource") |
| 41 | + .setParamIdx(0) |
| 42 | + .setCount(1); |
| 43 | + rule.setParamFlowItemList(Collections.singletonList(new ParamFlowItem("a+b", 3, String.class.getName()))); |
| 44 | + |
| 45 | + CommandRequest request = new CommandRequest(); |
| 46 | + request.addParam("data", JSON.toJSONString(Collections.singletonList(rule))); |
| 47 | + |
| 48 | + CommandResponse<String> response = new ModifyParamFlowRulesCommandHandler().handle(request); |
| 49 | + |
| 50 | + assertTrue(response.isSuccess()); |
| 51 | + List<ParamFlowRule> rules = ParamFlowRuleManager.getRulesOfResource("test-resource"); |
| 52 | + assertEquals(1, rules.size()); |
| 53 | + assertEquals(Integer.valueOf(3), rules.get(0).getParsedHotItems().get("a+b")); |
| 54 | + } |
| 55 | +} |
0 commit comments