Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wicket 7125 set bean manager #1022

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ You will find the source code here:
|-- wicket-auth-roles
|-- wicket-bean-validation
|-- wicket-cdi
|-- wicket-cdi-tests
|-- wicket-core
|-- wicket-tester
|-- wicket-core-tests
Expand Down
15 changes: 8 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<module>wicket-extensions</module>
<module>wicket-ioc</module>
<module>wicket-cdi</module>
<module>wicket-cdi-tests</module>
<module>wicket-spring</module>
<module>wicket-velocity</module>
<module>wicket-auth-roles</module>
Expand Down Expand Up @@ -145,7 +146,7 @@
<assertj-core.version>3.26.3</assertj-core.version>
<bouncycastle.version>1.79</bouncycastle.version>
<byte-buddy.version>1.15.10</byte-buddy.version>
<cdi-unit.version>4.2.0</cdi-unit.version>
<cdi-unit.version>5.0.0-EA7</cdi-unit.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-fileupload.version>2.0.0-M2</commons-fileupload.version>
<commons-io.version>2.17.0</commons-io.version>
Expand Down Expand Up @@ -572,6 +573,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.github.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
<version>${cdi-unit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-tester</artifactId>
Expand Down Expand Up @@ -637,12 +644,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jglue.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
<version>${cdi-unit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
93 changes: 93 additions & 0 deletions wicket-cdi-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-parent</artifactId>
<version>10.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>wicket-cdi-tests</artifactId>
<packaging>jar</packaging>
<name>Wicket CDI tests</name>
<description>
Provides tests for the Wicket and CDI module.
</description>
<properties>
<osgi.export.package>org.apache.wicket.cdi*;-noimport:=true</osgi.export.package>
<osgi.import.package>!java*,!kotlin*,!sun.nio.ch,org.slf4j*;version="[1.7,3)",*</osgi.import.package>
<maven.deploy.skip>true</maven.deploy.skip>
<japicmp.skip>true</japicmp.skip> <!-- this module is not released -->
</properties>
<dependencies>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-cdi</artifactId>
</dependency>
<dependency>
<groupId>io.github.cdi-unit</groupId>
<artifactId>cdi-unit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-tester</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.module</groupId>
<artifactId>weld-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@
*/
package org.apache.wicket.cdi;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.github.cdiunit.ActivatedAlternatives;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.inject.Inject;
import org.apache.wicket.Application;
import org.apache.wicket.cdi.testapp.AlternativeTestAppScope;
import org.apache.wicket.cdi.testapp.ModelWithInjectedDependency;
import org.apache.wicket.cdi.testapp.TestConversationPage;
import org.apache.wicket.cdi.testapp.TestPage;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author jsarman
*/
// FIXME Wicket 10. Re-enable once cdi-unit is adapted to jakarta.**
@Disabled
@ActivatedAlternatives(AlternativeTestAppScope.class)
class CdiConfigurationTest extends WicketCdiTestCase
{
@Inject
BeanManager beanManager;

@Test
void testApplicationScope()
{
Expand All @@ -40,6 +46,14 @@ void testApplicationScope()
tester.assertLabel("appscope", "Test ok");
}

@Test
void testUsesCdiJUnitConfiguration()
{
configure(new CdiConfiguration().setBeanManager(beanManager));
tester.startPage(TestPage.class);
tester.assertLabel("appscope", "Alternative ok");
}

@Test
void testConversationScope()
{
Expand All @@ -52,6 +66,26 @@ void testConversationScope()
}
}

@Test
void testNotConfigured()
{
assertThrows(IllegalStateException.class, () -> {
new ModelWithInjectedDependency();
});

}

@Test
void testAlreadyConfigured()
{
configure(new CdiConfiguration());

assertThrows(IllegalStateException.class, () -> {
CdiConfiguration.get(Application.get()).setBeanManager(beanManager);
});

}

@Test
void testConfigureTwice()
{
Expand All @@ -66,13 +100,12 @@ void testConfigureTwice()
@Test
void testApplicationLevelConfiguration()
{
WicketTester tester = new WicketTester();
CdiConfiguration config = new CdiConfiguration();
for (ConversationPropagation cp : ConversationPropagation.values())
{
config.setPropagation(cp);
assertEquals(cp, config.getPropagation());
}
config.configure(tester.getApplication());
configure(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jakarta.annotation.PreDestroy;
import jakarta.inject.Inject;

import org.apache.wicket.Page;
import org.apache.wicket.core.request.handler.IPageRequestHandler;
import org.apache.wicket.protocol.http.WebApplication;
Expand All @@ -35,6 +32,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.annotation.PreDestroy;

/**
* @author jsarman
*/
Expand All @@ -43,16 +42,19 @@ public class CdiWicketTester extends WicketTester
private static final Pattern COUNT_PATTERN = Pattern.compile("COUNT=x([0-9]+)x");
private static final Logger logger = LoggerFactory.getLogger(CdiWicketTester.class);

@Inject
ContextManager contextManager;

public CdiWicketTester(WebApplication app)
{
super(app);
NonContextual.of(CdiWicketTester.class).inject(this);
getHttpSession().setTemporary(false);
}

public void setContextManager(ContextManager contextManager)
{
this.contextManager = contextManager;
}

/**
* Process the request by first activating the contexts on initial call. This call is called
* recursively in the super class so keep track of the topmost call and only activate and
Expand Down Expand Up @@ -92,24 +94,6 @@ public Url urlFor(IRequestHandler handler)
return ret;
}

@PreDestroy
public void finish()
{
try
{
logger.debug("Destroying Cdi Wicket Tester");
if (getLastRequest() != null)
{
contextManager.deactivateContexts();
}
contextManager.destroy();
destroy();
}
catch (Throwable t)
{
}
}

/**
* Asserts that the response contains the right count. This can only be done by parsing the
* markup because models only contain valid values during a request, not after.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
*/
package org.apache.wicket.cdi;

import org.jboss.weld.bean.builtin.BeanManagerProxy;
import org.jboss.weld.module.web.servlet.HttpContextLifecycle;
import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter;

import io.github.cdiunit.internal.servlet.CdiUnitInitialListenerImpl;
import io.github.cdiunit.internal.servlet.LifecycleAwareRequest;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

import org.jboss.weld.bean.builtin.BeanManagerProxy;
import org.jboss.weld.module.web.servlet.HttpContextLifecycle;
import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter;

/**
* @author jsarman
*/
Expand Down Expand Up @@ -72,8 +74,7 @@ public void activateContexts(HttpServletRequest request)
if (currentRequest != null)
return;

// FIXME Wicket 10
currentRequest = null;// new LifecycleAwareRequest(new CdiUnitInitialListenerImpl(), new javax.servlet.http.HttpServletRequest(request));
currentRequest = new LifecycleAwareRequest(new CdiUnitInitialListenerImpl(), request);
lifecycle.requestInitialized(currentRequest, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.enterprise.context.Conversation;
import jakarta.inject.Inject;

import org.apache.wicket.cdi.testapp.TestConversationPage;
import org.apache.wicket.cdi.testapp.TestConversationalPage;
import org.apache.wicket.core.request.mapper.MountedMapper;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import jakarta.enterprise.context.Conversation;
import jakarta.inject.Inject;

/**
* @author jsarman
*/
// FIXME Wicket 10. Re-enable once cdi-unit is adapted to jakarta.**
@Disabled
class ConversationPropagatorTest extends WicketCdiTestCase
{
@Inject
Expand Down
Loading
Loading