Search in sources :

Example 11 with ValidationViolation

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

the class FieldLabelRuleTest method testLabelNotChanged.

@Parameters(method = "fieldLabels")
@Test
public void testLabelNotChanged(final String label) throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", String.format("syntax = 'proto2';\n" + "message AMessage {\n" + "  %s int32 a_field = 1;" + "}", label));
    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 12 with ValidationViolation

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

the class FieldNameChangeRuleTest method testFieldNameChanged.

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

Example 13 with ValidationViolation

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

the class FieldNamingRuleTest method testAllowedName_new.

@Parameters(method = "allowedNames")
@Test
public void testAllowedName_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, is(empty()));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 14 with ValidationViolation

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

the class FieldTypeCompatibilityRuleTest method testFieldTypeUnchanged.

@Parameters(method = "typeUnchanged")
@Test
public void testFieldTypeUnchanged(final String typeName) throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, typeName));
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format(TEMPLATE, typeName));
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, 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 15 with ValidationViolation

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

the class FieldTypeCompatibilityRuleTest method testComplexFieldTypeChange.

@Parameters(method = "complexTypeChanges")
@Test
public void testComplexFieldTypeChange(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)

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