Search in sources :

Example 21 with DescriptorSet

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

the class JavaPackageRuleTest method existingFile_javaOptionChanged.

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

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

the class MessageNamingRuleTest 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 23 with DescriptorSet

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

the class MethodClientStreamingCompatibilityRuleTest method testClientUnaryToClientStreaming.

@Test
public void testClientUnaryToClientStreaming() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "  rpc GetDerp (Empty) returns (Empty);\n" + "}\n" + "message Empty {}\n");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "  rpc GetDerp (stream Empty) returns (Empty);\n" + "}\n" + "message Empty {}\n");
    final ImmutableList<ValidationViolation> violations = schemaValidator.validate(current, candidate);
    assertThat(violations, contains(validationViolation().description(equalTo("changed to/from client streaming")).type(equalTo(ViolationType.WIRE_INCOMPATIBILITY_VIOLATION))));
}
Also used : ValidationViolation(com.spotify.protoman.validation.ValidationViolation) DescriptorSet(com.spotify.protoman.descriptor.DescriptorSet) Test(org.junit.Test)

Example 24 with DescriptorSet

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

the class MethodIdempotencyChangeRuleTest method testIdempotencyChange_allowed.

@Parameters(method = "allowedIdempotencyChanges")
@Test
public void testIdempotencyChange_allowed(final String from, final String to) throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format("syntax = 'proto3';\n" + "service Foo {\n" + "  rpc GetFoo(Derp) returns (Derp) { option idempotency_level = %s; };\n" + "}\n" + "message Derp {}", from));
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", String.format("syntax = 'proto3';\n" + "service Foo {\n" + "  rpc GetFoo(Derp) returns (Derp) { option idempotency_level = %s; };\n" + "}\n" + "message Derp {}", to));
    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 25 with DescriptorSet

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

the class MethodRemovalRuleTest method testNoChange.

@Test
public void testNoChange() throws Exception {
    final DescriptorSet current = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "  rpc GetDerp (HerpDerp) returns (HerpDerp);\n" + "}\n" + "message HerpDerp {}");
    final DescriptorSet candidate = DescriptorSetUtils.buildDescriptorSet("a.proto", "syntax = 'proto3';\n" + "service Derp {\n" + "  rpc GetDerp (HerpDerp) returns (HerpDerp);\n" + "}\n" + "message HerpDerp {}");
    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)

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