Search in sources :

Example 56 with ValidationViolation

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

the class FilePathAndPackageMatchRuleTest method testPackageAndPathMismatch.

@Test
public void testPackageAndPathMismatch() throws Exception {
    final DescriptorSet current = DescriptorSet.empty();
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("foo/bar/a.proto", "syntax = 'proto3';\n" + "package foo.baz;");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().description(equalTo("proto file path must match package name")).type(equalTo(ViolationType.BEST_PRACTICE_VIOLATION)).current(nullValue(GenericDescriptor.class)).candidate(genericDescriptor())));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 57 with ValidationViolation

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

the class JavaPackageRuleTest method existingFile_javaOptionMissing.

@Test
public void existingFile_javaOptionMissing() throws Exception {
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "package foo.bar;\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 58 with ValidationViolation

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

the class MessageNamingRuleTest 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 59 with ValidationViolation

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

the class MessageNamingRuleTest 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 60 with ValidationViolation

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

the class MessageNamingRuleTest 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("message name should be UpperCamelCase")).type(equalTo(ViolationType.STYLE_GUIDE_VIOLATION)).current(nullValue(GenericDescriptor.class)).candidate(genericDescriptor().sourceCodeInfo(optionalWithValue(sourceCodeInfo().start(filePosition().line(2).column(1)))))));
}
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