Search in sources :

Example 1 with RuleData

use of org.apache.shenyu.common.dto.RuleData in project incubator-shenyu by apache.

the class RuleServiceTest method testFindBySelectorId.

@Test
public void testFindBySelectorId() {
    publishEvent();
    RuleConditionQuery ruleConditionQuery = buildRuleConditionQuery();
    RuleConditionDO ruleCondition = buildRuleConditionDO();
    given(this.ruleConditionMapper.selectByQuery(ruleConditionQuery)).willReturn(Collections.singletonList(ruleCondition));
    RuleDO ruleDO = buildRuleDO("123");
    List<RuleDO> ruleDOList = Collections.singletonList(ruleDO);
    given(this.ruleMapper.findBySelectorId("456")).willReturn(ruleDOList);
    List<RuleData> dataList = this.ruleService.findBySelectorId("456");
    assertNotNull(dataList);
    assertEquals(ruleDOList.size(), dataList.size());
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) RuleConditionDO(org.apache.shenyu.admin.model.entity.RuleConditionDO) RuleConditionQuery(org.apache.shenyu.admin.model.query.RuleConditionQuery) RuleDO(org.apache.shenyu.admin.model.entity.RuleDO) Test(org.junit.jupiter.api.Test)

Example 2 with RuleData

use of org.apache.shenyu.common.dto.RuleData in project incubator-shenyu by apache.

the class SyncDataServiceTest method buildRuleData.

/**
 * build mock RuleData.
 *
 * @return RuleData
 */
private RuleData buildRuleData() {
    RuleData ruleData = new RuleData();
    ruleData.setId(ID);
    ruleData.setEnabled(true);
    ruleData.setHandle("divide");
    ruleData.setLoged(true);
    ruleData.setMatchMode(1);
    ruleData.setName("divide");
    ruleData.setPluginName("divide");
    ruleData.setSelectorId("1");
    ruleData.setSort(1);
    ConditionData conditionData = new ConditionData();
    conditionData.setParamType(ParamTypeEnum.POST.getName());
    conditionData.setOperator(OperatorEnum.EQ.getAlias());
    conditionData.setParamName("post");
    conditionData.setParamValue("POST");
    ruleData.setConditionDataList(Collections.singletonList(conditionData));
    return ruleData;
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) ConditionData(org.apache.shenyu.common.dto.ConditionData)

Example 3 with RuleData

use of org.apache.shenyu.common.dto.RuleData in project incubator-shenyu by apache.

the class SyncDataServiceTest method syncAllTest.

@Test
public void syncAllTest() {
    PluginData pluginData = buildPluginData();
    SelectorData selectorData = buildSelectorData();
    RuleData ruleData = buildRuleData();
    given(this.appAuthService.syncData()).willReturn(ShenyuAdminResult.success());
    given(this.pluginService.listAll()).willReturn(Collections.singletonList(pluginData));
    given(this.selectorService.listAll()).willReturn(Collections.singletonList(selectorData));
    given(this.ruleService.listAll()).willReturn(Collections.singletonList(ruleData));
    assertThat(syncDataService.syncAll(DataEventTypeEnum.CREATE), greaterThan(false));
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) PluginData(org.apache.shenyu.common.dto.PluginData) SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Example 4 with RuleData

use of org.apache.shenyu.common.dto.RuleData in project incubator-shenyu by apache.

the class ZookeeperDataChangedListenerTest method testOnRuleChangedUpdate.

/**
 * test case onRuleChanged update event.
 */
@Test
public void testOnRuleChangedUpdate() {
    RuleData ruleData = RuleData.builder().id(MOCK_ID).name(MOCK_NAME).pluginName(MOCK_PLUGIN_NAME).selectorId(MOCK_SELECTOR_ID).build();
    String ruleRealPath = DefaultPathConstants.buildRulePath(ruleData.getPluginName(), ruleData.getSelectorId(), ruleData.getId());
    String ruleParentPath = DefaultPathConstants.buildRuleParentPath(ruleData.getPluginName());
    when(zkClient.exists(ruleRealPath)).thenReturn(true);
    when(zkClient.exists(ruleParentPath)).thenReturn(true);
    zookeeperDataChangedListener.onRuleChanged(ImmutableList.of(ruleData), DataEventTypeEnum.UPDATE);
    verify(zkClient, atMostOnce()).createPersistent(ruleRealPath, true);
    verify(zkClient, atMostOnce()).createPersistent(ruleParentPath, true);
    verify(zkClient, times(1)).writeData(ruleRealPath, GsonUtils.getInstance().toJson(ruleData));
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) Test(org.junit.jupiter.api.Test)

Example 5 with RuleData

use of org.apache.shenyu.common.dto.RuleData in project incubator-shenyu by apache.

the class BaseDataCacheTest method testRemoveRuleData.

@Test
public void testRemoveRuleData() throws NoSuchFieldException, IllegalAccessException {
    RuleData ruleData = RuleData.builder().id("1").selectorId(mockSelectorId1).build();
    ConcurrentHashMap<String, List<RuleData>> ruleMap = getFieldByName(ruleMapStr);
    ruleMap.put(mockSelectorId1, Lists.newArrayList(ruleData));
    BaseDataCache.getInstance().removeRuleData(ruleData);
    assertEquals(Lists.newArrayList(), ruleMap.get(mockSelectorId1));
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

RuleData (org.apache.shenyu.common.dto.RuleData)107 Test (org.junit.jupiter.api.Test)63 SelectorData (org.apache.shenyu.common.dto.SelectorData)48 ShenyuContext (org.apache.shenyu.plugin.api.context.ShenyuContext)18 ShenyuPluginChain (org.apache.shenyu.plugin.api.ShenyuPluginChain)17 ServerWebExchange (org.springframework.web.server.ServerWebExchange)17 List (java.util.List)16 Mono (reactor.core.publisher.Mono)15 Objects (java.util.Objects)12 PluginData (org.apache.shenyu.common.dto.PluginData)12 MetaData (org.apache.shenyu.common.dto.MetaData)11 PluginEnum (org.apache.shenyu.common.enums.PluginEnum)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Map (java.util.Map)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 ArrayList (java.util.ArrayList)9 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)7 CollectionUtils (org.apache.commons.collections4.CollectionUtils)7