Search in sources :

Example 1 with Violation

use of io.syndesis.common.model.Violation in project syndesis by syndesisio.

the class SwaggerHelper method validateJSonSchema.

private static SwaggerModelInfo validateJSonSchema(final String specification, final Swagger model) {
    try {
        final JsonNode specRoot = convertToJson(specification);
        final ProcessingReport report = SWAGGER_2_0_SCHEMA.validate(specRoot);
        final List<Violation> errors = new ArrayList<>();
        final List<Violation> warnings = new ArrayList<>();
        for (final ProcessingMessage message : report) {
            final boolean added = append(errors, message, Optional.of("error"));
            if (!added) {
                append(warnings, message, Optional.empty());
            }
        }
        return new SwaggerModelInfo.Builder().errors(errors).warnings(warnings).model(model).resolvedSpecification(specification).build();
    } catch (IOException | ProcessingException ex) {
        LOG.error("Unable to load the schema file embedded in the artifact", ex);
        return new SwaggerModelInfo.Builder().addError(new Violation.Builder().error("error").property("").message("Unable to load the swagger schema file embedded in the artifact").build()).build();
    }
}
Also used : Violation(io.syndesis.common.model.Violation) ProcessingMessage(com.github.fge.jsonschema.core.report.ProcessingMessage) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) SwaggerModelInfo(io.syndesis.server.connector.generator.swagger.SwaggerModelInfo) IOException(java.io.IOException) ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with Violation

use of io.syndesis.common.model.Violation in project syndesis by syndesisio.

the class ConnectionsITCase method nullNamesShouldNotBeAllowed.

@Test
public void nullNamesShouldNotBeAllowed() {
    final Connection connection = new Connection.Builder().build();
    final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
    assertThat(got.getBody()).containsExactly(new Violation.Builder().property("name").error("NotNull").message("Value is required").build());
}
Also used : Violation(io.syndesis.common.model.Violation) Connection(io.syndesis.common.model.connection.Connection) List(java.util.List) Test(org.junit.Test)

Example 3 with Violation

use of io.syndesis.common.model.Violation in project syndesis by syndesisio.

the class ConnectionsITCase method shouldDetermineValidityForInvalidConnections.

@Test
public void shouldDetermineValidityForInvalidConnections() {
    final Connection connection = new Connection.Builder().name("Existing connection").build();
    final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
    assertThat(got.getBody()).containsExactly(new Violation.Builder().property("name").error("UniqueProperty").message("Value 'Existing connection' is not unique").build());
}
Also used : Violation(io.syndesis.common.model.Violation) Connection(io.syndesis.common.model.connection.Connection) List(java.util.List) Test(org.junit.Test)

Example 4 with Violation

use of io.syndesis.common.model.Violation in project syndesis by syndesisio.

the class ConnectionsITCase method violationsShouldBeGivenForInvalidConnectionCreation.

@Test
public void violationsShouldBeGivenForInvalidConnectionCreation() {
    final Connection connection = new Connection.Builder().name("Existing connection").build();
    final ResponseEntity<List<Violation>> got = post("/api/v1/connections", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
    assertThat(got.getBody()).containsExactly(new Violation.Builder().property("create.obj.name").error("UniqueProperty").message("Value 'Existing connection' is not unique").build());
}
Also used : Violation(io.syndesis.common.model.Violation) Connection(io.syndesis.common.model.connection.Connection) List(java.util.List) Test(org.junit.Test)

Example 5 with Violation

use of io.syndesis.common.model.Violation in project syndesis by syndesisio.

the class ConnectionsITCase method emptyNamesShouldNotBeAllowed.

@Test
public void emptyNamesShouldNotBeAllowed() {
    final Connection connection = new Connection.Builder().name(" ").build();
    final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
    assertThat(got.getBody()).containsExactly(new Violation.Builder().property("name").error("NotNull").message("Value is required").build());
}
Also used : Violation(io.syndesis.common.model.Violation) Connection(io.syndesis.common.model.connection.Connection) List(java.util.List) Test(org.junit.Test)

Aggregations

Violation (io.syndesis.common.model.Violation)6 List (java.util.List)5 Test (org.junit.Test)5 Connection (io.syndesis.common.model.connection.Connection)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 ProcessingMessage (com.github.fge.jsonschema.core.report.ProcessingMessage)1 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)1 Integration (io.syndesis.common.model.integration.Integration)1 SwaggerModelInfo (io.syndesis.server.connector.generator.swagger.SwaggerModelInfo)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1