protected List<DefaultMetadataElement> fetchBootVersions() { String url = this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(); if (StringUtils.hasText(url)) { try { log.info("Fetching boot metadata from {}", url); return new SpringBootMetadataReader(this.objectMapper, this.restTemplate, url).getBootVersions(); } catch (Exception ex) { log.warn("Failed to fetch spring boot metadata", ex); } } return null; }
@Test void mergeConfiguration() { InitializrProperties config = load( new ClassPathResource("application-test-default.yml")); InitializrProperties customDefaultsConfig = load( new ClassPathResource("application-test-custom-env.yml")); InitializrMetadata metadata = InitializrMetadataBuilder .fromInitializrProperties(config) .withInitializrProperties(customDefaultsConfig, true).build(); InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv(); InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv(); assertThat(actualEnv.getArtifactRepository()) .isEqualTo("https://repo.spring.io/lib-release/"); assertThat(actualEnv.getSpringBootMetadataUrl()) .isEqualTo(defaultEnv.getSpringBootMetadataUrl()); assertThat(actualEnv.getFallbackApplicationName()).isEqualTo("FooBarApplication"); assertThat(actualEnv.isForceSsl()).isEqualTo(false); assertThat(actualEnv.getKotlin().getDefaultVersion()) .isEqualTo("1.0.0-beta-2423"); }
@Test void mergeConfigurationDisabledByDefault() { InitializrProperties config = load( new ClassPathResource("application-test-default.yml")); InitializrProperties customDefaultsConfig = load( new ClassPathResource("application-test-custom-env.yml")); InitializrMetadata metadata = InitializrMetadataBuilder .fromInitializrProperties(config) .withInitializrProperties(customDefaultsConfig).build(); InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv(); InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv(); assertThat(actualEnv.getArtifactRepository()) .isEqualTo(defaultEnv.getArtifactRepository()); assertThat(actualEnv.getSpringBootMetadataUrl()) .isEqualTo(defaultEnv.getSpringBootMetadataUrl()); assertThat(actualEnv.getFallbackApplicationName()) .isEqualTo(defaultEnv.getFallbackApplicationName()); assertThat(actualEnv.isForceSsl()).isEqualTo(defaultEnv.isForceSsl()); }
@Test void readAvailableVersions() throws IOException { this.server.expect(requestTo("https://spring.io/project_metadata/spring-boot")) .andRespond(withSuccess( new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON)); List<DefaultMetadataElement> versions = new SpringBootMetadataReader( this.objectMapper, this.restTemplate, this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()) .getBootVersions(); assertThat(versions).as("spring boot versions should not be null").isNotNull(); AtomicBoolean defaultFound = new AtomicBoolean(false); versions.forEach((it) -> { assertThat(it.getId()).as("Id must be set").isNotNull(); assertThat(it.getName()).as("Name must be set").isNotNull(); if (it.isDefault()) { if (defaultFound.get()) { fail("One default version was already found " + it.getId()); } defaultFound.set(true); } }); this.server.verify(); }
@Test void bootVersionsAreReplaced() { InitializrMetadata metadata = new InitializrMetadataTestBuilder() .addBootVersion("0.0.9.RELEASE", true) .addBootVersion("0.0.8.RELEASE", false).build(); assertThat(metadata.getBootVersions().getDefault().getId()) .isEqualTo("0.0.9.RELEASE"); DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider( metadata, objectMapper, this.restTemplate); expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(), "metadata/sagan/spring-boot.json"); InitializrMetadata updatedMetadata = provider.get(); assertThat(updatedMetadata.getBootVersions()).isNotNull(); List<DefaultMetadataElement> updatedBootVersions = updatedMetadata .getBootVersions().getContent(); assertThat(updatedBootVersions).hasSize(4); assertBootVersion(updatedBootVersions.get(0), "1.4.1 (SNAPSHOT)", false); assertBootVersion(updatedBootVersions.get(1), "1.4.0", true); assertBootVersion(updatedBootVersions.get(2), "1.3.8 (SNAPSHOT)", false); assertBootVersion(updatedBootVersions.get(3), "1.3.7", false); }
@Test void defaultBootVersionIsAlwaysSet() { InitializrMetadata metadata = new InitializrMetadataTestBuilder() .addBootVersion("0.0.9.RELEASE", true) .addBootVersion("0.0.8.RELEASE", false).build(); assertThat(metadata.getBootVersions().getDefault().getId()) .isEqualTo("0.0.9.RELEASE"); DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider( metadata, objectMapper, this.restTemplate); expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(), "metadata/sagan/spring-boot-no-default.json"); InitializrMetadata updatedMetadata = provider.get(); assertThat(updatedMetadata.getBootVersions()).isNotNull(); List<DefaultMetadataElement> updatedBootVersions = updatedMetadata .getBootVersions().getContent(); assertThat(updatedBootVersions).hasSize(4); assertBootVersion(updatedBootVersions.get(0), "1.3.1 (SNAPSHOT)", true); assertBootVersion(updatedBootVersions.get(1), "1.3.0", false); assertBootVersion(updatedBootVersions.get(2), "1.2.6 (SNAPSHOT)", false); assertBootVersion(updatedBootVersions.get(3), "1.2.5", false); }