|
| 1 | +/* |
| 2 | + * Copyright 2012 - present the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.spring.initializr.web.mapper; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 20 | +import com.fasterxml.jackson.databind.JsonNode; |
| 21 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 22 | +import io.spring.initializr.generator.test.InitializrMetadataTestBuilder; |
| 23 | +import io.spring.initializr.metadata.InitializrMetadata; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | + |
| 28 | +/** |
| 29 | + * Tests for {@link InitializrMetadataV23JsonMapper}. |
| 30 | + * |
| 31 | + * @author Sijun Yang |
| 32 | + */ |
| 33 | +class InitializrMetadataV23JsonMapperTests { |
| 34 | + |
| 35 | + private static final ObjectMapper objectMapper = new ObjectMapper(); |
| 36 | + |
| 37 | + private final InitializrMetadataV23JsonMapper mapper = new InitializrMetadataV23JsonMapper(); |
| 38 | + |
| 39 | + @Test |
| 40 | + void writeConfigurationFileFormatMetadata() throws JsonProcessingException { |
| 41 | + InitializrMetadata metadata = new InitializrMetadataTestBuilder() |
| 42 | + .addConfigurationFileFormats("properties", true) |
| 43 | + .addConfigurationFileFormats("yaml", false) |
| 44 | + .build(); |
| 45 | + String json = this.mapper.write(metadata, null); |
| 46 | + JsonNode result = objectMapper.readTree(json); |
| 47 | + |
| 48 | + assertThat(result.has("configurationFileFormat")).isTrue(); |
| 49 | + JsonNode formatsNode = result.get("configurationFileFormat"); |
| 50 | + assertThat(formatsNode.get("type").asText()).isEqualTo("single-select"); |
| 51 | + assertThat(formatsNode.get("default").asText()).isEqualTo("properties"); |
| 52 | + assertThat(formatsNode.get("values")).hasSize(2); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void writeTemplatedUriWithConfigurationFileFormatParameter() throws JsonProcessingException { |
| 57 | + InitializrMetadata metadata = new InitializrMetadataTestBuilder() |
| 58 | + .addType("id", true, "action", "build", "dialect", "format") |
| 59 | + .build(); |
| 60 | + String json = this.mapper.write(metadata, null); |
| 61 | + JsonNode result = objectMapper.readTree(json); |
| 62 | + |
| 63 | + assertThat(result.at("/_links/id/href").asText()) |
| 64 | + .isEqualTo("/action?type=id{&dependencies,packaging,javaVersion," |
| 65 | + + "language,bootVersion,groupId,artifactId,version,name,description,packageName,configurationFileFormat}"); |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments