mirror of
https://gitee.com/dcren/initializr.git
synced 2026-09-28 07:17:40 +08:00
Ensure configuration can be serialized
Closes gh-506
This commit is contained in:
@@ -425,6 +425,7 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
*/
|
||||
private String version;
|
||||
|
||||
@JsonIgnore
|
||||
private VersionRange range;
|
||||
|
||||
public String getGroupId() {
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -55,6 +57,7 @@ public class VersionProperty implements Serializable, Comparable<VersionProperty
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String toStandardFormat() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ initializr:
|
||||
my-api-bom:
|
||||
groupId: org.acme
|
||||
artifactId: my-api-bom
|
||||
versionProperty: my-api.version
|
||||
additionalBoms: ['my-api-dependencies-bom']
|
||||
mappings:
|
||||
- versionRange: "[1.0.0.RELEASE,1.1.6.RELEASE)"
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2012-2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.InitializrMetadataBuilder;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic smoke tests for {@link InitializrService}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class InitializrServiceSmokeTests {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private InitializrMetadataProvider metadataProvider;
|
||||
|
||||
@Test
|
||||
public void metadataCanBeSerialized() throws URISyntaxException {
|
||||
RequestEntity<Void> request = RequestEntity.get(new URI("/"))
|
||||
.accept(MediaType.parseMediaType("application/vnd.initializr.v2.1+json"))
|
||||
.build();
|
||||
ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
new JSONObject(response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationCanBeSerialized() throws URISyntaxException {
|
||||
RequestEntity<Void> request = RequestEntity.get(new URI("/metadata/config"))
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
ResponseEntity<String> response = this.restTemplate.exchange(request, String.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
InitializrMetadata actual = InitializrMetadataBuilder.create()
|
||||
.withInitializrMetadata(new ByteArrayResource(
|
||||
response.getBody().getBytes()))
|
||||
.build();
|
||||
assertThat(actual).isNotNull();
|
||||
InitializrMetadata expected = metadataProvider.get();
|
||||
assertThat(actual.getDependencies().getAll().size())
|
||||
.isEqualTo(expected.getDependencies().getAll().size());
|
||||
assertThat(actual.getConfiguration().getEnv().getBoms().size())
|
||||
.isEqualTo(expected.getConfiguration().getEnv().getBoms().size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -86,6 +86,7 @@
|
||||
"my-api-bom": {
|
||||
"groupId": "org.acme",
|
||||
"artifactId": "my-api-bom",
|
||||
"versionProperty": "my-api.version",
|
||||
"additionalBoms": [
|
||||
"my-api-dependencies-bom"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user