Search in sources :

Example 16 with DescriptorSet

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

Example 17 with DescriptorSet

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

the class FilePathAndPackageMatchRuleTest method testPackageAndPathMatches.

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

Example 18 with DescriptorSet

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

the class JavaPackageRuleTest method existingFile_javaOptionAdded.

@Test
public void existingFile_javaOptionAdded() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "package foo.bar;\n");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "package foo.bar;\n" + "option java_package = 'com.foo.bar';");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.GENERATED_SOURCE_CODE_INCOMPATIBILITY_VIOLATION)).description(equalTo("Java package changed"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 19 with DescriptorSet

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

the class JavaPackageRuleTest method newFile_javaOptionPresent.

@Test
public void newFile_javaOptionPresent() throws Exception {
    final DescriptorSet current = DescriptorSet.empty();
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "package foo.bar;\n" + "option java_package = 'com.foo.bar';");
    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) Test(org.junit.Test)

Example 20 with DescriptorSet

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

the class JavaPackageRuleTest method newFile_javaOptionMissing.

@Test
public void newFile_javaOptionMissing() throws Exception {
    final DescriptorSet current = DescriptorSet.empty();
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "package foo.bar;\n");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().type(equalTo(ViolationType.BEST_PRACTICE_VIOLATION)).description(equalTo("java_package option should be set"))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) 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