Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try palantir-java-format #599

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
@RunWith(Parameterized.class)
public class AutoDeserializeTest {

@ClassRule
public static final VerificationServerRule server = new VerificationServerRule();
@ClassRule public static final VerificationServerRule server = new VerificationServerRule();

private static final Logger log = LoggerFactory.getLogger(AutoDeserializeTest.class);
private static final AutoDeserializeService testService = VerificationClients.autoDeserializeService(server);
Expand All @@ -63,13 +62,12 @@ public static Collection<Object[]> data() {
int positiveSize = positiveAndNegativeTestCases.getPositive().size();
int negativeSize = positiveAndNegativeTestCases.getNegative().size();

IntStream.range(0, positiveSize).forEach(i -> objects.add(new Object[] {
endpointName, i, true,
positiveAndNegativeTestCases.getPositive().get(i)}));
IntStream.range(0, positiveSize).forEach(i -> objects.add(
new Object[] {endpointName, i, true, positiveAndNegativeTestCases.getPositive().get(i)}));

IntStream.range(0, negativeSize).forEach(i -> objects.add(new Object[] {
endpointName, positiveSize + i, false,
positiveAndNegativeTestCases.getNegative().get(i)}));
endpointName, positiveSize + i, false, positiveAndNegativeTestCases.getNegative().get(i)
}));
});
return objects;
}
Expand All @@ -79,11 +77,9 @@ public void runTestCase() throws Exception {
Assume.assumeFalse(Cases.shouldIgnore(endpointName, jsonString));

Method method = testService.getClass().getMethod(endpointName.get(), int.class);
System.out.println(String.format("Test case %s: Invoking %s(%s), expected %s",
index,
endpointName,
jsonString,
shouldSucceed ? "success" : "failure"));
System.out.println(String.format(
"Test case %s: Invoking %s(%s), expected %s",
index, endpointName, jsonString, shouldSucceed ? "success" : "failure"));

if (shouldSucceed) {
expectSuccess(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,32 @@

public final class Cases {

public static final ClientTestCases TEST_CASES = deserializeTestCases(
new File("build/test-cases/test-cases.json"));
private static final IgnoredClientTestCases IGNORED_TEST_CASES = deserializeIgnoredClientTestCases(
new File("src/test/resources/ignored-test-cases.yml"));
public static final ClientTestCases TEST_CASES = deserializeTestCases(new File("build/test-cases/test-cases.json"));
private static final IgnoredClientTestCases IGNORED_TEST_CASES =
deserializeIgnoredClientTestCases(new File("src/test/resources/ignored-test-cases.yml"));

private Cases() {}

private static ClientTestCases deserializeTestCases(File file) {
try {
return new ObjectMapper()
.registerModule(new Jdk8Module())
.readValue(file, com.palantir.conjure.verification.server.TestCases.class).getClient();
.readValue(file, com.palantir.conjure.verification.server.TestCases.class)
.getClient();
} catch (IOException e) {
throw new RuntimeException(
String.format("Unable to read %s, you may need to run ./gradlew copyTestCases", file),
e);
String.format("Unable to read %s, you may need to run ./gradlew copyTestCases", file), e);
}
}

private static IgnoredClientTestCases deserializeIgnoredClientTestCases(File file) {
try {
return new ObjectMapper(new YAMLFactory())
.registerModule(new Jdk8Module())
.readValue(file, IgnoredTestCases.class).getClient();
.readValue(file, IgnoredTestCases.class)
.getClient();
} catch (IOException e) {
throw new RuntimeException(
String.format("Unable to read %s", file),
e);
throw new RuntimeException(String.format("Unable to read %s", file), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
@RunWith(Parameterized.class)
public class SingleParamServicesTest {

@ClassRule
public static final VerificationServerRule server = new VerificationServerRule();
@ClassRule public static final VerificationServerRule server = new VerificationServerRule();

private static final Logger log = LoggerFactory.getLogger(SingleParamServicesTest.class);
private static final ObjectMapper objectMapper = ObjectMappers.newClientObjectMapper();
Expand All @@ -66,26 +65,20 @@ public static Collection<Object[]> data() {
List<Object[]> objects = new ArrayList<>();
Cases.TEST_CASES.getSingleHeaderService().forEach((endpointName, singleHeaderTestCases) -> {
int size = singleHeaderTestCases.size();
IntStream.range(0, size)
.forEach(i -> objects.add(
new Object[] {"singleHeaderService", endpointName, i, singleHeaderTestCases.get(i)}));

IntStream.range(0, size).forEach(i -> objects.add(
new Object[] {"singleHeaderService", endpointName, i, singleHeaderTestCases.get(i)}));
});

Cases.TEST_CASES.getSinglePathParamService().forEach((endpointName, singleHeaderTestCases) -> {
int size = singleHeaderTestCases.size();
IntStream.range(0, size)
.forEach(i -> objects.add(
new Object[] {"singlePathParamService", endpointName, i, singleHeaderTestCases.get(i)}));

IntStream.range(0, size).forEach(i -> objects.add(
new Object[] {"singlePathParamService", endpointName, i, singleHeaderTestCases.get(i)}));
});

Cases.TEST_CASES.getSingleQueryParamService().forEach((endpointName, singleQueryTestCases) -> {
int size = singleQueryTestCases.size();
IntStream.range(0, size)
.forEach(i -> objects.add(
new Object[] {"singleQueryParamService", endpointName, i, singleQueryTestCases.get(i)}));

IntStream.range(0, size).forEach(i -> objects.add(
new Object[] {"singleQueryParamService", endpointName, i, singleQueryTestCases.get(i)}));
});

return objects;
Expand All @@ -112,13 +105,11 @@ public void runTestCase() throws Exception {
if ("singleHeaderService".equals(serviceName)) {
Type type = method.getGenericParameterTypes()[0];
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(
service, objectMapper.readValue(jsonString, cls), index);
method.invoke(service, objectMapper.readValue(jsonString, cls), index);
} else {
Type type = method.getGenericParameterTypes()[1];
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(
service, index, objectMapper.readValue(jsonString, cls));
method.invoke(service, index, objectMapper.readValue(jsonString, cls));
}

log.info("Successfully post param to endpoint {} and index {}", endpointName, index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public static SinglePathParamService singlePathParamService(VerificationServerRu

public static SingleHeaderService singleHeaderService(VerificationServerRule server) {
return JaxRsClient.create(
SingleHeaderService.class,
getUserAgent(),
new HostMetricsRegistry(),
server.getClientConfiguration());
SingleHeaderService.class, getUserAgent(), new HostMetricsRegistry(), server.getClientConfiguration());
}

public static SingleQueryParamService singleQueryParamService(VerificationServerRule server) {
return JaxRsClient.create(SingleQueryParamService.class,
return JaxRsClient.create(
SingleQueryParamService.class,
getUserAgent(),
new HostMetricsRegistry(),
server.getClientConfiguration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public ClientConfiguration getClientConfiguration() {
@Override
public void before() throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder(
"build/verification/verifier",
"build/test-cases/test-cases.json",
"build/test-cases/verification-api.json")
"build/verification/verifier",
"build/test-cases/test-cases.json",
"build/test-cases/verification-api.json")
.redirectErrorStream(true)
.redirectOutput(Redirect.PIPE);

Expand All @@ -65,8 +65,8 @@ public void before() throws Exception {
private static void blockUntilServerStarted(InputStream inputStream) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Thread thread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,
StandardCharsets.UTF_8))) {
try (BufferedReader reader =
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
while (true) {
String line = reader.readLine();
if (line == null) {
Expand Down
7 changes: 7 additions & 0 deletions conjure-java-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ tasks.withType(JavaCompile) {
// this complains about the integrationInput directory
options.errorprone.errorproneArgs += '-Xep:StrictUnusedVariable:OFF'
}

spotless {
java {
// these are generated files which we check-in to do snapshot testing, don't want them reformatted!
targetExclude 'src/integrationInput/**'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@

public enum FeatureFlags {
/**
* Instructs the {@link Retrofit2ServiceGenerator} to generate service
* endpoints returning {@link java.util.concurrent.CompletableFuture} instead of {@code Call<>} objects.
* Incompatible with {@link FeatureFlags#RetrofitListenableFutures}.
* Instructs the {@link Retrofit2ServiceGenerator} to generate service endpoints returning {@link
* java.util.concurrent.CompletableFuture} instead of {@code Call<>} objects. Incompatible with {@link
* FeatureFlags#RetrofitListenableFutures}.
*
* @deprecated please use {@link FeatureFlags#RetrofitListenableFutures}
*/
@Deprecated
RetrofitCompletableFutures,

/**
* Instructs the {@link Retrofit2ServiceGenerator} to generate service
* endpoints returning {@link com.google.common.util.concurrent.ListenableFuture} instead of {@code Call<>} objects.
* Incompatible with {@link FeatureFlags#RetrofitCompletableFutures}.
* Instructs the {@link Retrofit2ServiceGenerator} to generate service endpoints returning {@link
* com.google.common.util.concurrent.ListenableFuture} instead of {@code Call<>} objects. Incompatible with {@link
* FeatureFlags#RetrofitCompletableFutures}.
*/
RetrofitListenableFutures,

Expand All @@ -46,25 +47,20 @@ public enum FeatureFlags {
JerseyBinaryAsResponse,

/**
* Instructs the {@link JerseyServiceGenerator} to add {@link NotNull}
* annotations to all auth parameters, as well as all non-optional body params on service endpoints.
* Instructs the {@link JerseyServiceGenerator} to add {@link NotNull} annotations to all auth parameters, as well
* as all non-optional body params on service endpoints.
*/
RequireNotNullAuthAndBodyParams,

/**
* Undertow generated service interfaces are generated with an "Undertow" prefix.
*/
/** Undertow generated service interfaces are generated with an "Undertow" prefix. */
UndertowServicePrefix,

/**
* Use the conjure immutable "Bytes" class over ByteBuffer.
*/
/** Use the conjure immutable "Bytes" class over ByteBuffer. */
UseImmutableBytes,

/**
* Instructs the {@link com.palantir.conjure.java.services.UndertowServiceGenerator} to generate service
* endpoints returning {@link com.google.common.util.concurrent.ListenableFuture} to allow asynchronous
* request processing.
* Instructs the {@link com.palantir.conjure.java.services.UndertowServiceGenerator} to generate service endpoints
* returning {@link com.google.common.util.concurrent.ListenableFuture} to allow asynchronous request processing.
*/
UndertowListenableFutures,

Expand Down
Loading