GH-28 - Consolidate sample and integration tests module.

This commit is contained in:
Oliver Drotbohm
2022-07-27 12:03:47 +02:00
parent 9512c36c32
commit 13b83ef947
41 changed files with 23 additions and 208 deletions

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2018-2022 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;
import org.springframework.modulith.Modulith;
/**
* @author Oliver Drotbohm
*/
@Modulith
public class Application {
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2018-2022 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.api;
/**
*
* @author Oliver Drotbohm
*/
public class ComplexApiComponent {
}

View File

@@ -0,0 +1,4 @@
@NamedInterface("API")
package com.acme.myproject.complex.api;
import org.springframework.modulith.NamedInterface;

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2018-2022 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.springframework.stereotype.Component;
/**
* @author Oliver Drotbohm
*/
@Component
class ComplextInternalComponent {
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2019-2022 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.springframework.modulith.NamedInterface;
/**
* @author Oliver Drotbohm
*/
@NamedInterface({ "Port 1", "Port 2" })
public class FirstTypeBasedPort {
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2019-2022 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.springframework.modulith.NamedInterface;
/**
* @author Oliver Drotbohm
*/
@NamedInterface({ "Port 2", "Port 3" })
public class SecondTypeBasePort {
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2018-2022 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.spi;
/**
*
* @author Oliver Drotbohm
*/
public class ComplexSpiComponent {
}

View File

@@ -0,0 +1,4 @@
@NamedInterface("SPI")
package com.acme.myproject.complex.spi;
import org.springframework.modulith.NamedInterface;

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2018-2022 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.cycleA;
import com.acme.myproject.cycleB.CycleB;
/**
* @author Oliver Drotbohm
*/
public class CycleA {
CycleB cycleB;
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2018-2022 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.cycleB;
import com.acme.myproject.cycleA.CycleA;
/**
* @author Oliver Drotbohm
*/
public class CycleB {
CycleA cycleA;
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2019-2022 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.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;
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2018-2022 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.invalid;
import com.acme.myproject.moduleB.internal.InternalComponentB;
/**
* @author Oliver Drotbohm
*/
public class InvalidComponent {
InvalidComponent(InternalComponentB invalidComponent) {}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2018-2022 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.invalid2;
import com.acme.myproject.moduleA.ServiceComponentA;
/**
* @author Oliver Drotbohm
*/
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
}
}

View File

@@ -0,0 +1,4 @@
@ApplicationModule(allowedDependencies = "moduleB")
package com.acme.myproject.invalid2;
import org.springframework.modulith.ApplicationModule;

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2018-2022 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.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"));
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2018-2022 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.moduleA;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Oliver Drotbohm
*/
@Configuration
public class SomeConfigurationA {
@Bean
SomeAtBeanComponentA atBeanComponent() {
return null;
}
public static class SomeAtBeanComponentA {}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2018-2022 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.moduleA;
import lombok.Value;
import org.jmolecules.event.annotation.DomainEvent;
/**
* @author Oliver Drotbohm
*/
@Value
@DomainEvent
public class SomeEventA {
String message;
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2018-2022 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.moduleB;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import com.acme.myproject.moduleA.ServiceComponentA;
import com.acme.myproject.moduleB.internal.InternalComponentB;
/**
* @author Oliver Drotbohm
*/
@Component
@RequiredArgsConstructor
public class ServiceComponentB {
private final ServiceComponentA serviceComponentA;
private final InternalComponentB internalComponentB;
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2018-2022 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.moduleB;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import com.acme.myproject.moduleA.SomeEventA;
/**
* @author Oliver Drotbohm
*/
@Component
class SomeEventListenerB {
@EventListener
void on(SomeEventA event) {}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2018-2022 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.moduleB.internal;
import org.springframework.stereotype.Component;
/**
* @author Oliver Drotbohm
*/
@Component
public class InternalComponentB {
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2018-2022 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.moduleB.internal;
import org.springframework.stereotype.Component;
/**
* @author Oliver Drotbohm
*/
@Component
class SupportingComponentB {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2018-2022 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.moduleC;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import com.acme.myproject.moduleB.ServiceComponentB;
/**
* @author Oliver Drotbohm
*/
@Component
@RequiredArgsConstructor
class ServiceComponentC {
private final ServiceComponentB serviceComponentB;
}

View File

@@ -0,0 +1,4 @@
@ApplicationModule(displayName = "MyModule C")
package com.acme.myproject.moduleC;
import org.springframework.modulith.ApplicationModule;

View File

@@ -0,0 +1,81 @@
/*
* Copyright 2020-2022 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.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
@ConfigurationProperties("org.springframework.modulith.sample")
static class SomeConfigurationProperties {
/**
* Some test property.
*/
String test;
public SomeConfigurationProperties(String test) {
this.test = test;
}
}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2020-2022 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 {
}