ActionPluginClientService { public void initScoreHolderAwarePlugin(final RuleModeller ruleModeller, final ScoreHolderGlobalAware scoreHolderGlobalAware, final Collection supportedScoreHolderTypes) { invokeScoreInformationCachedOperation(ruleModeller, scoreInformation -> { Collection<String> scoreHolderFqns = scoreInformation.getScoreHolderFqnTypeFqns(); if (scoreHolderFqns.isEmpty()) { scoreHolderGlobalAware.scoreHolderGlobalIssueDetected(translationService.getTranslation(GuidedRuleEditorConstants.ActionPluginClientService_ScoreHolderGlobalNotFound)); } else if (scoreHolderFqns.size() > 1) { scoreHolderGlobalAware.scoreHolderGlobalIssueDetected(translationService.getTranslation(translationService.getTranslation(GuidedRuleEditorConstants.ActionPluginClientService_MultipleScoreHolderGlobals))); } else if (scoreHolderFqns.size() == 1) { if (!supportedScoreHolderTypes.containsAll(scoreHolderFqns)) { scoreHolderGlobalAware.scoreHolderGlobalIssueDetected(translationService.getTranslation(GuidedRuleEditorConstants.ActionPluginClientService_ScoreTypeNotSupported)); } else { scoreHolderGlobalAware.scoreHolderGlobalLoadedCorrectly(scoreHolderFqns.iterator().next()); } } }); } @Inject  ActionPluginClientService(final Caller<ScoreHolderService> scoreHolderService,
                                     final TranslationService translationService); void invokeScoreInformationCachedOperation(final RuleModeller ruleModeller,
                                                      final Consumer<ScoreInformation> scoreInformationConsumer); void initScoreHolderAwarePlugin(final RuleModeller ruleModeller,
                                           final ScoreHolderGlobalAware scoreHolderGlobalAware,
                                           final Collection supportedScoreHolderTypes); void addPluginToActionList(final RuleModeller ruleModeller,
                                      final Command addCommand,
                                      final Collection supportedScoreHolderTypes); void initBendableScoreLevels(final RuleModeller ruleModeller,
                                        final AbstractActionMultiConstraintBendableMatch constraintMatch);  }
@Test public void initScoreHolderAwarePlugin() { ScoreInformation scoreInformation = new ScoreInformation(Arrays.asList(HardSoftScoreHolder.class.getName()), Arrays.asList(new BendableScoreLevelsWrapper(1, 1))); Map<String, Object> serviceCache = new HashMap<>(); serviceCache.put(ActionPluginClientService.SCORE_INFORMATION, scoreInformation); RuleModeller ruleModeller = mock(RuleModeller.class); when(ruleModeller.getServiceInvocationCache()).thenReturn(serviceCache); ScoreHolderGlobalAware scoreHolderGlobalAware = mock(ScoreHolderGlobalAware.class); service.initScoreHolderAwarePlugin(ruleModeller, scoreHolderGlobalAware, Arrays.asList(HardSoftScoreHolder.class.getName())); verify(scoreHolderGlobalAware, times(1)).scoreHolderGlobalLoadedCorrectly(HardSoftScoreHolder.class.getName()); }
@Test public void initScoreHolderAwarePluginAmbigiousScoreHolder() { ScoreInformation scoreInformation = new ScoreInformation(Arrays.asList(HardSoftScoreHolder.class.getName(), SimpleScoreHolder.class.getName()), Arrays.asList(new BendableScoreLevelsWrapper(1, 1))); Map<String, Object> serviceCache = new HashMap<>(); serviceCache.put(ActionPluginClientService.SCORE_INFORMATION, scoreInformation); RuleModeller ruleModeller = mock(RuleModeller.class); when(ruleModeller.getServiceInvocationCache()).thenReturn(serviceCache); ScoreHolderGlobalAware scoreHolderGlobalAware = mock(ScoreHolderGlobalAware.class); service.initScoreHolderAwarePlugin(ruleModeller, scoreHolderGlobalAware, Arrays.asList(HardSoftScoreHolder.class.getName())); verify(scoreHolderGlobalAware, times(1)).scoreHolderGlobalIssueDetected(anyString()); }