EventSourceValidator extends AbstractValidator { @Override public List<ValidationEvent> validate(Model model) { return model.shapes(ServiceShape.class) .flatMap(service -> Trait.flatMapStream(service, ServiceTrait.class)) .flatMap(pair -> OptionalUtils.stream(validateService(pair.getLeft(), pair.getRight()))) .collect(toList()); }  @Override List<ValidationEvent> validate(Model model);  }
@Test public void detectsWhenEventSourceIsUnexpected() { ServiceTrait trait = ServiceTrait.builder() .sdkId("Foo") .arnNamespace("foo") .cloudTrailEventSource("REPLACE_ME_LATER") .cloudFormationName("AWS::Foo") .build(); ServiceShape service = ServiceShape.builder() .id("smithy.example#Foo") .version("123") .addTrait(trait) .build(); Model model = Model.builder().addShape(service).build(); EventSourceValidator validator = new EventSourceValidator(); List<ValidationEvent> events = validator.validate(model); ValidationEvent event = getMatchingEvent(events, validator.getName()); assertThat(event.getSeverity(), is(Severity.WARNING)); assertThat(event.getShapeId().get(), equalTo(service.getId())); assertThat(event.getMessage(), containsString("must not use placeholders")); }
@Test public void detectsWhenEventSourceIsPlaceholder() { ServiceTrait trait = ServiceTrait.builder() .sdkId("Foo") .arnNamespace("foo") .cloudTrailEventSource("notfoo.amazonaws.com") .cloudFormationName("AWS::Foo") .build(); ServiceShape service = ServiceShape.builder() .id("smithy.example#Foo") .version("123") .addTrait(trait) .build(); Model model = Model.builder().addShape(service).build(); EventSourceValidator validator = new EventSourceValidator(); List<ValidationEvent> events = validator.validate(model); ValidationEvent event = getMatchingEvent(events, validator.getName()); assertThat(event.getSeverity(), is(Severity.WARNING)); assertThat(event.getShapeId().get(), equalTo(service.getId())); assertThat(event.getMessage(), containsString("Expected 'foo.amazonaws.com', but found 'notfoo.amazonaws.com'")); }
@Test public void ignoresKnownExceptions() { ServiceTrait trait = ServiceTrait.builder() .sdkId("Foo") .arnNamespace("cloudwatch") .cloudTrailEventSource("monitoring.amazonaws.com") .cloudFormationName("AWS::Foo") .build(); ServiceShape service = ServiceShape.builder() .id("smithy.example#Foo") .version("123") .addTrait(trait) .build(); Model model = Model.builder().addShape(service).build(); EventSourceValidator validator = new EventSourceValidator(); List<ValidationEvent> events = validator.validate(model); Assertions.assertThrows(RuntimeException.class, () -> getMatchingEvent(events, validator.getName())); }