private boolean typeMatches(final ObjectAdapter adapter) { if (typeBinding == null || !typeBinding.isFound()) { return true; } final ObjectSpecification spec = adapter.getSpecification(); final String requiredTypeName = typeBinding.getCurrentCell().getText(); final String specFullName = spec.getFullIdentifier(); if (specFullName.equals(requiredTypeName)) { return true; } final String simpleSpecName = StringUtils.simpleName(specFullName); final String simpleRequiredType = StringUtils.simpleName(requiredTypeName); return simpleSpecName.equalsIgnoreCase(simpleRequiredType); }
private boolean typeMatches(final ObjectAdapter adapter) { if (typeBinding == null || !typeBinding.isFound()) { return true; } final ObjectSpecification spec = adapter.getSpecification(); final String requiredTypeName = typeBinding.getCurrentCell().getText(); final String specFullName = spec.getFullIdentifier(); if (specFullName.equals(requiredTypeName)) { return true; } final String simpleSpecName = StringUtils.simpleName(specFullName); final String simpleRequiredType = StringUtils.simpleName(requiredTypeName); return simpleSpecName.equalsIgnoreCase(simpleRequiredType); }
private boolean bindingAfterArg0() { if (!getArg0Binding().isFound()) { return false; } for (final CellBinding binding : getCellBindings()) { if (binding.getColumn() > getArg0Binding().getColumn()) { return true; } } return false; }
@Override public void perform(final PerformContext performContext) throws ScenarioBoundValueException { final CellBinding thatItBinding = performContext.getPeer().getThatItBinding(); if (!thatItBinding.isFound()) { final CellBinding performBinding = performContext.getPeer().getPerformBinding(); throw ScenarioBoundValueException.current(performBinding, "(require " + IsisViewerConstants.THAT_IT_NAME + "' column)"); } final ScenarioCell thatItCell = thatItBinding.getCurrentCell(); final String thatIt = thatItCell.getText(); final ThatSubcommand thatSubcommand = subcommandByKey.get(thatIt); if (thatSubcommand == null) { throw ScenarioBoundValueException.current(thatItBinding, "(unknown '" + IsisViewerConstants.THAT_IT_NAME + "' verb)"); } result = thatSubcommand.that(performContext); }
@Override protected void doThat(final PerformContext performContext, final Iterable<ObjectAdapter> collection) throws ScenarioBoundValueException { final CellBinding thatBinding = performContext.getPeer().getThatItBinding(); final CellBinding arg0Binding = performContext.getPeer().getArg0Binding(); if (!arg0Binding.isFound()) { throw ScenarioBoundValueException.current(thatBinding, "(requires argument)"); } final ScenarioCell arg0Cell = arg0Binding.getCurrentCell(); final String expectedSizeStr = arg0Cell.getText(); final int expectedSize; try { expectedSize = Integer.parseInt(expectedSizeStr); } catch (final NumberFormatException ex) { throw ScenarioBoundValueException.current(arg0Binding, "(not an integer)"); } if (expectedSize <= 0) { throw ScenarioBoundValueException.current(arg0Binding, "(not a positive integer)"); } int actualSize = 0; for (@SuppressWarnings("unused") final ObjectAdapter eachObject : collection) { actualSize++; } if (expectedSize != actualSize) { throw ScenarioBoundValueException.current(arg0Binding, "" + actualSize); } }
public String executeRow(final String onObject, final String aliasResultAs, final String perform, final String usingMember, final String thatIt, final String arg0, final String... remainingArgs) { setupHeader(onObject, aliasResultAs, perform, usingMember, thatIt, arg0); final List<String> argumentCells = new ArrayList<String>(); // capture current getPeer().getOnObjectBinding().captureCurrent(new ScenarioCellDefault(onObject)); getPeer().getAliasResultAsBinding().captureCurrent(new ScenarioCellDefault(aliasResultAs)); getPeer().getPerformBinding().captureCurrent(new ScenarioCellDefault(perform)); getPeer().getOnMemberBinding().captureCurrent(new ScenarioCellDefault(usingMember)); if (getPeer().getThatItBinding().isFound()) { getPeer().getThatItBinding().captureCurrent(new ScenarioCellDefault(thatIt)); } if (getPeer().getArg0Binding().isFound()) { getPeer().getArg0Binding().captureCurrent(new ScenarioCellDefault(arg0)); argumentCells.add(arg0); } for (final String arg : remainingArgs) { argumentCells.add(arg); } // execute try { execute(argumentCells); } catch (final ScenarioBoundValueException ex) { return ex.getMessage(); } return "ok"; }
@Override protected void doThat(final PerformContext performContext, final Iterable<ObjectAdapter> collection) throws ScenarioBoundValueException { final ObjectMember nakedObjectMember = performContext.getObjectMember(); final CellBinding thatBinding = performContext.getPeer().getThatItBinding(); final CellBinding arg0Binding = performContext.getPeer().getArg0Binding(); if (!arg0Binding.isFound()) { throw ScenarioBoundValueException.current(thatBinding, "(requires argument)"); } final ScenarioCell arg0Cell = arg0Binding.getCurrentCell(); final ObjectAdapter containedAdapter = performContext.getPeer().getAdapter(null, nakedObjectMember.getSpecification(), arg0Binding, arg0Cell); boolean contains = false; for (final ObjectAdapter eachAdapter : collection) { if (containedAdapter == eachAdapter) { contains = true; break; } } if (!assertion.isSatisfiedBy(contains)) { throw ScenarioBoundValueException.current(arg0Binding, assertion.getErrorMsgIfNotSatisfied()); } }
@Override public ObjectAdapter that(final PerformContext performContext) throws ScenarioBoundValueException { final ObjectMember nakedObjectMember = performContext.getObjectMember(); final CellBinding thatBinding = performContext.getPeer().getThatItBinding(); final CellBinding arg0Binding = performContext.getPeer().getArg0Binding(); // check we have an argument to validate (if one is required) if (!arg0Binding.isFound()) { throw ScenarioBoundValueException.current(thatBinding, "(requires argument)"); } final ScenarioCell arg0Cell = arg0Binding.getCurrentCell(); final String toValidate = arg0Cell.getText(); if (StringUtils.isNullOrEmpty(toValidate)) { throw ScenarioBoundValueException.current(arg0Binding, "(required)"); } final ObjectAdapter toValidateAdapter = performContext.getPeer().getAdapter(null, nakedObjectMember.getSpecification(), arg0Binding, arg0Cell); final Consent validityConsent = determineConsent(performContext, toValidateAdapter); if (!getAssertion().satisfiedBy(validityConsent)) { throw ScenarioBoundValueException.current(getAssertion().colorBinding(arg0Binding, thatBinding), getAssertion().getReason(validityConsent)); } return toValidateAdapter; }