Search in sources :

Example 51 with ValidationViolation

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

the class FieldRemovalRuleTest method testFieldRemoved.

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

Example 52 with ValidationViolation

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

the class FieldRemovalRuleTest method testFieldRemoved_nameReserved.

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

Example 53 with ValidationViolation

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

the class FieldRemovalRuleTest method testFieldRemoved_numberAndNameReserved.

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

Example 54 with ValidationViolation

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

the class FieldTypeCompatibilityRuleTest method testWireIncompatibleFieldTypeChange.

@Parameters(method = "wireIncompatiblePrimitiveTypeChanges")
@Test
public void testWireIncompatibleFieldTypeChange(final String currentType, final String candidateType) 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(String.format("wire-incompatible field type change %s -> %s", currentType.toUpperCase(), candidateType.toUpperCase()))).type(equalTo(ViolationType.WIRE_INCOMPATIBILITY_VIOLATION))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 55 with ValidationViolation

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

the class FieldTypeCompatibilityRuleTest method testWireCompatibleFieldTypeChange.

@Parameters(method = "wireCompatiblePrimitiveTypeChanges")
@Test
public void testWireCompatibleFieldTypeChange(final String currentType, final String candidateType) 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("field type changed (wire-compat)")).type(equalTo(ViolationType.GENERATED_SOURCE_CODE_INCOMPATIBILITY_VIOLATION))));
}
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