GH-587 - Additional modulith packages are now considered for application classes.

This commit is contained in:
Oliver Drotbohm
2024-05-20 17:23:15 +02:00
parent a7145c3b86
commit 04c1203f65
11 changed files with 178 additions and 4 deletions

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2024 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 different.moduleB;
/**
* @author Oliver Drotbohm
*/
public class ModuleBType {}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2024 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;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.modulith.Modulithic;
/**
* @author Oliver Drotbohm
*/
@Modulithic(additionalPackages = "different")
@SpringBootApplication
public class SampleApplication {}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2024 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.moduleA;
/**
* @author Oliver Drotbohm
*/
public class ModuleAType {}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2024 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.runtime;
import static org.assertj.core.api.Assertions.*;
import different.moduleB.ModuleBType;
import example.SampleApplication;
import example.moduleA.ModuleAType;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.modulith.core.ApplicationModules;
import org.springframework.modulith.runtime.autoconfigure.TestSpringBootApplicationRuntime;
import org.springframework.modulith.test.TestApplicationModules;
/**
* Integration tests for {@link ApplicationModulesRuntime}.
*
* @author Oliver Drotbohm
*/
public class ApplicationModulesRuntimeIntegrationTests {
ApplicationModules modules = TestApplicationModules.of(SampleApplication.class);
@Test // GH-587
void detectsTypeInAdditionalPackageAsApplicationType() {
var context = SpringApplication.run(SampleApplication.class);
var applicationRuntime = new TestSpringBootApplicationRuntime(context);
var runtime = new ApplicationModulesRuntime(() -> modules, applicationRuntime);
Stream.of(ModuleAType.class, ModuleBType.class)
.forEach(it -> assertThat(runtime.isApplicationClass(it)).isTrue());
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2024 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.runtime.autoconfigure;
import org.springframework.context.ApplicationContext;
/**
* @author Oliver Drotbohm
*/
public class TestSpringBootApplicationRuntime extends SpringBootApplicationRuntime {
public TestSpringBootApplicationRuntime(ApplicationContext context) {
super(context);
}
}