GH-187 - Do not include non-exposed Spring beans that implement interfaces in Application Module Canvas by default.

We now properly check whether one of a Spring bean's implemented interfaces is exposed by the module before including it in the default rendering of the Application Module Canvas.
This commit is contained in:
Oliver Drotbohm
2023-04-30 14:18:36 +02:00
parent 0b6dccf334
commit 4656f82089
5 changed files with 106 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2023 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
*
* https://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 example.springbean.internal;
import org.springframework.stereotype.Component;
/**
* @author Oliver Drotbohm
*/
@Component
public class ServiceImplementation implements ServiceInterface {}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2023 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
*
* https://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 example.springbean.internal;
/**
* @author Oliver Drotbohm
*/
public interface ServiceInterface {}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2023 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
*
* https://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 org.springframework.modulith.core;
import static org.assertj.core.api.Assertions.*;
import example.springbean.internal.ServiceImplementation;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link SpringBean}.
*
* @author Oliver Drotbohm
*/
class SpringBeanUnitTests {
@Test // GH-187
void doesNotConsiderInternalBeanImplementingInterfaceApiBean() {
var module = TestUtils.getApplicationModule("example.springbean");
assertThat(module.getSpringBeans())
.filteredOn(SpringBean::isApiBean)
.extracting(SpringBean::getFullyQualifiedTypeName)
.doesNotContain(ServiceImplementation.class.getName());
}
}

View File

@@ -74,4 +74,20 @@ class TestUtils {
public static JavaPackage getPackage(Class<?> packageType) {
return JavaPackage.of(TestUtils.getClasses(packageType), packageType.getPackageName());
}
public static ApplicationModule getApplicationModule(String packageName) {
return new ApplicationModule(getPackage(packageName), false);
}
private static JavaPackage getPackage(String name) {
return JavaPackage.of(getClasses(name), name);
}
private static Classes getClasses(String packageName) {
Assert.hasText(packageName, "Package name must not be null or empty!");
return Classes.of(new ClassFileImporter()
.importPackages(packageName));
}
}