@Test public void testGetEntity() throws Exception { String serviceName = "xreGuide"; Collection<IfExpression> rules = new ArrayList<>(); rules.add(UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("receiverType", "Native"), "protocol1", IpProtocolVersion.IPV4.getVersionString())); rules.add(UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("mac", "receiverMacAddress"), "protocol2", IpProtocolVersion.IPV6.getVersionString())); when(urlRulesService.getUrlRules(serviceName)).thenReturn(rules); when(urlParamsService.getUrlParams(serviceName)) .thenReturn(UrlRuleExpressionsHelper.prepareUrlParams("DefaultProtocol", IpProtocolVersion.IPV4.getVersionString())); PendingChangesStatus pendingChangesStatus = new PendingChangesStatus(); Map<String, PendingChange> urlRulesChanges = new HashMap<>(); PendingChangesHelper.putPendingChange(urlRulesChanges, UrlRuleExpressionsHelper.getRuleIdByProtocolAndIp("protocol1", IpProtocolVersion.IPV4.getVersionString()), UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("receiverType", "changed"), "protocol1", IpProtocolVersion.IPV4.getVersionString()), UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("receiverType", "Native"), "protocol1", IpProtocolVersion.IPV4.getVersionString()), ActionType.UPDATE); PendingChangesHelper.putPendingChange(urlRulesChanges, UrlRuleExpressionsHelper.getRuleIdByProtocolAndIp("protocol2", IpProtocolVersion.IPV6.getVersionString()), null, UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("mac", "receiverMacAddress"), "protocol2", IpProtocolVersion.IPV6.getVersionString()), ActionType.DELETE); PendingChangesHelper.putPendingChange(urlRulesChanges, UrlRuleExpressionsHelper.getRuleIdByProtocolAndIp("newProtocol", IpProtocolVersion.IPV6.getVersionString()), UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("newParameter", "newValue"), "newProtocol", IpProtocolVersion.IPV6.getVersionString()), null, ActionType.UPDATE); pendingChangesStatus.setUrlRules(urlRulesChanges); Map<String, PendingChange> urlParamsChanges = new HashMap<>(); PendingChangesHelper.putPendingChange(urlParamsChanges, RedirectorConstants.DEFAULT_SERVER_NAME, UrlRuleExpressionsHelper.prepareUrlParams("changedDefaultProtocol", IpProtocolVersion.IPV6.getVersionString()), UrlRuleExpressionsHelper.prepareUrlParams("DefaultProtocol", IpProtocolVersion.IPV4.getVersionString()), ActionType.UPDATE); pendingChangesStatus.setUrlParams(urlParamsChanges); when(changesStatusService.getPendingChangesStatus(serviceName)).thenReturn(pendingChangesStatus); URLRules expectedUrlRules = new URLRules(); Collection<IfExpression> expectedRules = new ArrayList<>(); expectedRules.add(UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("receiverType", "changed"), "protocol1", IpProtocolVersion.IPV4.getVersionString())); expectedRules.add(UrlRuleExpressionsHelper.getUrlRuleIfExpression(new Equals("newParameter", "newValue"), "newProtocol", IpProtocolVersion.IPV6.getVersionString())); expectedUrlRules.setItems(expectedRules); Default expectedDefaultUrlRule = new Default(); expectedDefaultUrlRule.setUrlRule(UrlRuleExpressionsHelper.prepareUrlParams("changedDefaultProtocol", IpProtocolVersion.IPV6.getVersionString())); expectedUrlRules.setDefaultStatement(expectedDefaultUrlRule); URLRules result = testee.getEntity(serviceName); verifyRuleExpressionsEqual(expectedUrlRules.getItems(), result.getItems()); Assert.assertEquals(expectedUrlRules.getDefaultStatement().getUrlRule(), result.getDefaultStatement().getUrlRule()); }
@Override public URLRules getEntity(String serviceName) { PendingChangesStatus pendingChanges = changesStatusService.getPendingChangesStatus(serviceName); Collection<IfExpression> urlRules = PendingRulesPreviewHelper.mergeRules( RulesUtils.mapFromCollection(urlRulesService.getUrlRules(serviceName)), pendingChanges.getUrlRules()); PendingChange defaultUrlParamChange = pendingChanges.getUrlParams().get(RedirectorConstants.DEFAULT_SERVER_NAME); Default defaultUrlParams = new Default(); if (defaultUrlParamChange != null) { defaultUrlParams.setUrlRule((UrlRule) defaultUrlParamChange.getChangedExpression()); } else { defaultUrlParams.setUrlRule(urlParamsService.getUrlParams(serviceName)); } return RulesUtils.buildURLRules(urlRules, defaultUrlParams); }
NextUrlRulesEntityViewService implements IEntityViewService<URLRules> { @Override public URLRules getEntity(String serviceName) { PendingChangesStatus pendingChanges = changesStatusService.getPendingChangesStatus(serviceName); Collection<IfExpression> urlRules = PendingRulesPreviewHelper.mergeRules( RulesUtils.mapFromCollection(urlRulesService.getUrlRules(serviceName)), pendingChanges.getUrlRules()); PendingChange defaultUrlParamChange = pendingChanges.getUrlParams().get(RedirectorConstants.DEFAULT_SERVER_NAME); Default defaultUrlParams = new Default(); if (defaultUrlParamChange != null) { defaultUrlParams.setUrlRule((UrlRule) defaultUrlParamChange.getChangedExpression()); } else { defaultUrlParams.setUrlRule(urlParamsService.getUrlParams(serviceName)); } return RulesUtils.buildURLRules(urlRules, defaultUrlParams); } }
NextUrlRulesEntityViewService implements IEntityViewService<URLRules> { @Override public URLRules getEntity(String serviceName) { PendingChangesStatus pendingChanges = changesStatusService.getPendingChangesStatus(serviceName); Collection<IfExpression> urlRules = PendingRulesPreviewHelper.mergeRules( RulesUtils.mapFromCollection(urlRulesService.getUrlRules(serviceName)), pendingChanges.getUrlRules()); PendingChange defaultUrlParamChange = pendingChanges.getUrlParams().get(RedirectorConstants.DEFAULT_SERVER_NAME); Default defaultUrlParams = new Default(); if (defaultUrlParamChange != null) { defaultUrlParams.setUrlRule((UrlRule) defaultUrlParamChange.getChangedExpression()); } else { defaultUrlParams.setUrlRule(urlParamsService.getUrlParams(serviceName)); } return RulesUtils.buildURLRules(urlRules, defaultUrlParams); }  }
NextUrlRulesEntityViewService implements IEntityViewService<URLRules> { @Override public URLRules getEntity(String serviceName) { PendingChangesStatus pendingChanges = changesStatusService.getPendingChangesStatus(serviceName); Collection<IfExpression> urlRules = PendingRulesPreviewHelper.mergeRules( RulesUtils.mapFromCollection(urlRulesService.getUrlRules(serviceName)), pendingChanges.getUrlRules()); PendingChange defaultUrlParamChange = pendingChanges.getUrlParams().get(RedirectorConstants.DEFAULT_SERVER_NAME); Default defaultUrlParams = new Default(); if (defaultUrlParamChange != null) { defaultUrlParams.setUrlRule((UrlRule) defaultUrlParamChange.getChangedExpression()); } else { defaultUrlParams.setUrlRule(urlParamsService.getUrlParams(serviceName)); } return RulesUtils.buildURLRules(urlRules, defaultUrlParams); }  @Override URLRules getEntity(String serviceName); @Override URLRules getEntity(PendingChangesStatus pendingChangesStatus, URLRules currentEntity); }
NextUrlRulesEntityViewService implements IEntityViewService<URLRules> { @Override public URLRules getEntity(String serviceName) { PendingChangesStatus pendingChanges = changesStatusService.getPendingChangesStatus(serviceName); Collection<IfExpression> urlRules = PendingRulesPreviewHelper.mergeRules( RulesUtils.mapFromCollection(urlRulesService.getUrlRules(serviceName)), pendingChanges.getUrlRules()); PendingChange defaultUrlParamChange = pendingChanges.getUrlParams().get(RedirectorConstants.DEFAULT_SERVER_NAME); Default defaultUrlParams = new Default(); if (defaultUrlParamChange != null) { defaultUrlParams.setUrlRule((UrlRule) defaultUrlParamChange.getChangedExpression()); } else { defaultUrlParams.setUrlRule(urlParamsService.getUrlParams(serviceName)); } return RulesUtils.buildURLRules(urlRules, defaultUrlParams); }  @Override URLRules getEntity(String serviceName); @Override URLRules getEntity(PendingChangesStatus pendingChangesStatus, URLRules currentEntity);  }