diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java index 23eac51c0e..380d057cf3 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java @@ -59,10 +59,15 @@ public void validate() { this.env.validate(); } - // Add customFields + /** + * The customFields feature in Spring Initializr enables additional, adaptable metadata beyond the standard fields. + * This allows organizations to set environment-specific values like default configurations, dependencies, + * version control, or deployment options—aligning generated projects directly with their standards. + * By using customFields, organizations can add new metadata flexibly without altering core configurations, + * making Initializr more adaptable and valuable for various use cases. + */ private Map customFields = Collections.emptyMap(); - // Getter and Setter public Map getCustomFields() { return this.customFields; } diff --git a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectMetadataControllerCustomFieldsIntegrationTests.java b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectMetadataControllerCustomFieldsIntegrationTests.java index 56b64a0589..311ba7cc73 100644 --- a/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectMetadataControllerCustomFieldsIntegrationTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/controller/ProjectMetadataControllerCustomFieldsIntegrationTests.java @@ -16,9 +16,6 @@ package io.spring.initializr.web.controller; -import io.spring.initializr.metadata.InitializrMetadata; -import io.spring.initializr.metadata.InitializrMetadataBuilder; -import io.spring.initializr.metadata.InitializrMetadataProvider; import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests; import org.json.JSONException; import org.json.JSONObject; @@ -26,53 +23,18 @@ import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.UrlResource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; -import org.springframework.web.client.HttpClientErrorException; - -import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link ProjectMetadataController} on a real http server. * - * @author Stephane Nicoll + * @author Joar Varpe */ @ActiveProfiles("test-custom-fields") class ProjectMetadataControllerCustomFieldsIntegrationTests extends AbstractFullStackInitializrIntegrationTests { - @Autowired - private InitializrMetadataProvider metadataProvider; - - @Test - void initializeRemoteConfig() throws Exception { - InitializrMetadata localMetadata = this.metadataProvider.get(); - InitializrMetadata metadata = InitializrMetadataBuilder.create() - .withInitializrMetadata(new UrlResource(createUrl("/metadata/config"))) - .build(); - // Basic assertions - assertThat(metadata.getDependencies().getContent()).hasSameSizeAs(localMetadata.getDependencies().getContent()); - assertThat(metadata.getTypes().getContent()).hasSameSizeAs(localMetadata.getTypes().getContent()); - assertThat(metadata.getBootVersions().getContent()).hasSameSizeAs(localMetadata.getBootVersions().getContent()); - assertThat(metadata.getPackagings().getContent()).hasSameSizeAs(localMetadata.getPackagings().getContent()); - assertThat(metadata.getJavaVersions().getContent()).hasSameSizeAs(localMetadata.getJavaVersions().getContent()); - assertThat(metadata.getLanguages().getContent()).hasSameSizeAs(localMetadata.getLanguages().getContent()); - } - - @Test - void textPlainNotAccepted() { - try { - execute("/metadata/config", String.class, null, "text/plain"); - } - catch (HttpClientErrorException ex) { - assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE); - } - } - @Test void validateJson() throws JSONException { ResponseEntity response = execute("/metadata/config", String.class, null, "application/json"); @@ -81,47 +43,4 @@ void validateJson() throws JSONException { JSONObject expected = readJsonFrom("metadata/config/test-custom-fields.json"); JSONAssert.assertEquals(expected, json, JSONCompareMode.STRICT); } - - @Test - void metadataClientEndpoint() { - ResponseEntity response = execute("/metadata/client", String.class, null, "application/json"); - validateDefaultMetadata(response); - } - - @Test - void dependenciesNoAcceptHeaderWithNoBootVersion() throws JSONException { - validateDependenciesMetadata("*/*", DEFAULT_METADATA_MEDIA_TYPE); - } - - @Test - void dependenciesV21WithNoBootVersion() throws JSONException { - validateDependenciesMetadata("application/vnd.initializr.v2.1+json", DEFAULT_METADATA_MEDIA_TYPE); - } - - @Test - void dependenciesV22WithNoBootVersion() throws JSONException { - validateDependenciesMetadata("application/vnd.initializr.v2.2+json", CURRENT_METADATA_MEDIA_TYPE); - } - - private void validateDependenciesMetadata(String acceptHeader, MediaType expectedMediaType) throws JSONException { - ResponseEntity response = execute("/dependencies", String.class, null, acceptHeader); - assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull(); - validateContentType(response, expectedMediaType); - validateDependenciesOutput("2.4.4", response.getBody()); - } - - @Test - void filteredDependencies() throws JSONException { - ResponseEntity response = execute("/dependencies?bootVersion=2.6.1", String.class, null, - "application/json"); - assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull(); - validateContentType(response, DEFAULT_METADATA_MEDIA_TYPE); - validateDependenciesOutput("2.6.1", response.getBody()); - } - - protected void validateDependenciesOutput(String version, String actual) throws JSONException { - JSONObject expected = readJsonFrom("metadata/dependencies/test-dependencies-" + version + ".json"); - JSONAssert.assertEquals(expected, new JSONObject(actual), JSONCompareMode.STRICT); - } - }