-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15f5f63
commit aaf4d5f
Showing
8 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
service/tests/inject/inject/src/main/java/io/helidon/service/tests/inject/CustomMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
service/tests/inject/inject/src/test/java/io/helidon/service/tests/inject/MainClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters