@Test public void testSuccessfulValidation() { ActivityDTO currentActivity = PostActivityTestHelpers.buildActivityDTO( PostActivityTestHelpers.DestinationStreamTestState.VALID, false, testComment, DESTINATION_ID); currentRequest = new PostActivityRequest(currentActivity); currentActionContext = new ServiceActionContext(currentRequest, currentPrincipal); context.checking(new Expectations() { { oneOf(postVerbValMock).validate(with(any(ActivityDTO.class))); oneOf(noteObjValMock).validate(with(any(ActivityDTO.class))); } }); sut.validate(currentActionContext); context.assertIsSatisfied(); }
@Override public void validate(final ServiceActionContext inActionContext) { ValidationException valEx = new ValidationException(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); ActivityDTO currentActivity = currentRequest.getActivityDTO(); if (currentActivity.getDestinationStream() == null || currentActivity.getDestinationStream().getUniqueIdentifier() == null || currentActivity.getDestinationStream().getUniqueIdentifier().length() <= 0) { valEx.addError("destination_stream", "Activities require a Destination Stream."); throw valEx; } if (!((currentActivity.getDestinationStream().getType() == EntityType.PERSON) || (currentActivity.getDestinationStream().getType() == EntityType.GROUP) || currentActivity .getDestinationStream().getType() == EntityType.RESOURCE)) { valEx.addError("destination_stream_type", "Activities can only be submitted to Person, Group, or Resource streams."); throw valEx; } if (verbValidators.containsKey(currentActivity.getVerb().name()) && objectValidators.containsKey(currentActivity.getBaseObjectType().name())) { try { ActivityValidator currentVerbVal = verbValidators.get(currentActivity.getVerb().name()); currentVerbVal.validate(currentActivity); ActivityValidator currentObjectVal = objectValidators.get(currentActivity.getBaseObjectType().name()); currentObjectVal.validate(currentActivity); } catch (ValidationException vex) { log.error("ActivityValidators failed for this activity.", vex); for (Entry<String, String> validationError : vex.getErrors().entrySet()) { valEx.addError(validationError.getKey(), validationError.getValue()); log.error("Error key: " + validationError.getKey() + " message: " + validationError.getValue()); } throw valEx; } } else { valEx.addError("validator_required", "The supplied activity does not have a corresponding validator and cannot be persisted."); throw valEx; } }
PostActivityValidationStrategy implements ValidationStrategy<ServiceActionContext> { @Override public void validate(final ServiceActionContext inActionContext) { ValidationException valEx = new ValidationException(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); ActivityDTO currentActivity = currentRequest.getActivityDTO(); if (currentActivity.getDestinationStream() == null || currentActivity.getDestinationStream().getUniqueIdentifier() == null || currentActivity.getDestinationStream().getUniqueIdentifier().length() <= 0) { valEx.addError("destination_stream", "Activities require a Destination Stream."); throw valEx; } if (!((currentActivity.getDestinationStream().getType() == EntityType.PERSON) || (currentActivity.getDestinationStream().getType() == EntityType.GROUP) || currentActivity .getDestinationStream().getType() == EntityType.RESOURCE)) { valEx.addError("destination_stream_type", "Activities can only be submitted to Person, Group, or Resource streams."); throw valEx; } if (verbValidators.containsKey(currentActivity.getVerb().name()) && objectValidators.containsKey(currentActivity.getBaseObjectType().name())) { try { ActivityValidator currentVerbVal = verbValidators.get(currentActivity.getVerb().name()); currentVerbVal.validate(currentActivity); ActivityValidator currentObjectVal = objectValidators.get(currentActivity.getBaseObjectType().name()); currentObjectVal.validate(currentActivity); } catch (ValidationException vex) { log.error("ActivityValidators failed for this activity.", vex); for (Entry<String, String> validationError : vex.getErrors().entrySet()) { valEx.addError(validationError.getKey(), validationError.getValue()); log.error("Error key: " + validationError.getKey() + " message: " + validationError.getValue()); } throw valEx; } } else { valEx.addError("validator_required", "The supplied activity does not have a corresponding validator and cannot be persisted."); throw valEx; } } }
PostActivityValidationStrategy implements ValidationStrategy<ServiceActionContext> { @Override public void validate(final ServiceActionContext inActionContext) { ValidationException valEx = new ValidationException(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); ActivityDTO currentActivity = currentRequest.getActivityDTO(); if (currentActivity.getDestinationStream() == null || currentActivity.getDestinationStream().getUniqueIdentifier() == null || currentActivity.getDestinationStream().getUniqueIdentifier().length() <= 0) { valEx.addError("destination_stream", "Activities require a Destination Stream."); throw valEx; } if (!((currentActivity.getDestinationStream().getType() == EntityType.PERSON) || (currentActivity.getDestinationStream().getType() == EntityType.GROUP) || currentActivity .getDestinationStream().getType() == EntityType.RESOURCE)) { valEx.addError("destination_stream_type", "Activities can only be submitted to Person, Group, or Resource streams."); throw valEx; } if (verbValidators.containsKey(currentActivity.getVerb().name()) && objectValidators.containsKey(currentActivity.getBaseObjectType().name())) { try { ActivityValidator currentVerbVal = verbValidators.get(currentActivity.getVerb().name()); currentVerbVal.validate(currentActivity); ActivityValidator currentObjectVal = objectValidators.get(currentActivity.getBaseObjectType().name()); currentObjectVal.validate(currentActivity); } catch (ValidationException vex) { log.error("ActivityValidators failed for this activity.", vex); for (Entry<String, String> validationError : vex.getErrors().entrySet()) { valEx.addError(validationError.getKey(), validationError.getValue()); log.error("Error key: " + validationError.getKey() + " message: " + validationError.getValue()); } throw valEx; } } else { valEx.addError("validator_required", "The supplied activity does not have a corresponding validator and cannot be persisted."); throw valEx; } } PostActivityValidationStrategy(final Map<String, ActivityValidator> inVerbValidators,
            final Map<String, ActivityValidator> inObjectValidators); }
