Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Revert Commit which introducer spring-boot dependency
Browse files Browse the repository at this point in the history
This reverts commit f510110.
  • Loading branch information
rhuss committed Jul 30, 2018
1 parent 662d182 commit 2e10a9e
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 444 deletions.
7 changes: 0 additions & 7 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@
<artifactId>json-path-assert</artifactId>
</dependency>

<!-- Spring Boot Profiles handling -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${version.spring-boot}</version>
</dependency>

</dependencies>

<build>
Expand Down
365 changes: 158 additions & 207 deletions core/src/main/java/io/fabric8/maven/core/util/SpringBootUtil.java

Large diffs are not rendered by default.

220 changes: 41 additions & 179 deletions core/src/test/java/io/fabric8/maven/core/util/SpringBootUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,27 @@
*/
package io.fabric8.maven.core.util;

import java.util.*;

import io.fabric8.utils.PropertiesHelper;
import org.apache.maven.model.Build;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.junit.Test;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Collections;
import java.util.Properties;
import java.util.UUID;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;

/**
* Checking the behaviour of utility methods.
*/
public class SpringBootUtilTest {

@Test
public void testYamlToPropertiesParsing() throws Exception {

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application.yml");

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.yml"));

Properties props = SpringBootUtil.getApplicationProperties(project, Collections.<String>emptyList());
@Test
public void testYamlToPropertiesParsing() {

Properties props = SpringBootUtil.getPropertiesFromYamlResource(
SpringBootUtilTest.class.getResource("/util/test-application.yml"), Collections.<String>emptyList());
assertNotEquals(0, props.size());

assertEquals(new Integer(8081), PropertiesHelper.getInteger(props, "management.port"));
Expand All @@ -71,162 +48,55 @@ public void testYamlToPropertiesParsing() throws Exception {
}

@Test
public void testYamlToPropertiesMerge() throws Exception {

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application-merge-multi.yml");
public void testYamlToPropertiesParsingWithActiveProfiles() {

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.yml"), "UTF-8", null, true);

Properties props = SpringBootUtil.getApplicationProperties(project, Collections.<String>emptyList());
List<String> activeProfiles = new ArrayList<String>() {{
add("dev");
add("qa");
}};

Properties props = SpringBootUtil.getPropertiesFromYamlResource(
SpringBootUtilTest.class.getResource("/util/test-application-multi.yml"), activeProfiles);
assertNotEquals(0, props.size());

assertEquals(new Integer(9090), PropertiesHelper.getInteger(props, "server.port"));
assertEquals("Hello", props.getProperty("my.name"));
assertEquals("Foo", props.getProperty("their.name"));
}

@Test
public void testWithDifferentConfigName() throws Exception {

System.setProperty("spring.config.name", "foo");

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application-named.yml");

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"foo.yml"), "UTF-8", null, true);

Properties props = SpringBootUtil.getApplicationProperties(project, Collections.<String>emptyList());

assertNotEquals(0, props.size());

assertEquals(new Integer(9090), PropertiesHelper.getInteger(props, "server.port"));
assertEquals("Foo", props.getProperty("their.name"));

System.getProperties().remove("spring.config.name");
assertEquals("Hola!", props.getProperty("their.name"));
}

@Test
public void testPropertiesInclude() throws Exception {

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application-include.yml");
public void testYamlToPropertiesParsingWithActiveProfiles2() {

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.yml"), "UTF-8", null, true);

SpringApplication sbBuilder = new SpringApplicationBuilder(AnnotationConfigApplicationContext.class)
.web(false)
.headless(true)
.bannerMode(Banner.Mode.OFF)
.build();

ConfigurableApplicationContext ctx = sbBuilder.run();

Properties props = SpringBootUtil.getApplicationProperties(project,Collections.<String>emptyList());
List<String> activeProfiles = new ArrayList<String>() {{
add("qa");
add("dev");
}};

Properties props = SpringBootUtil.getPropertiesFromYamlResource(
SpringBootUtilTest.class.getResource("/util/test-application-multi.yml"), activeProfiles);
assertNotEquals(0, props.size());

assertEquals(new Integer(2020), PropertiesHelper.getInteger(props, "my.port"));
assertEquals("bar", props.getProperty("my.name"));
assertEquals("foo", props.getProperty("name"));
}


@Test
public void testProfilePropertiesForDev() throws Exception {

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application-multi.yml");

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.yml"), "UTF-8", null, true);

Properties props = SpringBootUtil.getApplicationProperties(project,"dev");

assertEquals(new Integer(8080), PropertiesHelper.getInteger(props, "server.port"));
assertEquals("Hello", props.getProperty("my.name"));
assertEquals("Hola!", props.getProperty("their.name"));
}

@Test
public void testProfilePropertiesForQa() throws Exception {

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);
public void testNonExistentYamlToPropertiesParsing() {

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application-multi.yml");
Properties props = SpringBootUtil.getPropertiesFromYamlResource(
SpringBootUtilTest.class.getResource("/this-file-does-not-exist")
, Collections.<String>emptyList());
assertNotNull(props);
assertEquals(0, props.size());

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.yml"), "UTF-8", null, true);

Properties props = SpringBootUtil.getApplicationProperties(project,"qa");

assertNotEquals(0, props.size());

assertEquals(new Integer(9090), PropertiesHelper.getInteger(props, "server.port"));
assertEquals("Hola!", props.getProperty("their.name"));
}

// // @Test TODO SK Remove this after Roland Review - this will not happen at all
// public void testNonExistentYamlToPropertiesParsing() throws Exception {
//
// Properties props = SpringBootUtil.getPropertiesFromYamlResource(
// SpringBootUtilTest.class.getResource("/this-file-does-not-exist")
// , null);
//
// MavenProject project = new MavenProject();
// Build build = new Build();
//
// setMavenProject(project, build);
//
// URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/this-file-does-not-exist");
//
// FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
// "application.yml"), "UTF-8", null, true);
//
// Properties props = SpringBootUtil.getApplicationProperties(project,"qa");
// assertNotNull(props);
// assertEquals(0, props.size());
//
// }

@Test
public void testPropertiesParsing() throws Exception {

MavenProject project = new MavenProject();
Build build = new Build();

setMavenProject(project, build);

URL testAppPropertyResource = SpringBootUtilTest.class.getResource("/util/test-application.properties");

FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.properties"), "UTF-8", null, true);

Properties props = SpringBootUtil.getApplicationProperties(project,Collections.<String>emptyList());

public void testPropertiesParsing() {

Properties props = SpringBootUtil.getPropertiesResource(
SpringBootUtilTest.class.getResource("/util/test-application.properties"));
assertNotEquals(0, props.size());

assertEquals(new Integer(8081), PropertiesHelper.getInteger(props, "management.port"));
Expand All @@ -236,21 +106,13 @@ public void testPropertiesParsing() throws Exception {

}

// @Test TODO SK Remove this after Roland Review
// public void testNonExistentPropertiesParsing() throws IOException {
//
// Properties props = SpringBootUtil.getPropertiesResource(SpringBootUtilTest.class.getResource(
// "/this-file-does-not-exist"), null);
// assertNotNull(props);
// assertEquals(0, props.size());
// }
@Test
public void testNonExistentPropertiesParsing() {

Properties props = SpringBootUtil.getPropertiesResource(SpringBootUtilTest.class.getResource("/this-file-does-not-exist"));
assertNotNull(props);
assertEquals(0, props.size());

public void setMavenProject(final MavenProject project, final Build build) throws IOException {
//Set Build Dir
final String outputTempDir = Files.createTempDirectory(UUID.randomUUID().toString()).toFile().getAbsolutePath();
new File(outputTempDir).mkdirs();
build.setOutputDirectory(outputTempDir);
project.setBuild(build);
}

}
14 changes: 0 additions & 14 deletions core/src/test/resources/util/test-application-include.yml

This file was deleted.

9 changes: 0 additions & 9 deletions core/src/test/resources/util/test-application-merge-multi.yml

This file was deleted.

4 changes: 4 additions & 0 deletions core/src/test/resources/util/test-application-multi.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
spring:
profiles:
active: dev,qa

---

spring:
Expand Down
4 changes: 0 additions & 4 deletions core/src/test/resources/util/test-application-named.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public boolean hasAllClasses(MavenProject project, String ... classNames) {
private void withProjectProperties(final Properties properties) {
new MockUp<SpringBootUtil>() {
@Mock
public Properties getSpringBootApplicationProperties(MavenProject project) {
public Properties getApplicationProperties(MavenProject project, String activeProfiles) {
return properties;
}
};
Expand Down
Loading

0 comments on commit 2e10a9e

Please sign in to comment.