Search in sources :

Example 41 with ValidationViolation

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

the class EnumValueRemovalRuleTest method testEnumValueRemoved_numberAndNameReserved.

@Test
public void testEnumValueRemoved_numberAndNameReserved() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "enum Derp {\n" + "  A = 0;\n" + "  B = 1;\n" + "}");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "enum Derp {\n" + "  A = 0;\n" + "  reserved \"B\";\n" + "  reserved 1;\n" + "}");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.GENERATED_SOURCE_CODE_INCOMPATIBILITY_VIOLATION)).description(equalTo("enum value made reserved"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 42 with ValidationViolation

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

the class EnumValueRemovalRuleTest method testEnumValueRemoved_nameReserved.

@Test
public void testEnumValueRemoved_nameReserved() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "enum Derp {\n" + "  A = 0;\n" + "  B = 1;\n" + "}");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "enum Derp {\n" + "  A = 0;\n" + "  reserved \"B\";\n" + "}");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.GENERATED_SOURCE_CODE_INCOMPATIBILITY_VIOLATION)).description(equalTo("enum value removed"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 43 with ValidationViolation

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

the class FieldJsonNameRuleTest method testJsonNameUnchanged.

@Test
public void testJsonNameUnchanged() throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", "syntax = 'proto3';\n" + "package foo.bar;\n" + "message AMessage {\n" + "  int32 a_field = 1;" + "}");
    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) Test(org.junit.Test)

Example 44 with ValidationViolation

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

the class FieldLabelRuleTest method testWireIncompatChange.

@Parameters(method = "wireIncompat")
@Test
public void testWireIncompatChange(final String from, final String to) throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", String.format("syntax = 'proto2';\n" + "message AMessage {\n" + "  %s int32 a_field = 1;" + "}", from));
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", String.format("syntax = 'proto2';\n" + "message AMessage {\n" + "  %s int32 a_field = 1;" + "}", to));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.WIRE_INCOMPATIBILITY_VIOLATION)).description(equalTo("field label changed to/from required"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 45 with ValidationViolation

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

the class FieldLabelRuleTest method testGeneratedSourceIncompat.

@Parameters(method = "generatedSourceIncompat")
@Test
public void testGeneratedSourceIncompat(final String from, final String to) throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", String.format("syntax = 'proto2';\n" + "message AMessage {\n" + "  %s int32 a_field = 1;" + "}", from));
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", String.format("syntax = 'proto2';\n" + "message AMessage {\n" + "  %s int32 a_field = 1;" + "}", to));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.GENERATED_SOURCE_CODE_INCOMPATIBILITY_VIOLATION)).description(equalTo("field label changed"))));
}
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