Skip to content

Commit

Permalink
Excavator: Format Java files (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot authored Apr 6, 2020
1 parent 5927fc5 commit b6454e1
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 135 deletions.
4 changes: 0 additions & 4 deletions .baseline/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@
<property name="separated" value="true"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<module name="Indentation"> <!-- Java Style Guide: Block indentation: +4 spaces -->
<property name="arrayInitIndent" value="8"/>
<property name="lineWrappingIndentation" value="8"/>
</module>
<module name="InnerAssignment"/> <!-- Java Coding Guidelines: Inner assignments: Not used -->
<module name="LeftCurly"/> <!-- Java Style Guide: Nonempty blocks: K & R style -->
<module name="LineLength"> <!-- Java Style Guide: No line-wrapping -->
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ buildscript {
}

dependencies {
classpath 'com.palantir.javaformat:gradle-palantir-java-format:1.0.0'
classpath 'com.netflix.nebula:gradle-info-plugin:7.1.3'
classpath 'com.netflix.nebula:nebula-publishing-plugin:17.2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
Expand All @@ -40,6 +41,7 @@ apply plugin: 'com.palantir.baseline'
apply from: 'gradle/publish-rust-dist.gradle'

allprojects {
apply plugin: 'com.palantir.java-format'
version gitVersion()
group 'com.palantir.conjure.verification'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public String visitList(ListType type) {

@Override
public String visitMap(MapType type) {
return "mapOf" + StringUtils.capitalize(type.keyType().visit(this))
+ "To" + StringUtils.capitalize(type.valueType().visit(this));
return "mapOf" + StringUtils.capitalize(type.keyType().visit(this)) + "To"
+ StringUtils.capitalize(type.valueType().visit(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ public static void main(String... args) throws IOException {
generateAutoDeserializeService(testCases.getBody()));
}

private static void writeServiceDefinition(
File fileName, String serviceName, Map<String, Object> service) throws IOException {
TestCasesUtils.YAML_MAPPER.writeValue(fileName,
createConjureYmlBuilder().put("services", ImmutableMap.of(serviceName, service)).build());
private static void writeServiceDefinition(File fileName, String serviceName, Map<String, Object> service)
throws IOException {
TestCasesUtils.YAML_MAPPER.writeValue(
fileName,
createConjureYmlBuilder()
.put("services", ImmutableMap.of(serviceName, service))
.build());
}

private static ImmutableMap.Builder<String, Object> createConjureYmlBuilder() {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
builder.put(
"types",
ImmutableMap.of("conjure-imports",
ImmutableMap.of(
"conjure-imports",
ImmutableMap.of(
"examples", "../example-types.conjure.yml",
"testCases", "../test-cases.conjure.yml")));
Expand All @@ -55,14 +59,22 @@ private static ImmutableMap.Builder<String, Object> createConjureYmlBuilder() {
private static Map<String, Object> generateAutoDeserializeService(List<BodyTests> bodyTests) {
ImmutableMap.Builder<String, Object> endpoints = ImmutableMap.builder();

bodyTests.stream().map(BodyTests::getType).map(TestCasesUtils::parseConjureType).forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("get", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(endpointName, ImmutableMap.of(
"http", "POST /" + endpointName,
"returns", typeName,
"args", ImmutableMap.of("body", typeName)));
});
bodyTests.stream()
.map(BodyTests::getType)
.map(TestCasesUtils::parseConjureType)
.forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("get", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(
endpointName,
ImmutableMap.of(
"http",
"POST /" + endpointName,
"returns",
typeName,
"args",
ImmutableMap.of("body", typeName)));
});

return ImmutableMap.of(
"name", "Auto Deserialize Service",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,61 @@ public static void main(String... args) throws IOException {
Files.createDirectories(outputDir.toPath());
MoreFiles.deleteDirectoryContents(outputDir.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);

writeServiceDefinition(new File(outputDir, "auto-deserialize-service.conjure.yml"),
writeServiceDefinition(
new File(outputDir, "auto-deserialize-service.conjure.yml"),
"AutoDeserializeService",
generateAutoDeserializeService(testCases.getBody()));
writeServiceDefinition(
new File(outputDir, "auto-deserialize-confirm-service.conjure.yml"),
"AutoDeserializeConfirmService",
generateAutoDeserializeConfirmService(testCases.getBody()));
writeServiceDefinition(new File(outputDir, "single-header-service.conjure.yml"),
writeServiceDefinition(
new File(outputDir, "single-header-service.conjure.yml"),
"SingleHeaderService",
generateSingleHeaderService(testCases.getSingleHeaderParam()));
writeServiceDefinition(new File(outputDir, "single-path-param-service.conjure.yml"),
writeServiceDefinition(
new File(outputDir, "single-path-param-service.conjure.yml"),
"SinglePathParamService",
generateSinglePathParamService(testCases.getSinglePathParam()));
writeServiceDefinition(new File(outputDir, "single-query-param-service.conjure.yml"),
writeServiceDefinition(
new File(outputDir, "single-query-param-service.conjure.yml"),
"SingleQueryParamService",
generateSingleQueryParamService(testCases.getSingleQueryParam()));
}

private static Map<String, Object> generateAutoDeserializeConfirmService(List<BodyTests> body) {
ImmutableMap.Builder<String, Object> endpoints = ImmutableMap.builder();
endpoints.put("confirm", ImmutableMap.builder()
.put("http", "POST /{endpoint}/{index}")
.put("docs", "Send the response received for positive test cases here to verify that it has been "
+ "serialized and deserialized properly.")
.put("args", ImmutableMap.builder()
.put("endpoint", "testCases.EndpointName")
.put("index", "integer")
.put("body", "any")
.build())
.build());

body.stream().map(BodyTests::getType).map(TestCasesUtils::parseConjureType).forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("receive", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(endpointName, ImmutableMap.of(
"http", "POST /" + endpointName + "/{index}",
"args", ImmutableMap.of("index", "integer", "body", typeName)));
});
endpoints.put(
"confirm",
ImmutableMap.builder()
.put("http", "POST /{endpoint}/{index}")
.put(
"docs",
"Send the response received for positive test cases here to verify that it has been "
+ "serialized and deserialized properly.")
.put(
"args",
ImmutableMap.builder()
.put("endpoint", "testCases.EndpointName")
.put("index", "integer")
.put("body", "any")
.build())
.build());

body.stream()
.map(BodyTests::getType)
.map(TestCasesUtils::parseConjureType)
.forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("receive", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(
endpointName,
ImmutableMap.of(
"http",
"POST /" + endpointName + "/{index}",
"args",
ImmutableMap.of("index", "integer", "body", typeName)));
});

return ImmutableMap.of(
"name", "Auto Deserialize Confirm Service",
Expand All @@ -76,17 +93,21 @@ private static Map<String, Object> generateAutoDeserializeConfirmService(List<Bo
"endpoints", endpoints.build());
}

private static void writeServiceDefinition(
File fileName, String serviceName, Map<String, Object> service) throws IOException {
TestCasesUtils.YAML_MAPPER.writeValue(fileName,
createConjureYmlBuilder().put("services", ImmutableMap.of(serviceName, service)).build());
private static void writeServiceDefinition(File fileName, String serviceName, Map<String, Object> service)
throws IOException {
TestCasesUtils.YAML_MAPPER.writeValue(
fileName,
createConjureYmlBuilder()
.put("services", ImmutableMap.of(serviceName, service))
.build());
}

private static ImmutableMap.Builder<String, Object> createConjureYmlBuilder() {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
builder.put(
"types",
ImmutableMap.of("conjure-imports",
ImmutableMap.of(
"conjure-imports",
ImmutableMap.of(
"examples", "../example-types.conjure.yml",
"testCases", "../test-cases.conjure.yml")));
Expand All @@ -96,14 +117,22 @@ private static ImmutableMap.Builder<String, Object> createConjureYmlBuilder() {
private static Map<String, Object> generateAutoDeserializeService(List<BodyTests> bodyTests) {
ImmutableMap.Builder<String, Object> endpoints = ImmutableMap.builder();

bodyTests.stream().map(BodyTests::getType).map(TestCasesUtils::parseConjureType).forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("receive", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(endpointName, ImmutableMap.of(
"http", "GET /" + endpointName + "/{index}",
"returns", typeName,
"args", ImmutableMap.of("index", "integer")));
});
bodyTests.stream()
.map(BodyTests::getType)
.map(TestCasesUtils::parseConjureType)
.forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("receive", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(
endpointName,
ImmutableMap.of(
"http",
"GET /" + endpointName + "/{index}",
"returns",
typeName,
"args",
ImmutableMap.of("index", "integer")));
});

return ImmutableMap.of(
"name", "Auto Deserialize Service",
Expand All @@ -116,21 +145,26 @@ private static Map<String, Object> generateAutoDeserializeService(List<BodyTests
private static Map<String, Object> generateSingleHeaderService(List<SingleHeaderParamTests> testCases) {
ImmutableMap.Builder<String, Object> endpoints = ImmutableMap.builder();

testCases
.stream()
testCases.stream()
.map(SingleHeaderParamTests::getType)
.map(TestCasesUtils::parseConjureType)
.forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("header", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(endpointName, ImmutableMap.of(
"http", "POST /" + endpointName + "/{index}",
"args", ImmutableMap.of(
"index", "integer",
"header", ImmutableMap.of(
"type", typeName,
"param-type", "header",
"param-id", "Some-Header"))));
endpoints.put(
endpointName,
ImmutableMap.of(
"http",
"POST /" + endpointName + "/{index}",
"args",
ImmutableMap.of(
"index",
"integer",
"header",
ImmutableMap.of(
"type", typeName,
"param-type", "header",
"param-id", "Some-Header"))));
});

return ImmutableMap.of(
Expand All @@ -144,18 +178,19 @@ private static Map<String, Object> generateSingleHeaderService(List<SingleHeader
private static Map<String, Object> generateSinglePathParamService(List<SinglePathParamTests> testCases) {
ImmutableMap.Builder<String, Object> endpoints = ImmutableMap.builder();

testCases
.stream()
testCases.stream()
.map(SinglePathParamTests::getType)
.map(TestCasesUtils::parseConjureType)
.forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("pathParam", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(endpointName, ImmutableMap.of(
"http", "POST /" + endpointName + "/{index}/{param}",
"args", ImmutableMap.of(
"index", "integer",
"param", typeName)));
endpoints.put(
endpointName,
ImmutableMap.of(
"http",
"POST /" + endpointName + "/{index}/{param}",
"args",
ImmutableMap.of("index", "integer", "param", typeName)));
});

return ImmutableMap.of(
Expand All @@ -175,14 +210,20 @@ private static Map<String, Object> generateSingleQueryParamService(List<SingleQu
.forEach(conjureType -> {
String endpointName = TestCasesUtils.typeToEndpointName("queryParam", conjureType);
String typeName = conjureType.visit(new ResolveLocalReferencesConjureTypeVisitor());
endpoints.put(endpointName, ImmutableMap.of(
"http", "POST /" + endpointName + "/{index}",
"args", ImmutableMap.of(
"index", "integer",
"someQuery", ImmutableMap.of(
"type", typeName,
"param-type", "query",
"param-id", "foo"))));
endpoints.put(
endpointName,
ImmutableMap.of(
"http",
"POST /" + endpointName + "/{index}",
"args",
ImmutableMap.of(
"index",
"integer",
"someQuery",
ImmutableMap.of(
"type", typeName,
"param-type", "query",
"param-id", "foo"))));
});

return ImmutableMap.of(
Expand All @@ -192,5 +233,4 @@ private static Map<String, Object> generateSingleQueryParamService(List<SingleQu
"base-path", "/single-query-param",
"endpoints", endpoints.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import org.apache.commons.lang3.StringUtils;

public final class TestCasesUtils {
public static final ObjectMapper YAML_MAPPER = ObjectMappers
.withDefaultModules(new ObjectMapper(new YAMLFactory()))
public static final ObjectMapper YAML_MAPPER = ObjectMappers.withDefaultModules(new ObjectMapper(new YAMLFactory()))
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

private TestCasesUtils() {}
Expand Down
Loading

0 comments on commit b6454e1

Please sign in to comment.