HardConstraintMatchPersistenceExtension implements RuleModelIActionPersistenceExtension { @Override public PluggableIAction unmarshal(final String iActionString) throws RuleModelDRLPersistenceException { List<String> parameters = StringUtils.splitArgumentsList(PersistenceExtensionUtils.unwrapParenthesis(iActionString)); if (!parameters.isEmpty() && "kcontext".equals(parameters.get(0))) { if (parameters.size() == 2) { return new ActionHardConstraintMatch(PersistenceExtensionUtils.extractConstraintMatchValue(parameters.get(1))); } if (parameters.size() == 3) { try { int bendableScoreLevel = Integer.parseInt(parameters.get(1)); return new ActionBendableHardConstraintMatch(bendableScoreLevel, PersistenceExtensionUtils.extractConstraintMatchValue(parameters.get(2))); } catch (NumberFormatException e) { LOGGER.error("Could not parse bendable score level parameter " + parameters.get(1) + " as an Integer"); } } } throw new RuleModelDRLPersistenceException(PersistenceExtensionUtils.EXCEPTION_MESSAGE_BASE + iActionString); }  @Override boolean accept(final String iActionString); @Override PluggableIAction unmarshal(final String iActionString);  }
@Test public void unmarshalHardConstraintMatch() throws RuleModelDRLPersistenceException { String actionString = "scoreHolder.addHardConstraintMatch(kcontext, -1);"; IAction action = extension.unmarshal(actionString); assertTrue(action instanceof ActionHardConstraintMatch); ActionHardConstraintMatch actionHardConstraintMatch = (ActionHardConstraintMatch) action; assertEquals("-1", actionHardConstraintMatch.getConstraintMatch()); }
@Test public void unmarshalHardConstraintMatchNull() throws RuleModelDRLPersistenceException { String actionString = "scoreHolder.addHardConstraintMatch(kcontext, null);"; IAction action = extension.unmarshal(actionString); assertTrue(action instanceof ActionHardConstraintMatch); ActionHardConstraintMatch actionHardConstraintMatch = (ActionHardConstraintMatch) action; assertNull(actionHardConstraintMatch.getConstraintMatch()); }
@Test public void unmarshalActionBendableHardConstraintMatch() throws RuleModelDRLPersistenceException { String actionString = "scoreHolder.addHardConstraintMatch(kcontext, 1, -1);"; IAction action = extension.unmarshal(actionString); assertTrue(action instanceof ActionBendableHardConstraintMatch); ActionBendableHardConstraintMatch actionHardConstraintMatch = (ActionBendableHardConstraintMatch) action; assertEquals(1, actionHardConstraintMatch.getPosition()); assertEquals("-1", actionHardConstraintMatch.getConstraintMatch()); }