forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect callback methods (such as methods annotated with @PostConstruct …
…and @PreDestroy), and validate their signature. In this case, a DefinitionException is thrown, indicating that the method signature is invalid. Fix quarkusio#27591 according to the discussion.
- Loading branch information
1 parent
efeb47c
commit cb2c0d5
Showing
6 changed files
with
133 additions
and
7 deletions.
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
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
38 changes: 38 additions & 0 deletions
38
...ects/arc/tests/src/test/java/io/quarkus/arc/test/validation/InvalidPostConstructTest.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,38 @@ | ||
package io.quarkus.arc.test.validation; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class InvalidPostConstructTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(InvalidBean.class).shouldFail().build(); | ||
|
||
@Test | ||
public void testFailure() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
public static class InvalidBean { | ||
|
||
@PostConstruct | ||
public Uni<Void> invalid() { | ||
return Uni.createFrom().nullItem(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.../src/test/java/io/quarkus/arc/test/validation/InvalidPostConstructWithParametersTest.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,41 @@ | ||
package io.quarkus.arc.test.validation; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class InvalidPostConstructWithParametersTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(InvalidBean.class).shouldFail().build(); | ||
|
||
@Test | ||
public void testFailure() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
Assertions.assertTrue(error.getMessage().contains("invalid(java.lang.String ignored)")); | ||
Assertions.assertTrue(error.getMessage().contains("$InvalidBean")); | ||
Assertions.assertTrue(error.getMessage().contains("PostConstruct")); | ||
} | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
public static class InvalidBean { | ||
|
||
@PostConstruct | ||
public void invalid(String ignored) { | ||
|
||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...rojects/arc/tests/src/test/java/io/quarkus/arc/test/validation/InvalidPreDestroyTest.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,42 @@ | ||
package io.quarkus.arc.test.validation; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.spi.DefinitionException; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import io.smallrye.mutiny.Multi; | ||
|
||
public class InvalidPreDestroyTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder().beanClasses(InvalidBean.class).shouldFail().build(); | ||
|
||
@Test | ||
public void testFailure() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
Assertions.assertTrue(error.getMessage().contains("invalid()")); | ||
Assertions.assertTrue(error.getMessage().contains("$InvalidBean")); | ||
Assertions.assertTrue(error.getMessage().contains("PreDestroy")); | ||
} | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
public static class InvalidBean { | ||
|
||
@PreDestroy | ||
public Multi<Void> invalid() { | ||
return null; | ||
} | ||
} | ||
} |