Search in sources :

Example 61 with ValidationViolation

use of com.spotify.protoman.validation.ValidationViolation in project protoman by spotify.

the class MethodClientStreamingCompatibilityRuleTest method testClientStreamingToClientUnary.

@Test
public void testClientStreamingToClientUnary() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "  rpc GetDerp (stream Empty) returns (Empty);\n" + "}\n" + "message Empty {}\n");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "  rpc GetDerp (Empty) returns (Empty);\n" + "}\n" + "message Empty {}\n");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().description(equalTo("changed to/from client streaming")).type(equalTo(ViolationType.WIRE_INCOMPATIBILITY_VIOLATION))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 62 with ValidationViolation

use of com.spotify.protoman.validation.ValidationViolation in project protoman by spotify.

the class MethodIdempotencyChangeRuleTest method testIdempotencyChange_disallowed.

@Parameters(method = "disallowedIdempotencyChanges")
@Test
public void testIdempotencyChange_disallowed(final String from, final String to) throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format("syntax = 'proto3';\n" + "service Foo {\n" + "  rpc GetFoo(Derp) returns (Derp) { option idempotency_level = %s; };\n" + "}\n" + "message Derp {}", from));
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format("syntax = 'proto3';\n" + "service Foo {\n" + "  rpc GetFoo(Derp) returns (Derp) { option idempotency_level = %s; };\n" + "}\n" + "message Derp {}", to));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.BEST_PRACTICE_VIOLATION)).description(equalTo("Idempotency level changed to less strict"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 63 with ValidationViolation

use of com.spotify.protoman.validation.ValidationViolation in project protoman by spotify.

the class MethodInputTypeCompatibilityRuleTest method testInputTypeChanged.

@Parameters(method = "testCases")
@Test
public void testInputTypeChanged(final String currentType, final String candidateType, final ViolationType expectedViolationType, final String expectedDescription) throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, currentType));
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, candidateType));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().description(equalTo(expectedDescription)).type(equalTo(expectedViolationType))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 64 with ValidationViolation

use of com.spotify.protoman.validation.ValidationViolation in project protoman by spotify.

the class MethodNamingRuleTest method testAllowedName_existing.

@Parameters(method = "allowedNames")
@Test
public void testAllowedName_existing(final String name) throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, name));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(candidate, candidate);
    assertThat(violations, is(empty()));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 65 with ValidationViolation

use of com.spotify.protoman.validation.ValidationViolation in project protoman by spotify.

the class MethodNamingRuleTest method testDisallowedName_new.

@Parameters(method = "disallowedNames")
@Test
public void testDisallowedName_new(final String name) throws Exception {
    final DescriptorSet current = DescriptorSet.empty();
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, name));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().description(equalTo("method name should be UpperCamelCase")).type(equalTo(ViolationType.STYLE_GUIDE_VIOLATION)).current(nullValue(GenericDescriptor.class)).candidate(genericDescriptor().sourceCodeInfo(optionalWithValue(sourceCodeInfo().start(filePosition().line(3).column(3)))))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

ValidationViolation (com.spotify.protoman.validation.ValidationViolation)76 DescriptorSet (com.spotify.protoman.descriptor.DescriptorSet)75 Test (org.junit.Test)74 Parameters (junitparams.Parameters)43 DescriptorBuilderException (com.spotify.protoman.descriptor.DescriptorBuilderException)1 GenericDescriptor (com.spotify.protoman.descriptor.GenericDescriptor)1 SchemaStorage (com.spotify.protoman.registry.storage.SchemaStorage)1 Path (java.nio.file.Path)1 Nullable (javax.annotation.Nullable)1