Turn off auto-formatting where it reduces readability
This commit is contained in:
@@ -10,8 +10,12 @@ public enum ProjectStatus {
|
||||
|
||||
@JsonCreator
|
||||
public static ProjectStatus fromName(String name) {
|
||||
return Arrays.stream(ProjectStatus.values()).filter(type -> type.name().equals(name)).findFirst()
|
||||
// @formatter:off
|
||||
return Arrays.stream(ProjectStatus.values())
|
||||
.filter(type -> type.name().equals(name))
|
||||
.findFirst()
|
||||
.orElse(ProjectStatus.ACTIVE);
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,12 @@ public enum ReleaseStatus {
|
||||
|
||||
@JsonCreator
|
||||
public static ReleaseStatus fromName(String name) {
|
||||
return Arrays.stream(ReleaseStatus.values()).filter(type -> type.name().equals(name)).findFirst()
|
||||
// @formatter:off
|
||||
return Arrays.stream(ReleaseStatus.values())
|
||||
.filter(type -> type.name().equals(name))
|
||||
.findFirst()
|
||||
.orElse(ReleaseStatus.GENERAL_AVAILABILITY);
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@ package io.spring.sample.graphql.project;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
@@ -13,27 +10,35 @@ import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.client.Hop;
|
||||
import org.springframework.hateoas.client.Traverson;
|
||||
import org.springframework.hateoas.server.core.TypeReferences;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Component
|
||||
public class SpringProjectsClient {
|
||||
|
||||
private static final TypeReferences.CollectionModelType<Release> releaseCollection = new TypeReferences.CollectionModelType<Release>() {
|
||||
};
|
||||
// @formatter:off
|
||||
|
||||
private static final TypeReferences.CollectionModelType<Release> releaseCollection =
|
||||
new TypeReferences.CollectionModelType<Release>() {};
|
||||
|
||||
// @formatter:on
|
||||
|
||||
private final Traverson traverson;
|
||||
|
||||
public SpringProjectsClient(RestTemplateBuilder builder) {
|
||||
RestTemplate restTemplate = builder
|
||||
.messageConverters(Traverson.getDefaultMessageConverters(MediaTypes.HAL_JSON)).build();
|
||||
List<HttpMessageConverter<?>> converters = Traverson.getDefaultMessageConverters(MediaTypes.HAL_JSON);
|
||||
RestTemplate restTemplate = builder.messageConverters(converters).build();
|
||||
this.traverson = new Traverson(URI.create("https://spring.io/api/"), MediaTypes.HAL_JSON);
|
||||
this.traverson.setRestOperations(restTemplate);
|
||||
}
|
||||
|
||||
public Project fetchProject(String projectSlug) {
|
||||
return this.traverson.follow("projects").follow(Hop.rel("project").withParameter("id", projectSlug))
|
||||
// @formatter:off
|
||||
return this.traverson.follow("projects")
|
||||
.follow(Hop.rel("project").withParameter("id", projectSlug))
|
||||
.toObject(Project.class);
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
public List<Release> fetchProjectReleases(String projectSlug) {
|
||||
|
||||
@@ -18,12 +18,12 @@ public class ArtifactRepositoriesInitializer implements ApplicationRunner {
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
// @formatter:off
|
||||
List<ArtifactRepository> repositoryList = Arrays.asList(
|
||||
new ArtifactRepository("spring-releases", "Spring Releases", "https://repo.spring.io/libs-releases"),
|
||||
new ArtifactRepository("spring-milestones", "Spring Milestones",
|
||||
"https://repo.spring.io/libs-milestones"),
|
||||
new ArtifactRepository("spring-snapshots", "Spring Snapshots",
|
||||
"https://repo.spring.io/libs-snapshots"));
|
||||
new ArtifactRepository("spring-milestones", "Spring Milestones", "https://repo.spring.io/libs-milestones"),
|
||||
new ArtifactRepository("spring-snapshots", "Spring Snapshots", "https://repo.spring.io/libs-snapshots"));
|
||||
// @formatter:on
|
||||
repositories.saveAll(repositoryList);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
// @formatter:off
|
||||
|
||||
/**
|
||||
* GraphQL requests via {@link GraphQlTester} connecting to {@link MockMvc}.
|
||||
*/
|
||||
@@ -39,28 +41,50 @@ public class MockMvcGraphQlTests {
|
||||
|
||||
@Test
|
||||
void jsonPath() {
|
||||
String query = "{" + " project(slug:\"spring-framework\") {" + " releases {" + " version" + " }"
|
||||
+ " }" + "}";
|
||||
String query = "{" +
|
||||
" project(slug:\"spring-framework\") {" +
|
||||
" releases {" +
|
||||
" version" +
|
||||
" }"+
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
this.graphQlTester.query(query).execute().path("project.releases[*].version").entityList(String.class)
|
||||
this.graphQlTester.query(query)
|
||||
.execute()
|
||||
.path("project.releases[*].version")
|
||||
.entityList(String.class)
|
||||
.hasSizeGreaterThan(1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonContent() {
|
||||
String query = "{" + " project(slug:\"spring-framework\") {" + " repositoryUrl" + " }" + "}";
|
||||
String query = "{" +
|
||||
" project(slug:\"spring-framework\") {" +
|
||||
" repositoryUrl" +
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
this.graphQlTester.query(query).execute().path("project")
|
||||
this.graphQlTester.query(query)
|
||||
.execute()
|
||||
.path("project")
|
||||
.matchesJson("{\"repositoryUrl\":\"http://github.com/spring-projects/spring-framework\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void decodedResponse() {
|
||||
String query = "{" + " project(slug:\"spring-framework\") {" + " releases {" + " version" + " }"
|
||||
+ " }" + "}";
|
||||
String query = "{" +
|
||||
" project(slug:\"spring-framework\") {" +
|
||||
" releases {" +
|
||||
" version" +
|
||||
" }" +
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
this.graphQlTester.query(query).execute().path("project").entity(Project.class)
|
||||
this.graphQlTester.query(query)
|
||||
.execute()
|
||||
.path("project")
|
||||
.entity(Project.class)
|
||||
.satisfies(project -> assertThat(project.getReleases()).hasSizeGreaterThan(1));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user