Skip to content

#305 Provide SpringBootDefaultPropertiesFinder that returns the default ap… #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.springframework.sbm.boot.properties.finder;

import org.openrewrite.properties.tree.Properties;
import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties;
import org.springframework.sbm.project.resource.ProjectResourceSet;
import org.springframework.sbm.project.resource.filter.ProjectResourceFinder;

import java.util.Optional;

public class SpringBootDefaultPropertiesFinder implements ProjectResourceFinder<Optional<SpringBootApplicationProperties>> {

@Override
public Optional<SpringBootApplicationProperties> apply(ProjectResourceSet projectResourceSet) {
return projectResourceSet.stream()
.filter(r -> r.getSourceFile() instanceof Properties.File)
.map(r -> new SpringBootApplicationProperties(r.getAbsoluteProjectDir(), (Properties.File) r.getSourceFile()))
.filter(SpringBootApplicationProperties::isDefaultProperties)
.findFirst();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.springframework.sbm.boot.properties.finder;

import org.junit.jupiter.api.Test;
import org.springframework.sbm.engine.context.ProjectContext;
import org.springframework.sbm.project.resource.TestProjectContext;

import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;

public class SpringBootDefaultPropertiesFinderTest {

@Test
public void givenAProjectWithDefaultSpringBootProperties_applyFinder_expectPropertyFile(){
ProjectContext projectContext = TestProjectContext.buildProjectContext()
.addProjectResource(Path.of("src","main", "resources", "application.properties"), "foo=bar")
.build();

SpringBootDefaultPropertiesFinder springBootDefaultPropertiesFinder = new SpringBootDefaultPropertiesFinder();
assertThat(springBootDefaultPropertiesFinder.apply(projectContext.getProjectResources()).isPresent()).isTrue();
}

@Test
public void givenAProjectWithoutDefaultSpringBootProperties_applyFinder_expectPropertyFile(){
ProjectContext projectContext = TestProjectContext.buildProjectContext()
.build();

SpringBootDefaultPropertiesFinder springBootDefaultPropertiesFinder = new SpringBootDefaultPropertiesFinder();
assertThat(springBootDefaultPropertiesFinder.apply(projectContext.getProjectResources()).isEmpty()).isTrue();
}
}