PostActivityValidationStrategy implements ValidationStrategy<ServiceActionContext> { @Override public void validate(final ServiceActionContext inActionContext) { ValidationException valEx = new ValidationException(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); ActivityDTO currentActivity = currentRequest.getActivityDTO(); if (currentActivity.getDestinationStream() == null || currentActivity.getDestinationStream().getUniqueIdentifier() == null || currentActivity.getDestinationStream().getUniqueIdentifier().length() <= 0) { valEx.addError("destination_stream", "Activities require a Destination Stream."); throw valEx; } if (!((currentActivity.getDestinationStream().getType() == EntityType.PERSON) || (currentActivity.getDestinationStream().getType() == EntityType.GROUP) || currentActivity .getDestinationStream().getType() == EntityType.RESOURCE)) { valEx.addError("destination_stream_type", "Activities can only be submitted to Person, Group, or Resource streams."); throw valEx; } if (verbValidators.containsKey(currentActivity.getVerb().name()) && objectValidators.containsKey(currentActivity.getBaseObjectType().name())) { try { ActivityValidator currentVerbVal = verbValidators.get(currentActivity.getVerb().name()); currentVerbVal.validate(currentActivity); ActivityValidator currentObjectVal = objectValidators.get(currentActivity.getBaseObjectType().name()); currentObjectVal.validate(currentActivity); } catch (ValidationException vex) { log.error("ActivityValidators failed for this activity.", vex); for (Entry<String, String> validationError : vex.getErrors().entrySet()) { valEx.addError(validationError.getKey(), validationError.getValue()); log.error("Error key: " + validationError.getKey() + " message: " + validationError.getValue()); } throw valEx; } } else { valEx.addError("validator_required", "The supplied activity does not have a corresponding validator and cannot be persisted."); throw valEx; } } PostActivityValidationStrategy(final Map<String, ActivityValidator> inVerbValidators,
            final Map<String, ActivityValidator> inObjectValidators); @Override void validate(final ServiceActionContext inActionContext); }
PostActivityValidationStrategy implements ValidationStrategy<ServiceActionContext> { @Override public void validate(final ServiceActionContext inActionContext) { ValidationException valEx = new ValidationException(); PostActivityRequest currentRequest = (PostActivityRequest) inActionContext.getParams(); ActivityDTO currentActivity = currentRequest.getActivityDTO(); if (currentActivity.getDestinationStream() == null || currentActivity.getDestinationStream().getUniqueIdentifier() == null || currentActivity.getDestinationStream().getUniqueIdentifier().length() <= 0) { valEx.addError("destination_stream", "Activities require a Destination Stream."); throw valEx; } if (!((currentActivity.getDestinationStream().getType() == EntityType.PERSON) || (currentActivity.getDestinationStream().getType() == EntityType.GROUP) || currentActivity .getDestinationStream().getType() == EntityType.RESOURCE)) { valEx.addError("destination_stream_type", "Activities can only be submitted to Person, Group, or Resource streams."); throw valEx; } if (verbValidators.containsKey(currentActivity.getVerb().name()) && objectValidators.containsKey(currentActivity.getBaseObjectType().name())) { try { ActivityValidator currentVerbVal = verbValidators.get(currentActivity.getVerb().name()); currentVerbVal.validate(currentActivity); ActivityValidator currentObjectVal = objectValidators.get(currentActivity.getBaseObjectType().name()); currentObjectVal.validate(currentActivity); } catch (ValidationException vex) { log.error("ActivityValidators failed for this activity.", vex); for (Entry<String, String> validationError : vex.getErrors().entrySet()) { valEx.addError(validationError.getKey(), validationError.getValue()); log.error("Error key: " + validationError.getKey() + " message: " + validationError.getValue()); } throw valEx; } } else { valEx.addError("validator_required", "The supplied activity does not have a corresponding validator and cannot be persisted."); throw valEx; } } PostActivityValidationStrategy(final Map<String, ActivityValidator> inVerbValidators,
            final Map<String, ActivityValidator> inObjectValidators); @Override void validate(final ServiceActionContext inActionContext);  }