GH-1 - Initial port of Moduliths project.
Basically the state of commit c7cf939 of https://github.com/moduliths/moduliths for further development under the Spring umbrella.
This commit is contained in:
79
moduliths-sample/jqassistant/index.adoc
Normal file
79
moduliths-sample/jqassistant/index.adoc
Normal file
@@ -0,0 +1,79 @@
|
||||
= Modulith
|
||||
|
||||
== Overview
|
||||
|
||||
include::jQA:Summary[]
|
||||
|
||||
[[default]]
|
||||
[role=group,includesConcepts="modulith:ModuleDependencies,modulith:ModuleExposesType"]
|
||||
== Reports
|
||||
|
||||
[[modulith:ModulithApplication]]
|
||||
[source,cypher,role=concept]
|
||||
.Classes annotated by `org.moduliths.Modulith` are labeled with `Modulith` and `Application`.
|
||||
----
|
||||
MATCH
|
||||
(:Artifact)-[:CONTAINS]->(modulith:Type)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(:Type{fqn:"org.moduliths.Modulith"})
|
||||
SET
|
||||
modulith:Modulith:Application
|
||||
RETURN
|
||||
modulith as Modulith
|
||||
----
|
||||
|
||||
[[modulith:Module]]
|
||||
[source,cypher,role=concept,requiresConcepts="modulith:ModulithApplication"]
|
||||
.Each package that is located within the same package as the Modulith application class is labeled with `Module`.
|
||||
----
|
||||
MATCH
|
||||
(root:Package)-[:CONTAINS]->(modulith:Modulith:Application),
|
||||
(root)-[:CONTAINS]->(module:Package)
|
||||
OPTIONAL MATCH
|
||||
(module)-[:CONTAINS]->(:Type{name:"package-info"})-[:ANNOTATED_BY]->(moduleInfo),
|
||||
(moduleInfo)-[:OF_TYPE]->(:Type{fqn:"org.moduliths.Module"}),
|
||||
(moduleInfo)-[:HAS]->(displayName:Value{name:"displayName"})
|
||||
SET
|
||||
module:Module
|
||||
SET
|
||||
module.displayName = coalesce(displayName.value, module.name)
|
||||
RETURN
|
||||
module.displayName as Module
|
||||
ORDER BY
|
||||
Module
|
||||
----
|
||||
|
||||
[[modulith:ModuleDependencies]]
|
||||
[source,cypher,role=concept,requiresConcepts="modulith:Module",reportType="plantuml-component-diagram"]
|
||||
.A dependency between two modules exists if there's a type dependency between both. The module dependency is represented by `DEPENDS_ON_MODULE` relationships having a `weight` property indicating the degree of coupling.
|
||||
----
|
||||
MATCH
|
||||
(module1:Module)-[:CONTAINS*]->(type1:Type),
|
||||
(module2:Module)-[:CONTAINS*]->(type2:Type),
|
||||
(type1)-[dependsOn:DEPENDS_ON]->(type2)
|
||||
WHERE
|
||||
module1 <> module2
|
||||
WITH
|
||||
module1, module2, count(dependsOn) as weight
|
||||
MERGE
|
||||
(module1)-[dependsOnModule:DEPENDS_ON_MODULE]->(module2)
|
||||
SET
|
||||
dependsOnModule.weight = weight
|
||||
RETURN
|
||||
module1, dependsOnModule, module2
|
||||
----
|
||||
|
||||
[[modulith:ModuleExposesType]]
|
||||
[source,cypher,role=concept,requiresConcepts="modulith:ModuleDependencies"]
|
||||
.A type of a module is exposed if it is referenced at least once by a type in another module.
|
||||
----
|
||||
MATCH
|
||||
(module:Module)
|
||||
OPTIONAL MATCH
|
||||
(dependent:Module)-[:DEPENDS_ON_MODULE]->(module),
|
||||
(dependent)-[:CONTAINS*]->(dependentType:Type),
|
||||
(module)-[:CONTAINS*]->(type:Type),
|
||||
(dependentType)-[:DEPENDS_ON]->(type)
|
||||
RETURN
|
||||
module.displayName as Module, collect(type.fqn) as ExposedTypes
|
||||
ORDER BY
|
||||
Module
|
||||
----
|
||||
97
moduliths-sample/pom.xml
Normal file
97
moduliths-sample/pom.xml
Normal file
@@ -0,0 +1,97 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.moduliths</groupId>
|
||||
<artifactId>moduliths</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<name>Moduliths - Sample</name>
|
||||
<artifactId>moduliths-sample</artifactId>
|
||||
|
||||
<properties>
|
||||
<module.name>org.moduliths.sample</module.name>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>jqa</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.buschmais.jqassistant</groupId>
|
||||
<artifactId>jqassistant-maven-plugin</artifactId>
|
||||
<version>1.8.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-cli</id>
|
||||
<goals>
|
||||
<goal>scan</goal>
|
||||
<goal>analyze</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>moduliths-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>moduliths-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jmolecules</groupId>
|
||||
<artifactId>jmolecules-events</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject;
|
||||
|
||||
import org.moduliths.Modulith;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Modulith
|
||||
public class Application {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.complex.api;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ComplexApiComponent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@org.moduliths.NamedInterface("API")
|
||||
package com.acme.myproject.complex.api;
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.complex.internal;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
class ComplextInternalComponent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2019 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 com.acme.myproject.complex.internal;
|
||||
|
||||
import org.moduliths.NamedInterface;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@NamedInterface({ "Port 1", "Port 2" })
|
||||
public class FirstTypeBasedPort {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2019 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 com.acme.myproject.complex.internal;
|
||||
|
||||
import org.moduliths.NamedInterface;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@NamedInterface({ "Port 2", "Port 3" })
|
||||
public class SecondTypeBasePort {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.complex.spi;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ComplexSpiComponent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@org.moduliths.NamedInterface("SPI")
|
||||
package com.acme.myproject.complex.spi;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.cycleA;
|
||||
|
||||
import com.acme.myproject.cycleB.CycleB;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CycleA {
|
||||
CycleB cycleB;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.cycleB;
|
||||
|
||||
import com.acme.myproject.cycleA.CycleA;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CycleB {
|
||||
CycleA cycleA;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2019 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
|
||||
*
|
||||
* http://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 com.acme.myproject.fieldinjected;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.acme.myproject.moduleA.ServiceComponentA;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Component
|
||||
public class WithFieldInjection {
|
||||
|
||||
@Autowired ServiceComponentA a;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.invalid;
|
||||
|
||||
import com.acme.myproject.moduleB.internal.InternalComponentB;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class InvalidComponent {
|
||||
|
||||
InvalidComponent(InternalComponentB invalidComponent) {}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.invalid2;
|
||||
|
||||
import com.acme.myproject.moduleA.ServiceComponentA;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class InvalidModuleDependency {
|
||||
|
||||
/**
|
||||
* The dependency is invalid as the module declaration only allows dependencies to Module B.
|
||||
*
|
||||
* @param dependency
|
||||
*/
|
||||
public InvalidModuleDependency(ServiceComponentA dependency) {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@org.moduliths.Module(allowedDependencies = "moduleB")
|
||||
package com.acme.myproject.invalid2;
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2018-2019 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleA;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ServiceComponentA {
|
||||
|
||||
private final ApplicationEventPublisher publisher;
|
||||
|
||||
public void fireEvent() {
|
||||
publisher.publishEvent(new SomeEventA("Message"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleA;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
public class SomeConfigurationA {
|
||||
|
||||
@Bean
|
||||
SomeAtBeanComponentA atBeanComponent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class SomeAtBeanComponentA {}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2018-2019 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleA;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import org.jmolecules.event.annotation.DomainEvent;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Value
|
||||
@DomainEvent
|
||||
public class SomeEventA {
|
||||
String message;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleB;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.acme.myproject.moduleA.ServiceComponentA;
|
||||
import com.acme.myproject.moduleB.internal.InternalComponentB;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ServiceComponentB {
|
||||
|
||||
private final ServiceComponentA serviceComponentA;
|
||||
private final InternalComponentB internalComponentB;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleB;
|
||||
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.acme.myproject.moduleA.SomeEventA;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
class SomeEventListenerB {
|
||||
|
||||
@EventListener
|
||||
void on(SomeEventA event) {}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleB.internal;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
public class InternalComponentB {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleB.internal;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
class SupportingComponentB {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleC;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.acme.myproject.moduleB.ServiceComponentB;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
class ServiceComponentC {
|
||||
private final ServiceComponentB serviceComponentB;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
@org.moduliths.Module(displayName = "MyModule C")
|
||||
package com.acme.myproject.moduleC;
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2020 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 com.acme.myproject.stereotypes;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class Stereotypes {
|
||||
|
||||
@Component
|
||||
static class SomeComponent {}
|
||||
|
||||
@Controller
|
||||
static class SomeController {}
|
||||
|
||||
@Service
|
||||
static class SomeService {}
|
||||
|
||||
@Repository
|
||||
static class SomeRepository {}
|
||||
|
||||
@Component
|
||||
static class SomeRepresentations {}
|
||||
|
||||
@Component
|
||||
static class SomeEventListener {
|
||||
|
||||
@EventListener
|
||||
void someEventListener(Object event) {}
|
||||
}
|
||||
|
||||
@Component
|
||||
static class SomeTxEventListener {
|
||||
|
||||
@TransactionalEventListener
|
||||
void someTxEventListener(Object event) {}
|
||||
}
|
||||
|
||||
@Component // Used for documentation purposes
|
||||
public static interface SomeAppInterface {};
|
||||
|
||||
@Component
|
||||
static class SomeAppInterfaceImplementation implements SomeAppInterface {}
|
||||
|
||||
@Value
|
||||
@ConstructorBinding
|
||||
@ConfigurationProperties("org.moduliths.sample")
|
||||
static class SomeConfigurationProperties {
|
||||
|
||||
/**
|
||||
* Some test property.
|
||||
*/
|
||||
String test;
|
||||
|
||||
public SomeConfigurationProperties(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2020 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 com.acme.myproject.stereotypes.web;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Component
|
||||
public class WebRepresentations {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.moduliths.model.Modules;
|
||||
import org.moduliths.model.Modules.Filters;
|
||||
import org.moduliths.model.Violations;
|
||||
|
||||
import com.acme.myproject.invalid.InvalidComponent;
|
||||
import com.acme.myproject.moduleB.internal.InternalComponentB;
|
||||
import com.tngtech.archunit.base.DescribedPredicate;
|
||||
import com.tngtech.archunit.core.domain.JavaClass;
|
||||
|
||||
/**
|
||||
* Test cases to verify the validity of the overall modulith rules
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Peter Gafert
|
||||
*/
|
||||
class ModulithTest {
|
||||
|
||||
static final DescribedPredicate<JavaClass> DEFAULT_EXCLUSIONS = Filters.withoutModules("cycleA", "cycleB", "invalid2",
|
||||
"fieldinjected");
|
||||
|
||||
@Test
|
||||
void verifyModules() {
|
||||
|
||||
String componentName = InternalComponentB.class.getSimpleName();
|
||||
|
||||
assertThatExceptionOfType(Violations.class) //
|
||||
.isThrownBy(() -> Modules.of(Application.class, DEFAULT_EXCLUSIONS).verify()) //
|
||||
.withMessageContaining(String.format("Module '%s' depends on non-exposed type %s within module 'moduleB'",
|
||||
"invalid", InternalComponentB.class.getName()))
|
||||
.withMessageContaining(String.format("%s declares constructor %s(%s)", InvalidComponent.class.getSimpleName(),
|
||||
InvalidComponent.class.getSimpleName(), componentName));
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyModulesWithoutInvalid() {
|
||||
Modules.of(Application.class, DEFAULT_EXCLUSIONS.or(Filters.withoutModule("invalid"))).verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectsCycleBetweenModules() {
|
||||
|
||||
assertThatExceptionOfType(Violations.class) //
|
||||
.isThrownBy(() -> Modules.of(Application.class, Filters.withoutModules("invalid", "invalid2")).verify()) //
|
||||
|
||||
// mentions modules
|
||||
.withMessageContaining("cycleA") //
|
||||
.withMessageContaining("cycleB") //
|
||||
|
||||
// mentions offending types
|
||||
.withMessageContaining("CycleA") //
|
||||
.withMessageContaining("CycleB");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.moduliths.test.ModuleTest;
|
||||
import org.moduliths.test.ModuleTest.BootstrapMode;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ModuleTest(verifyAutomatically = false)
|
||||
public @interface NonVerifyingModuleTest {
|
||||
|
||||
@AliasFor(annotation = ModuleTest.class, attribute = "mode")
|
||||
BootstrapMode value() default BootstrapMode.STANDALONE;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.complex;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.moduliths.model.NamedInterface;
|
||||
import org.moduliths.model.NamedInterfaces;
|
||||
import org.moduliths.test.ModuleTestExecution;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.acme.myproject.NonVerifyingModuleTest;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@NonVerifyingModuleTest
|
||||
class ComplexTest {
|
||||
|
||||
@Autowired ModuleTestExecution moduleTest;
|
||||
|
||||
@Test
|
||||
void exposesNamedInterfaces() {
|
||||
|
||||
NamedInterfaces interfaces = moduleTest.getModule().getNamedInterfaces();
|
||||
|
||||
assertThat(interfaces.stream().map(NamedInterface::getName)) //
|
||||
.containsExactlyInAnyOrder("API", "SPI", "Port 1", "Port 2", "Port 3");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2019 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
|
||||
*
|
||||
* http://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 com.acme.myproject.fieldinjected;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.moduliths.model.Modules;
|
||||
import org.moduliths.test.ModuleTestExecution;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import com.acme.myproject.NonVerifyingModuleTest;
|
||||
import com.acme.myproject.moduleA.ServiceComponentA;
|
||||
|
||||
/**
|
||||
* Integration tests to verify field injection is rejected.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@NonVerifyingModuleTest
|
||||
class FieldInjectedIntegrationTest {
|
||||
|
||||
@Autowired ModuleTestExecution execution;
|
||||
|
||||
@MockBean ServiceComponentA dependency;
|
||||
|
||||
@Test
|
||||
void rejectsFieldInjection() {
|
||||
|
||||
Modules modules = execution.getModules();
|
||||
|
||||
assertThat(execution.getModule().detectDependencies(modules)) //
|
||||
.hasMessageContaining("field injection") //
|
||||
.hasMessageContaining("WithFieldInjection.a"); // offending field
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleA;
|
||||
|
||||
// import static org.moduliths.test.assertj.PublishedEventAssertions.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.moduliths.test.PublishedEvents;
|
||||
import org.moduliths.test.PublishedEvents.TypedPublishedEvents;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.acme.myproject.NonVerifyingModuleTest;
|
||||
import com.acme.myproject.moduleB.ServiceComponentB;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@NonVerifyingModuleTest
|
||||
class ModuleATest {
|
||||
|
||||
@Autowired ApplicationContext context;
|
||||
@Autowired PublishedEvents events;
|
||||
|
||||
@Test
|
||||
void bootstrapsModuleAOnly() {
|
||||
|
||||
context.getBean(ServiceComponentA.class);
|
||||
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(() -> context.getBean(ServiceComponentB.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertEventsFired() {
|
||||
|
||||
context.getBean(ServiceComponentA.class).fireEvent();
|
||||
|
||||
TypedPublishedEvents<SomeEventA> matching = events.ofType(SomeEventA.class) //
|
||||
.matching(it -> it.getMessage().equals("Message"));
|
||||
|
||||
assertThat(matching).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void injectsPublishedEventsIntoMethod(PublishedEvents events) {
|
||||
assertThat(events).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleB;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.internal.creation.bytebuddy.MockAccess;
|
||||
import org.moduliths.test.ModuleTest.BootstrapMode;
|
||||
import org.moduliths.test.TestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import com.acme.myproject.NonVerifyingModuleTest;
|
||||
import com.acme.myproject.moduleA.ServiceComponentA;
|
||||
import com.acme.myproject.moduleB.internal.InternalComponentB;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class ModuleBTest {
|
||||
|
||||
@Nested
|
||||
static class WithoutMocksTest {
|
||||
|
||||
@Autowired ServiceComponentB serviceComponentB;
|
||||
|
||||
@NonVerifyingModuleTest
|
||||
static class Config {}
|
||||
|
||||
@Test
|
||||
void failsToStartBecauseServiceComponentAIsMissing() throws Exception {
|
||||
TestUtils.assertDependencyMissing(WithoutMocksTest.Config.class, ServiceComponentA.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@NonVerifyingModuleTest
|
||||
static class WithMocksTest {
|
||||
|
||||
@Autowired ApplicationContext context;
|
||||
@MockBean ServiceComponentA serviceComponentA;
|
||||
|
||||
@Test
|
||||
void bootstrapsModuleB() {
|
||||
|
||||
context.getBean(ServiceComponentB.class);
|
||||
|
||||
assertThat(context.getBean(ServiceComponentA.class)).isInstanceOf(MockAccess.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void considersNestedPackagePartOfTheModuleByDefault() {
|
||||
context.getBean(InternalComponentB.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tweaksAutoConfigurationPackageToModulePackage() {
|
||||
|
||||
assertThat(AutoConfigurationPackages.get(context)) //
|
||||
.containsExactly(getClass().getPackage().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@NonVerifyingModuleTest(BootstrapMode.DIRECT_DEPENDENCIES)
|
||||
static class WithUpstreamModuleTest {
|
||||
|
||||
@Autowired ServiceComponentA componentA;
|
||||
@Autowired ServiceComponentB componentB;
|
||||
|
||||
@Test
|
||||
void bootstrapsContext() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* http://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 com.acme.myproject.moduleC;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.moduliths.test.ModuleTest.BootstrapMode;
|
||||
import org.moduliths.test.TestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import com.acme.myproject.NonVerifyingModuleTest;
|
||||
import com.acme.myproject.moduleA.ServiceComponentA;
|
||||
import com.acme.myproject.moduleB.ServiceComponentB;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
class ModuleCTest {
|
||||
|
||||
@Nested
|
||||
public static class FailsStandaloneTest {
|
||||
|
||||
@NonVerifyingModuleTest
|
||||
static class Config {}
|
||||
|
||||
@Test
|
||||
void failsStandalone() {
|
||||
TestUtils.assertDependencyMissing(FailsStandaloneTest.Config.class, ServiceComponentB.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
static class FailsWithDirectDependencyTest {
|
||||
|
||||
@NonVerifyingModuleTest(BootstrapMode.DIRECT_DEPENDENCIES)
|
||||
static class Config {}
|
||||
|
||||
@Test
|
||||
void failsWithDirectDependency() {
|
||||
TestUtils.assertDependencyMissing(FailsWithDirectDependencyTest.Config.class, ServiceComponentA.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@NonVerifyingModuleTest(BootstrapMode.DIRECT_DEPENDENCIES)
|
||||
static class SucceedsWithDirectDependencyPlusItsDependenciesMocksTest {
|
||||
|
||||
@MockBean ServiceComponentA serviceComponentA;
|
||||
|
||||
@Test
|
||||
void bootstrapsContext() {
|
||||
assertThat(serviceComponentA).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@NonVerifyingModuleTest(BootstrapMode.ALL_DEPENDENCIES)
|
||||
static class SucceedsWithAllDependenciesTest {
|
||||
|
||||
@Autowired ServiceComponentA serviceComponentA;
|
||||
@Autowired ServiceComponentB serviceComponentB;
|
||||
|
||||
@Test
|
||||
void bootstrapsContext() {
|
||||
assertThat(serviceComponentA).isNotNull();
|
||||
assertThat(serviceComponentB).isNotNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
spring.main.banner-mode=OFF
|
||||
14
moduliths-sample/src/test/resources/logback.xml
Normal file
14
moduliths-sample/src/test/resources/logback.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="OFF">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user