Skip to content

Commit

Permalink
Tests to validate previous commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer committed Nov 4, 2024
1 parent 15f5f63 commit aaf4d5f
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
import java.util.Set;

import io.helidon.common.types.TypeName;
import io.helidon.service.inject.Binding;
import io.helidon.service.inject.InjectConfig;
import io.helidon.service.inject.InjectRegistryManager;
import io.helidon.service.inject.InjectionMain;
import io.helidon.service.inject.InjectionPlanBinder;
import io.helidon.service.inject.api.Event;
import io.helidon.service.inject.api.EventManager;
import io.helidon.service.inject.api.FactoryType;
import io.helidon.service.inject.api.GeneratedInjectService;
import io.helidon.service.inject.api.InjectRegistry;
import io.helidon.service.inject.api.InjectServiceDescriptor;
import io.helidon.service.inject.api.Injection;
import io.helidon.service.inject.api.Interception;
Expand Down Expand Up @@ -85,6 +91,7 @@ void testTypes() {
checkField(toCheck, checked, fields, "INJECTION_SCOPE_HANDLER", Injection.ScopeHandler.class);
checkField(toCheck, checked, fields, "INJECTION_SERVICES_FACTORY", Injection.ServicesFactory.class);
checkField(toCheck, checked, fields, "INJECTION_QUALIFIED_FACTORY", Injection.QualifiedFactory.class);
checkField(toCheck, checked, fields, "INJECTION_MAIN", Injection.Main.class);

// api.Interception.*
checkField(toCheck, checked, fields, "INTERCEPTION_INTERCEPTED", Interception.Intercepted.class);
Expand All @@ -97,6 +104,13 @@ void testTypes() {
checkField(toCheck, checked, fields, "INJECT_INJECTION_POINT", Ip.class);
checkField(toCheck, checked, fields, "INJECT_SERVICE_INSTANCE", ServiceInstance.class);
checkField(toCheck, checked, fields, "INJECT_SERVICE_DESCRIPTOR", InjectServiceDescriptor.class);
checkField(toCheck, checked, fields, "INJECT_CONFIG", InjectConfig.class);
checkField(toCheck, checked, fields, "INJECT_CONFIG_BUILDER", InjectConfig.Builder.class);
checkField(toCheck, checked, fields, "INJECT_MAIN", InjectionMain.class);
checkField(toCheck, checked, fields, "INJECT_BINDING", Binding.class);
checkField(toCheck, checked, fields, "INJECT_REGISTRY", InjectRegistry.class);
checkField(toCheck, checked, fields, "INJECT_REGISTRY_MANAGER", InjectRegistryManager.class);
checkField(toCheck, checked, fields, "INJECT_PLAN_BINDER", InjectionPlanBinder.class);

// api.* interception types
checkField(toCheck, checked, fields, "INTERCEPT_EXCEPTION", InterceptionException.class);
Expand Down Expand Up @@ -132,6 +146,9 @@ void testTypes() {
checkField(toCheck, checked, fields, "INTERCEPT_G_WRAPPER_QUALIFIED_FACTORY",
GeneratedInjectService.QualifiedFactoryInterceptionWrapper.class);

checkField(toCheck, checked, fields, "STRING_ARRAY", String[].class);
checkField(toCheck, checked, fields, "DOUBLE_ARRAY", double[].class);

assertThat("If the collection is not empty, please add appropriate checkField line to this test",
toCheck,
IsEmptyCollection.empty());
Expand Down
16 changes: 16 additions & 0 deletions service/tests/inject/inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.helidon.service.inject</groupId>
<artifactId>helidon-service-inject-maven-plugin</artifactId>
<version>${helidon.version}</version>
<executions>
<execution>
<id>create-application</id>
<goals>
<goal>create-application</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* 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 io.helidon.service.tests.inject;

import io.helidon.service.inject.InjectConfig;
import io.helidon.service.inject.InjectionMain;
import io.helidon.service.inject.api.InjectRegistry;
import io.helidon.service.inject.api.Injection;

/**
* Example of a custom main class.
* This class is here to make sure this does not get broken.
*/
@Injection.Main
public abstract class CustomMain extends InjectionMain {
/*
Important note:
DO NOT change the signature of methods in this class, as that would cause a backward incompatible change
for our users.
The subtype is code generated. Any changes in the
Helidon APIs would cause older generated code to stop working.
The only exception is major version updates, but it would still be better if this stays compatible.
*/

@Override
protected void beforeServiceDescriptors(InjectConfig.Builder configBuilder) {
System.out.println("Before service descriptors");
}

@Override
protected void afterServiceDescriptors(InjectConfig.Builder configBuilder) {
System.out.println("After service descriptors");
}

@Override
protected InjectRegistry init(InjectConfig config) {
System.out.println("Before init method");
try {
return super.init(config);
} finally {
System.out.println("After init method");
}
}

@Override
protected void start(String[] arguments) {
super.start(arguments);
}

@Override
protected InjectConfig.Builder configBuilder(String[] arguments) {
return super.configBuilder(arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* 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 io.helidon.service.tests.inject;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import io.helidon.service.inject.InjectConfig;

import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;

// test that the generated main class exists and works as expected
public class MainClassTest {
@Test
public void testMain() throws NoSuchMethodException {
// this class is expected to be code generated based on CustomMain @Injection.Main annotation
ApplicationMain appMain = new ApplicationMain();

assertThat(appMain, instanceOf(CustomMain.class));

Class<ApplicationMain> theClass = ApplicationMain.class;

assertThat("The class must be public, to be a candidate for Main class",
Modifier.isPublic(theClass.getModifiers()));

// the class must have the following two methods (when not using the maven plugin):
// public static void main(String[] args) {}
// protected void serviceDescriptors(InjectConfig.Builder config) {}
Method mainMethod = theClass.getMethod("main", String[].class);
assertThat("The main method must be public", Modifier.isPublic(mainMethod.getModifiers()));
assertThat("The main method must be static", Modifier.isStatic(mainMethod.getModifiers()));
assertThat("The main method must return void", mainMethod.getReturnType(), equalTo(void.class));

Method serviceDescriptorMethod = theClass.getDeclaredMethod("serviceDescriptors", InjectConfig.Builder.class);
assertThat("The service descriptors method must be protected",
Modifier.isProtected(serviceDescriptorMethod.getModifiers()));
assertThat("The service descriptors method must not be static",
!Modifier.isStatic(serviceDescriptorMethod.getModifiers()));
assertThat("The service descriptors method must return void",
serviceDescriptorMethod.getReturnType(),
equalTo(void.class));
}
}
16 changes: 16 additions & 0 deletions service/tests/inject/lookup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.helidon.service.inject</groupId>
<artifactId>helidon-service-inject-maven-plugin</artifactId>
<version>${helidon.version}</version>
<executions>
<execution>
<id>create-application</id>
<goals>
<goal>create-application</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
16 changes: 16 additions & 0 deletions service/tests/inject/qualified-providers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.helidon.service.inject</groupId>
<artifactId>helidon-service-inject-maven-plugin</artifactId>
<version>${helidon.version}</version>
<executions>
<execution>
<id>create-application</id>
<goals>
<goal>create-application</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
</plugins>
</build>
</project>
16 changes: 16 additions & 0 deletions service/tests/inject/toolbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.helidon.service.inject</groupId>
<artifactId>helidon-service-inject-maven-plugin</artifactId>
<version>${helidon.version}</version>
<executions>
<execution>
<id>create-application</id>
<goals>
<goal>create-application</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ void hierarchyOfInjections() {
* This assumes the presence of module(s) + application(s) to handle all bindings, with effectively no lookups!
*/
@Test
@Disabled("Disabled, as this required maven plugin, to be added in a later PR")
void noServiceActivationRequiresLookupWhenApplicationIsPresent() {
Counter counter = lookupCounter();
long initialCount = counter.count();
Expand Down

0 comments on commit aaf4d5f

Please sign in to comment.