Search in sources :

Example 36 with ValidationViolation

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

the class EnumNamingRuleTest method testDisallowedName_existing.

@Parameters(method = "disallowedNames")
@Test
public void testDisallowedName_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 37 with ValidationViolation

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

the class EnumValueNamingRuleTest 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", "syntax = 'proto3';\n" + "enum EnumWithNewValue {\n" + String.format("  %s = 0;\n", 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 38 with ValidationViolation

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

the class EnumValueNamingRuleTest 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 39 with ValidationViolation

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

the class EnumValueNamingRuleTest 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("enum value should be UPPER_SNAKE_CASE")).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)

Example 40 with ValidationViolation

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

the class EnumValueRemovalRuleTest method testEnumValueRemoved_numberReserved.

@Test
public void testEnumValueRemoved_numberReserved() 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 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 removed"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) 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