builder.append('\n'); for (ServiceElement service : services()) { builder.append(service.toSchema());
@Test public void emptyToSchema() { ServiceElement service = ServiceElement.builder(location).name("Service").build(); String expected = "service Service {}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void singleToSchema() { ServiceElement service = ServiceElement.builder(location) .name("Service") .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); String expected = "" + "service Service {\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void multipleToSchema() { RpcElement rpc = RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build(); ServiceElement service = ServiceElement.builder(location) .name("Service") .rpcs(ImmutableList.of(rpc, rpc)) .build(); String expected = "" + "service Service {\n" + " rpc Name (RequestType) returns (ResponseType);\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void singleWithOptionsToSchema() { ServiceElement service = ServiceElement.builder(location) .name("Service") .options(ImmutableList.of( OptionElement.create("foo", Kind.STRING, "bar"))) .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); String expected = "" + "service Service {\n" + " option foo = \"bar\";\n" + "\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
@Test public void singleWithDocumentationToSchema() { ServiceElement service = ServiceElement.builder(location) .name("Service") .documentation("Hello") .rpcs(ImmutableList.of( RpcElement.builder(location) .name("Name") .requestType("RequestType") .responseType("ResponseType") .build())) .build(); String expected = "" + "// Hello\n" + "service Service {\n" + " rpc Name (RequestType) returns (ResponseType);\n" + "}\n"; assertThat(service.toSchema()).isEqualTo(expected); }
builder.append('\n'); for (ServiceElement service : services()) { builder.append(service.toSchema());
builder.append('\n'); for (ServiceElement service : services()) { builder.append(service.toSchema());