ScoreOperationChainHandler implements OutputOperationHandler<ScoreOperationChain, Integer> { @JsonSetter("opScores") public void setOpScoresFromStrings(final Map<String, Integer> opScores) throws ClassNotFoundException { this.opScores.clear(); CollectionUtil.toMapWithClassKeys(opScores, this.opScores); validateOpScores(); }  @Override Integer doOperation(final ScoreOperationChain operation, final Context context, final Store store); int getChainScore(final Operations<?> operations, final User user); int getMaxUserAuthScore(final Set<String> opAuths); @JsonIgnore Map<Class<? extends Operation>, Integer> getOpScores(); @JsonIgnore void setOpScores(final Map<Class<? extends Operation>, Integer> opScores); @JsonGetter("opScores") Map<String, Integer> getOpScoresAsStrings(); @JsonSetter("opScores") void setOpScoresFromStrings(final Map<String, Integer> opScores); Map<String, Integer> getAuthScores(); void setAuthScores(final Map<String, Integer> authScores); Map<Class<? extends Operation>, ScoreResolver> getScoreResolvers(); void setScoreResolvers(final Map<Class<? extends Operation>, ScoreResolver> resolvers); void validateOpScores(); static Map<Class<? extends Operation>, ScoreResolver> getDefaultScoreResolvers();  }
@Test public void shouldPassValidationOfOperationScores() throws ClassNotFoundException { final ScoreOperationChainHandler handler = new ScoreOperationChainHandler(); final LinkedHashMap<String, Integer> opScores = new LinkedHashMap<>(); opScores.put(Operation.class.getName(), 1); opScores.put(GetElements.class.getName(), 2); opScores.put(GetAllElements.class.getName(), 3); handler.setOpScoresFromStrings(opScores); }
@Test public void shouldFailValidationOfOperationScores() throws ClassNotFoundException { final ScoreOperationChainHandler handler = new ScoreOperationChainHandler(); final LinkedHashMap<String, Integer> opScores = new LinkedHashMap<>(); opScores.put(GetElements.class.getName(), 2); opScores.put(GetAllElements.class.getName(), 3); opScores.put(Operation.class.getName(), 1); try { handler.setOpScoresFromStrings(opScores); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertTrue(e.getMessage().contains("Operation scores are configured incorrectly.")); } }