mirror of
https://gitee.com/dcren/initializr.git
synced 2026-06-25 14:54:04 +08:00
Upgrade to spring javaformat 0.0.38
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,8 +78,9 @@ public class ProjectGenerationStatPublisher {
|
||||
}
|
||||
json = toJson(document);
|
||||
|
||||
RequestEntity<String> request = RequestEntity.post(this.requestUrl).contentType(MediaType.APPLICATION_JSON)
|
||||
.body(json);
|
||||
RequestEntity<String> request = RequestEntity.post(this.requestUrl)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(json);
|
||||
|
||||
this.retryTemplate.execute((context) -> {
|
||||
this.restTemplate.exchange(request, String.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -170,13 +170,20 @@ public class ProjectRequestDocument {
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", ProjectRequestDocument.class.getSimpleName() + "[", "]")
|
||||
.add("generationTimestamp=" + this.generationTimestamp).add("type='" + this.type + "'")
|
||||
.add("buildSystem='" + this.buildSystem + "'").add("groupId='" + this.groupId + "'")
|
||||
.add("artifactId='" + this.artifactId + "'").add("javaVersion='" + this.javaVersion + "'")
|
||||
.add("language='" + this.language + "'").add("packaging='" + this.packaging + "'")
|
||||
.add("packageName='" + this.packageName + "'").add("version=" + this.version)
|
||||
.add("client=" + this.client).add("dependencies=" + this.dependencies)
|
||||
.add("errorState=" + this.errorState).toString();
|
||||
.add("generationTimestamp=" + this.generationTimestamp)
|
||||
.add("type='" + this.type + "'")
|
||||
.add("buildSystem='" + this.buildSystem + "'")
|
||||
.add("groupId='" + this.groupId + "'")
|
||||
.add("artifactId='" + this.artifactId + "'")
|
||||
.add("javaVersion='" + this.javaVersion + "'")
|
||||
.add("language='" + this.language + "'")
|
||||
.add("packaging='" + this.packaging + "'")
|
||||
.add("packageName='" + this.packageName + "'")
|
||||
.add("version=" + this.version)
|
||||
.add("client=" + this.client)
|
||||
.add("dependencies=" + this.dependencies)
|
||||
.add("errorState=" + this.errorState)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,8 +218,10 @@ public class ProjectRequestDocument {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", "{", "}").add("id='" + this.id + "'").add("major='" + this.major + "'")
|
||||
.add("minor='" + this.minor + "'").toString();
|
||||
return new StringJoiner(", ", "{", "}").add("id='" + this.id + "'")
|
||||
.add("major='" + this.major + "'")
|
||||
.add("minor='" + this.minor + "'")
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -256,8 +265,10 @@ public class ProjectRequestDocument {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", "{", "}").add("id='" + this.id + "'").add("values=" + this.values)
|
||||
.add("count=" + this.count).toString();
|
||||
return new StringJoiner(", ", "{", "}").add("id='" + this.id + "'")
|
||||
.add("values=" + this.values)
|
||||
.add("count=" + this.count)
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -300,8 +311,11 @@ public class ProjectRequestDocument {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", "{", "}").add("id='" + this.id + "'").add("version='" + this.version + "'")
|
||||
.add("ip='" + this.ip + "'").add("country='" + this.country + "'").toString();
|
||||
return new StringJoiner(", ", "{", "}").add("id='" + this.id + "'")
|
||||
.add("version='" + this.version + "'")
|
||||
.add("ip='" + this.ip + "'")
|
||||
.add("country='" + this.country + "'")
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -380,9 +394,13 @@ public class ProjectRequestDocument {
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", "{", "}").add("invalid=" + this.invalid)
|
||||
.add("javaVersion=" + this.javaVersion).add("language=" + this.language)
|
||||
.add("packaging=" + this.packaging).add("type=" + this.type)
|
||||
.add("dependencies=" + this.dependencies).add("message='" + this.message + "'").toString();
|
||||
.add("javaVersion=" + this.javaVersion)
|
||||
.add("language=" + this.language)
|
||||
.add("packaging=" + this.packaging)
|
||||
.add("type=" + this.type)
|
||||
.add("dependencies=" + this.dependencies)
|
||||
.add("message='" + this.message + "'")
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -83,10 +83,12 @@ public class ProjectRequestDocumentFactory {
|
||||
// Let's not rely on the resolved dependencies here
|
||||
List<String> dependencies = new ArrayList<>(request.getDependencies());
|
||||
List<String> validDependencies = dependencies.stream()
|
||||
.filter((id) -> metadata.getDependencies().get(id) != null).collect(Collectors.toList());
|
||||
.filter((id) -> metadata.getDependencies().get(id) != null)
|
||||
.collect(Collectors.toList());
|
||||
document.setDependencies(new DependencyInformation(validDependencies));
|
||||
List<String> invalidDependencies = dependencies.stream().filter((id) -> (!validDependencies.contains(id)))
|
||||
.collect(Collectors.toList());
|
||||
List<String> invalidDependencies = dependencies.stream()
|
||||
.filter((id) -> (!validDependencies.contains(id)))
|
||||
.collect(Collectors.toList());
|
||||
if (!invalidDependencies.isEmpty()) {
|
||||
document.triggerError().triggerInvalidDependencies(invalidDependencies);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class InitializrActuatorEndpointsAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class, InitializrAutoConfiguration.class,
|
||||
RestTemplateAutoConfiguration.class, InitializrActuatorEndpointsAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class, InitializrAutoConfiguration.class,
|
||||
RestTemplateAutoConfiguration.class, InitializrActuatorEndpointsAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void autoConfigRegistersBomRangesInfoContributor() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,42 +48,45 @@ import static org.mockito.Mockito.mock;
|
||||
class InitializrStatsAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class, InitializrAutoConfiguration.class,
|
||||
RestTemplateAutoConfiguration.class, InitializrStatsAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class, InitializrAutoConfiguration.class,
|
||||
RestTemplateAutoConfiguration.class, InitializrStatsAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void autoConfigRegistersProjectGenerationStatPublisher() {
|
||||
this.contextRunner.withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200")
|
||||
.run((context) -> assertThat(context).hasSingleBean(ProjectGenerationStatPublisher.class));
|
||||
.run((context) -> assertThat(context).hasSingleBean(ProjectGenerationStatPublisher.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigRegistersRetryTemplate() {
|
||||
this.contextRunner.withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200")
|
||||
.run((context) -> assertThat(context).hasSingleBean(RetryTemplate.class));
|
||||
.run((context) -> assertThat(context).hasSingleBean(RetryTemplate.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void statsRetryTemplateConditionalOnMissingBean() {
|
||||
this.contextRunner.withUserConfiguration(CustomStatsRetryTemplateConfiguration.class)
|
||||
.withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200").run((context) -> {
|
||||
assertThat(context).hasSingleBean(RetryTemplate.class);
|
||||
RetryTemplate retryTemplate = context.getBean(RetryTemplate.class);
|
||||
ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) ReflectionTestUtils
|
||||
.getField(retryTemplate, "backOffPolicy");
|
||||
assertThat(backOffPolicy.getMultiplier()).isEqualTo(10);
|
||||
});
|
||||
.withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(RetryTemplate.class);
|
||||
RetryTemplate retryTemplate = context.getBean(RetryTemplate.class);
|
||||
ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) ReflectionTestUtils
|
||||
.getField(retryTemplate, "backOffPolicy");
|
||||
assertThat(backOffPolicy.getMultiplier()).isEqualTo(10);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void customRestTemplateBuilderIsUsed() {
|
||||
this.contextRunner.withUserConfiguration(CustomRestTemplateConfiguration.class)
|
||||
.withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200").run((context) -> {
|
||||
assertThat(context).hasSingleBean(ProjectGenerationStatPublisher.class);
|
||||
RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
|
||||
context.getBean(ProjectGenerationStatPublisher.class)).getPropertyValue("restTemplate");
|
||||
assertThat(restTemplate.getErrorHandler()).isSameAs(CustomRestTemplateConfiguration.errorHandler);
|
||||
});
|
||||
.withPropertyValues("initializr.stats.elastic.uri=http://localhost:9200")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(ProjectGenerationStatPublisher.class);
|
||||
RestTemplate restTemplate = (RestTemplate) new DirectFieldAccessor(
|
||||
context.getBean(ProjectGenerationStatPublisher.class))
|
||||
.getPropertyValue("restTemplate");
|
||||
assertThat(restTemplate.getErrorHandler()).isSameAs(CustomRestTemplateConfiguration.errorHandler);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,8 +47,9 @@ class DependencyRangesInfoContributorTests {
|
||||
@Test
|
||||
void dependencyWithNoMapping() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
|
||||
}
|
||||
@@ -57,9 +58,10 @@ class DependencyRangesInfoContributorTests {
|
||||
void dependencyWithRangeOnArtifact() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, "foo2", null, null, null, null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, "foo2", null, null, null, null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
|
||||
}
|
||||
@@ -68,11 +70,14 @@ class DependencyRangesInfoContributorTests {
|
||||
void dependencyWithRangeAndBom() {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null,
|
||||
"0.1.0.RELEASE", null, null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null,
|
||||
null));
|
||||
dependency.setBom("bom");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom", bom)
|
||||
.addDependencyGroup("foo", dependency).build();
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addBom("bom", bom)
|
||||
.addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
|
||||
}
|
||||
@@ -81,8 +86,9 @@ class DependencyRangesInfoContributorTests {
|
||||
void dependencyNoMappingSimpleRange() {
|
||||
Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
|
||||
dependency.setCompatibilityRange("[1.1.0.RELEASE, 1.5.0.RELEASE)");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("foo", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
assertThat(info.getDetails()).containsKeys("dependency-ranges");
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -96,12 +102,14 @@ class DependencyRangesInfoContributorTests {
|
||||
@Test
|
||||
void dependencyWithMappingAndOpenRange() {
|
||||
Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE");
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null,
|
||||
"0.1.0.RELEASE", null, null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE", null, null, null));
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null,
|
||||
null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE", null, null, null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", dependency).build();
|
||||
.addDependencyGroup("test", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
assertDependencyId(info, "foo");
|
||||
Map<String, Object> foo = getDependencyRangeInfo(info, "foo");
|
||||
@@ -112,12 +120,15 @@ class DependencyRangesInfoContributorTests {
|
||||
@Test
|
||||
void dependencyWithMappingAndNoOpenRange() {
|
||||
Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE");
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null,
|
||||
"0.1.0.RELEASE", null, null, null));
|
||||
dependency.getMappings().add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null,
|
||||
"0.2.0.RELEASE", null, null, null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE", null, null,
|
||||
null));
|
||||
dependency.getMappings()
|
||||
.add(Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null, null,
|
||||
null));
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", dependency).build();
|
||||
.addDependencyGroup("test", dependency)
|
||||
.build();
|
||||
Info info = getInfo(metadata);
|
||||
assertDependencyId(info, "foo");
|
||||
Map<String, Object> foo = getDependencyRangeInfo(info, "foo");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,7 +60,7 @@ class MainControllerStatsIntegrationTests extends AbstractFullStackInitializrInt
|
||||
this.statsMockController.stats.clear();
|
||||
// Make sure our mock is going to be invoked with the stats
|
||||
this.projectGenerationStatPublisher
|
||||
.updateRequestUrl(URI.create("http://localhost:" + this.port + "/elastic/test/my-entity"));
|
||||
.updateRequestUrl(URI.create("http://localhost:" + this.port + "/elastic/test/my-entity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +105,8 @@ class MainControllerStatsIntegrationTests extends AbstractFullStackInitializrInt
|
||||
@Test
|
||||
void requestIpIsSetWhenHeaderIsPresent() throws Exception {
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip")))
|
||||
.header("X-FORWARDED-FOR", "10.0.0.123").build();
|
||||
.header("X-FORWARDED-FOR", "10.0.0.123")
|
||||
.build();
|
||||
getRestTemplate().exchange(request, String.class);
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
@@ -117,34 +118,36 @@ class MainControllerStatsIntegrationTests extends AbstractFullStackInitializrInt
|
||||
@Test
|
||||
void requestIpv4IsNotSetWhenHeaderHasGarbage() throws Exception {
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip")))
|
||||
.header("x-forwarded-for", "foo-bar").build();
|
||||
.header("x-forwarded-for", "foo-bar")
|
||||
.build();
|
||||
getRestTemplate().exchange(request, String.class);
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
assertThat(json.has("requestIpv4")).as("requestIpv4 property should not be set if value is not a valid IPv4")
|
||||
.isFalse();
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestCountryIsNotSetWhenHeaderIsSetToXX() throws Exception {
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip"))).header("cf-ipcountry", "XX")
|
||||
.build();
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip")))
|
||||
.header("cf-ipcountry", "XX")
|
||||
.build();
|
||||
getRestTemplate().exchange(request, String.class);
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
assertThat(json.has("requestCountry")).as("requestCountry property should not be set if value is set to xx")
|
||||
.isFalse();
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidProjectSillHasStats() {
|
||||
assertThatExceptionOfType(HttpClientErrorException.class)
|
||||
.isThrownBy(() -> downloadArchive("/starter.zip?type=invalid-type"))
|
||||
.satisfies((ex) -> assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST));
|
||||
.isThrownBy(() -> downloadArchive("/starter.zip?type=invalid-type"))
|
||||
.satisfies((ex) -> assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST));
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
@@ -162,7 +165,7 @@ class MainControllerStatsIntegrationTests extends AbstractFullStackInitializrInt
|
||||
@Test
|
||||
void errorPublishingStatsDoesNotBubbleUp() {
|
||||
this.projectGenerationStatPublisher
|
||||
.updateRequestUrl(URI.create("http://localhost:" + this.port + "/elastic-error"));
|
||||
.updateRequestUrl(URI.create("http://localhost:" + this.port + "/elastic-error"));
|
||||
downloadArchive("/starter.zip");
|
||||
assertThat(this.statsMockController.stats).as("No stat should be available").isEmpty();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,9 +63,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
class ProjectGenerationStatPublisherTests {
|
||||
|
||||
private final InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("core", "security", "validation", "aop")
|
||||
.addDependencyGroup("web", "web", "data-rest", "jersey").addDependencyGroup("data", "data-jpa", "jdbc")
|
||||
.addDependencyGroup("database", "h2", "mysql").build();
|
||||
.addDependencyGroup("core", "security", "validation", "aop")
|
||||
.addDependencyGroup("web", "web", "data-rest", "jersey")
|
||||
.addDependencyGroup("data", "data-jpa", "jdbc")
|
||||
.addDependencyGroup("database", "h2", "mysql")
|
||||
.build();
|
||||
|
||||
private RetryTemplate retryTemplate;
|
||||
|
||||
@@ -131,10 +133,11 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.setGroupId("com.example.foo");
|
||||
request.setArtifactId("my-project");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo(expectedUri)).andExpect(method(HttpMethod.POST))
|
||||
.andExpect(authorizationMatcher)
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
this.mockServer.expect(requestTo(expectedUri))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(authorizationMatcher)
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
}
|
||||
@@ -153,9 +156,10 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.getParameters().put("cf-ipcountry", "BE");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST)).andExpect(json("stat/request-simple.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-simple.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -172,9 +176,10 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.setLanguage("java");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST)).andExpect(json("stat/request-no-client.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-no-client.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -191,10 +196,10 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.setLanguage("java");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-type.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-type.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -211,10 +216,10 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.setLanguage("c");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-language.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-language.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -232,10 +237,10 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.setJavaVersion("1.2");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-java-version.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-java-version.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -252,10 +257,10 @@ class ProjectGenerationStatPublisherTests {
|
||||
request.setLanguage("java");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-dependencies.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andExpect(json("stat/request-invalid-dependencies.json", event.getTimestamp()))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -266,15 +271,17 @@ class ProjectGenerationStatPublisherTests {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
|
||||
.contentType(MediaType.APPLICATION_JSON));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
@@ -287,10 +294,12 @@ class ProjectGenerationStatPublisherTests {
|
||||
this.retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections.singletonMap(Exception.class, true)));
|
||||
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
|
||||
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
|
||||
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
.andExpect(method(HttpMethod.POST))
|
||||
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||
|
||||
this.statPublisher.handleEvent(event);
|
||||
this.mockServer.verify();
|
||||
|
||||
@@ -36,9 +36,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class ProjectRequestDocumentFactoryTests {
|
||||
|
||||
private final InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("core", "security", "validation", "aop")
|
||||
.addDependencyGroup("web", "web", "data-rest", "jersey").addDependencyGroup("data", "data-jpa", "jdbc")
|
||||
.addDependencyGroup("database", "h2", "mysql").build();
|
||||
.addDependencyGroup("core", "security", "validation", "aop")
|
||||
.addDependencyGroup("web", "web", "data-rest", "jersey")
|
||||
.addDependencyGroup("data", "data-jpa", "jdbc")
|
||||
.addDependencyGroup("database", "h2", "mysql")
|
||||
.build();
|
||||
|
||||
private final ProjectRequestDocumentFactory factory = new ProjectRequestDocumentFactory();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,14 +38,14 @@ public class MetricsAssert {
|
||||
|
||||
public MetricsAssert hasValue(long value, String... metrics) {
|
||||
Arrays.asList(metrics)
|
||||
.forEach((metric) -> assertThat(this.meterRegistry.get(metric).counter().count()).isEqualTo(value));
|
||||
.forEach((metric) -> assertThat(this.meterRegistry.get(metric).counter().count()).isEqualTo(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetricsAssert hasNoValue(String... metrics) {
|
||||
Arrays.asList(metrics).forEach(
|
||||
(metric) -> assertThat(Search.in(this.meterRegistry).name((n) -> n.startsWith(metric)).counter())
|
||||
.isNull());
|
||||
Arrays.asList(metrics)
|
||||
.forEach((metric) -> assertThat(Search.in(this.meterRegistry).name((n) -> n.startsWith(metric)).counter())
|
||||
.isNull());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user