Search in sources :

Example 1 with JsonConverter

use of com.alibaba.cloud.sentinel.datasource.converter.JsonConverter in project spring-cloud-alibaba by alibaba.

the class SentinelConverterTests method testConverterEmptyContent.

@Test
public void testConverterEmptyContent() {
    JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
    List<FlowRule> flowRules = (List<FlowRule>) jsonConverter.convert("");
    assertThat(flowRules.size()).isEqualTo(0);
}
Also used : JsonConverter(com.alibaba.cloud.sentinel.datasource.converter.JsonConverter) List(java.util.List) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Test(org.junit.Test)

Example 2 with JsonConverter

use of com.alibaba.cloud.sentinel.datasource.converter.JsonConverter in project spring-cloud-alibaba by alibaba.

the class SentinelConverterTests method testJsonConverter.

@Test
public void testJsonConverter() {
    JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
    List<FlowRule> flowRules = (List<FlowRule>) jsonConverter.convert(readFileContent("classpath: flowrule.json"));
    assertThat(flowRules.size()).isEqualTo(1);
    assertThat(flowRules.get(0).getResource()).isEqualTo("resource");
    assertThat(flowRules.get(0).getLimitApp()).isEqualTo("default");
    assertThat(String.valueOf(flowRules.get(0).getCount())).isEqualTo("1.0");
    assertThat(flowRules.get(0).getControlBehavior()).isEqualTo(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
    assertThat(flowRules.get(0).getStrategy()).isEqualTo(RuleConstant.STRATEGY_DIRECT);
    assertThat(flowRules.get(0).getGrade()).isEqualTo(RuleConstant.FLOW_GRADE_QPS);
}
Also used : JsonConverter(com.alibaba.cloud.sentinel.datasource.converter.JsonConverter) List(java.util.List) FlowRule(com.alibaba.csp.sentinel.slots.block.flow.FlowRule) Test(org.junit.Test)

Example 3 with JsonConverter

use of com.alibaba.cloud.sentinel.datasource.converter.JsonConverter in project spring-cloud-alibaba by alibaba.

the class SentinelConverterTests method testConverterErrorContent.

@Test(expected = RuntimeException.class)
public void testConverterErrorContent() {
    JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
    jsonConverter.convert(readFileContent("classpath: flowrule-errorcontent.json"));
}
Also used : JsonConverter(com.alibaba.cloud.sentinel.datasource.converter.JsonConverter) Test(org.junit.Test)

Example 4 with JsonConverter

use of com.alibaba.cloud.sentinel.datasource.converter.JsonConverter in project spring-cloud-alibaba by alibaba.

the class SentinelConverterTests method testConverterErrorFormat.

@Test(expected = RuntimeException.class)
public void testConverterErrorFormat() {
    JsonConverter jsonConverter = new JsonConverter(objectMapper, FlowRule.class);
    jsonConverter.convert(readFileContent("classpath: flowrule-errorformat.json"));
}
Also used : JsonConverter(com.alibaba.cloud.sentinel.datasource.converter.JsonConverter) Test(org.junit.Test)

Aggregations

JsonConverter (com.alibaba.cloud.sentinel.datasource.converter.JsonConverter)4 Test (org.junit.Test)4 FlowRule (com.alibaba.csp.sentinel.slots.block.flow.FlowRule)2 List (java.util.List)2