Skip to content

Commit aaf4d5f

Browse files
committed
Tests to validate previous commits.
1 parent 15f5f63 commit aaf4d5f

File tree

8 files changed

+210
-1
lines changed

8 files changed

+210
-1
lines changed

service/tests/inject/codegen/src/test/java/io/helidon/service/tests/inject/codegen/InjectCodegenTypesTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424
import java.util.Set;
2525

2626
import io.helidon.common.types.TypeName;
27+
import io.helidon.service.inject.Binding;
28+
import io.helidon.service.inject.InjectConfig;
29+
import io.helidon.service.inject.InjectRegistryManager;
30+
import io.helidon.service.inject.InjectionMain;
31+
import io.helidon.service.inject.InjectionPlanBinder;
2732
import io.helidon.service.inject.api.Event;
2833
import io.helidon.service.inject.api.EventManager;
2934
import io.helidon.service.inject.api.FactoryType;
3035
import io.helidon.service.inject.api.GeneratedInjectService;
36+
import io.helidon.service.inject.api.InjectRegistry;
3137
import io.helidon.service.inject.api.InjectServiceDescriptor;
3238
import io.helidon.service.inject.api.Injection;
3339
import io.helidon.service.inject.api.Interception;
@@ -85,6 +91,7 @@ void testTypes() {
8591
checkField(toCheck, checked, fields, "INJECTION_SCOPE_HANDLER", Injection.ScopeHandler.class);
8692
checkField(toCheck, checked, fields, "INJECTION_SERVICES_FACTORY", Injection.ServicesFactory.class);
8793
checkField(toCheck, checked, fields, "INJECTION_QUALIFIED_FACTORY", Injection.QualifiedFactory.class);
94+
checkField(toCheck, checked, fields, "INJECTION_MAIN", Injection.Main.class);
8895

8996
// api.Interception.*
9097
checkField(toCheck, checked, fields, "INTERCEPTION_INTERCEPTED", Interception.Intercepted.class);
@@ -97,6 +104,13 @@ void testTypes() {
97104
checkField(toCheck, checked, fields, "INJECT_INJECTION_POINT", Ip.class);
98105
checkField(toCheck, checked, fields, "INJECT_SERVICE_INSTANCE", ServiceInstance.class);
99106
checkField(toCheck, checked, fields, "INJECT_SERVICE_DESCRIPTOR", InjectServiceDescriptor.class);
107+
checkField(toCheck, checked, fields, "INJECT_CONFIG", InjectConfig.class);
108+
checkField(toCheck, checked, fields, "INJECT_CONFIG_BUILDER", InjectConfig.Builder.class);
109+
checkField(toCheck, checked, fields, "INJECT_MAIN", InjectionMain.class);
110+
checkField(toCheck, checked, fields, "INJECT_BINDING", Binding.class);
111+
checkField(toCheck, checked, fields, "INJECT_REGISTRY", InjectRegistry.class);
112+
checkField(toCheck, checked, fields, "INJECT_REGISTRY_MANAGER", InjectRegistryManager.class);
113+
checkField(toCheck, checked, fields, "INJECT_PLAN_BINDER", InjectionPlanBinder.class);
100114

101115
// api.* interception types
102116
checkField(toCheck, checked, fields, "INTERCEPT_EXCEPTION", InterceptionException.class);
@@ -132,6 +146,9 @@ void testTypes() {
132146
checkField(toCheck, checked, fields, "INTERCEPT_G_WRAPPER_QUALIFIED_FACTORY",
133147
GeneratedInjectService.QualifiedFactoryInterceptionWrapper.class);
134148

149+
checkField(toCheck, checked, fields, "STRING_ARRAY", String[].class);
150+
checkField(toCheck, checked, fields, "DOUBLE_ARRAY", double[].class);
151+
135152
assertThat("If the collection is not empty, please add appropriate checkField line to this test",
136153
toCheck,
137154
IsEmptyCollection.empty());

service/tests/inject/inject/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@
137137
</execution>
138138
</executions>
139139
</plugin>
140+
<plugin>
141+
<groupId>io.helidon.service.inject</groupId>
142+
<artifactId>helidon-service-inject-maven-plugin</artifactId>
143+
<version>${helidon.version}</version>
144+
<executions>
145+
<execution>
146+
<id>create-application</id>
147+
<goals>
148+
<goal>create-application</goal>
149+
</goals>
150+
</execution>
151+
</executions>
152+
<configuration>
153+
<failOnWarning>true</failOnWarning>
154+
</configuration>
155+
</plugin>
140156
</plugins>
141157
</build>
142158
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.service.tests.inject;
18+
19+
import io.helidon.service.inject.InjectConfig;
20+
import io.helidon.service.inject.InjectionMain;
21+
import io.helidon.service.inject.api.InjectRegistry;
22+
import io.helidon.service.inject.api.Injection;
23+
24+
/**
25+
* Example of a custom main class.
26+
* This class is here to make sure this does not get broken.
27+
*/
28+
@Injection.Main
29+
public abstract class CustomMain extends InjectionMain {
30+
/*
31+
Important note:
32+
DO NOT change the signature of methods in this class, as that would cause a backward incompatible change
33+
for our users.
34+
The subtype is code generated. Any changes in the
35+
Helidon APIs would cause older generated code to stop working.
36+
The only exception is major version updates, but it would still be better if this stays compatible.
37+
*/
38+
39+
@Override
40+
protected void beforeServiceDescriptors(InjectConfig.Builder configBuilder) {
41+
System.out.println("Before service descriptors");
42+
}
43+
44+
@Override
45+
protected void afterServiceDescriptors(InjectConfig.Builder configBuilder) {
46+
System.out.println("After service descriptors");
47+
}
48+
49+
@Override
50+
protected InjectRegistry init(InjectConfig config) {
51+
System.out.println("Before init method");
52+
try {
53+
return super.init(config);
54+
} finally {
55+
System.out.println("After init method");
56+
}
57+
}
58+
59+
@Override
60+
protected void start(String[] arguments) {
61+
super.start(arguments);
62+
}
63+
64+
@Override
65+
protected InjectConfig.Builder configBuilder(String[] arguments) {
66+
return super.configBuilder(arguments);
67+
}
68+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.service.tests.inject;
18+
19+
import java.lang.reflect.Method;
20+
import java.lang.reflect.Modifier;
21+
22+
import io.helidon.service.inject.InjectConfig;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.hamcrest.CoreMatchers.equalTo;
27+
import static org.hamcrest.CoreMatchers.instanceOf;
28+
import static org.hamcrest.MatcherAssert.assertThat;
29+
30+
// test that the generated main class exists and works as expected
31+
public class MainClassTest {
32+
@Test
33+
public void testMain() throws NoSuchMethodException {
34+
// this class is expected to be code generated based on CustomMain @Injection.Main annotation
35+
ApplicationMain appMain = new ApplicationMain();
36+
37+
assertThat(appMain, instanceOf(CustomMain.class));
38+
39+
Class<ApplicationMain> theClass = ApplicationMain.class;
40+
41+
assertThat("The class must be public, to be a candidate for Main class",
42+
Modifier.isPublic(theClass.getModifiers()));
43+
44+
// the class must have the following two methods (when not using the maven plugin):
45+
// public static void main(String[] args) {}
46+
// protected void serviceDescriptors(InjectConfig.Builder config) {}
47+
Method mainMethod = theClass.getMethod("main", String[].class);
48+
assertThat("The main method must be public", Modifier.isPublic(mainMethod.getModifiers()));
49+
assertThat("The main method must be static", Modifier.isStatic(mainMethod.getModifiers()));
50+
assertThat("The main method must return void", mainMethod.getReturnType(), equalTo(void.class));
51+
52+
Method serviceDescriptorMethod = theClass.getDeclaredMethod("serviceDescriptors", InjectConfig.Builder.class);
53+
assertThat("The service descriptors method must be protected",
54+
Modifier.isProtected(serviceDescriptorMethod.getModifiers()));
55+
assertThat("The service descriptors method must not be static",
56+
!Modifier.isStatic(serviceDescriptorMethod.getModifiers()));
57+
assertThat("The service descriptors method must return void",
58+
serviceDescriptorMethod.getReturnType(),
59+
equalTo(void.class));
60+
}
61+
}

service/tests/inject/lookup/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@
137137
</execution>
138138
</executions>
139139
</plugin>
140+
<plugin>
141+
<groupId>io.helidon.service.inject</groupId>
142+
<artifactId>helidon-service-inject-maven-plugin</artifactId>
143+
<version>${helidon.version}</version>
144+
<executions>
145+
<execution>
146+
<id>create-application</id>
147+
<goals>
148+
<goal>create-application</goal>
149+
</goals>
150+
</execution>
151+
</executions>
152+
<configuration>
153+
<failOnWarning>true</failOnWarning>
154+
</configuration>
155+
</plugin>
140156
</plugins>
141157
</build>
142158

service/tests/inject/qualified-providers/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@
127127
</execution>
128128
</executions>
129129
</plugin>
130+
<plugin>
131+
<groupId>io.helidon.service.inject</groupId>
132+
<artifactId>helidon-service-inject-maven-plugin</artifactId>
133+
<version>${helidon.version}</version>
134+
<executions>
135+
<execution>
136+
<id>create-application</id>
137+
<goals>
138+
<goal>create-application</goal>
139+
</goals>
140+
</execution>
141+
</executions>
142+
<configuration>
143+
<failOnWarning>true</failOnWarning>
144+
</configuration>
145+
</plugin>
130146
</plugins>
131147
</build>
132148
</project>

service/tests/inject/toolbox/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@
141141
</execution>
142142
</executions>
143143
</plugin>
144+
<plugin>
145+
<groupId>io.helidon.service.inject</groupId>
146+
<artifactId>helidon-service-inject-maven-plugin</artifactId>
147+
<version>${helidon.version}</version>
148+
<executions>
149+
<execution>
150+
<id>create-application</id>
151+
<goals>
152+
<goal>create-application</goal>
153+
</goals>
154+
</execution>
155+
</executions>
156+
<configuration>
157+
<failOnWarning>true</failOnWarning>
158+
</configuration>
159+
</plugin>
144160
</plugins>
145161
</build>
146162
</project>

service/tests/inject/toolbox/src/test/java/io/helidon/service/tests/inject/toolbox/ToolBoxTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ void hierarchyOfInjections() {
150150
* This assumes the presence of module(s) + application(s) to handle all bindings, with effectively no lookups!
151151
*/
152152
@Test
153-
@Disabled("Disabled, as this required maven plugin, to be added in a later PR")
154153
void noServiceActivationRequiresLookupWhenApplicationIsPresent() {
155154
Counter counter = lookupCounter();
156155
long initialCount = counter.count();

0 commit comments

Comments
 (0)