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());
}
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;
}
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));
}
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));
}
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));
}
Aggregations