Search in sources :

Example 46 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet 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 47 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet 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 48 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet 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)

Example 49 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class FieldNameChangeRuleTest method testFieldNameUnchanged.

@Test
public void testFieldNameUnchanged() throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", "syntax = 'proto3';\n" + "message Herp {\n" + "  int32 derp = 1;\n" + "}");
    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 50 with DescriptorSet

use of com.spotify.protoman.descriptor.DescriptorSet in project protoman by spotify.

the class FieldNamingRuleTest 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("field name should be lower_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)

Aggregations

DescriptorSet (com.spotify.protoman.descriptor.DescriptorSet)79 ValidationViolation (com.spotify.protoman.validation.ValidationViolation)76 Test (org.junit.Test)74 Parameters (junitparams.Parameters)43 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 DescriptorProtos (com.google.protobuf.DescriptorProtos)3 FileDescriptor (com.spotify.protoman.descriptor.FileDescriptor)3 Objects (java.util.Objects)3 Function (java.util.function.Function)3 Nullable (javax.annotation.Nullable)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 DescriptorBuilderException (com.spotify.protoman.descriptor.DescriptorBuilderException)2 SchemaStorage (com.spotify.protoman.registry.storage.SchemaStorage)2 Path (java.nio.file.Path)2 Predicate (java.util.function.Predicate)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AutoValue (com.google.auto.value.AutoValue)1