Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Aug 23, 2024
1 parent de832ad commit 2d1519f
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 59 deletions.
45 changes: 45 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,51 @@
<version>${swagger.version}</version>
</dependency>

<!-- CDI Support -->

<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>3.1.9.Final</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>bean-validator</artifactId>
<version>2.5.0-b06</version>
</dependency>

<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-locator</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
<version>2.0.2.Final</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<version>3.1.9.Final</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
<version>3.0.5</version>
</dependency>

<!--
*****************************
Expand Down
5 changes: 3 additions & 2 deletions dotCMS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,6 @@

<!-- Weld CDI -->

<!--
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
Expand All @@ -1432,7 +1431,9 @@
<artifactId>weld-se-shaded</artifactId>
<scope>test</scope>
</dependency>
-->

<!-- Weld CDI -->

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package com.dotcms.rest.config;public class JerseyApplicationEventListener {
}

This file was deleted.

9 changes: 9 additions & 0 deletions dotCMS/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
version="2.0" bean-discovery-mode="annotated">
<scan>
<exclude name="org.apache.**"/>
</scan>
</beans>
5 changes: 4 additions & 1 deletion dotCMS/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">
version="3.0" metadata-complete="false">
<display-name>dotCMS</display-name>

<!-- Don't ever delete the following comment tags, it will break the build -->
Expand Down Expand Up @@ -191,6 +191,9 @@


<!-- DOTMARKETING LISTENERS -->
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<listener>
<listener-class>com.dotmarketing.listeners.ContextLifecycleListener</listener-class>
</listener>
Expand Down
25 changes: 19 additions & 6 deletions dotCMS/src/test/java/com/dotcms/UnitTestBase.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
package com.dotcms;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.dotcms.company.CompanyAPI;
import com.liferay.portal.model.Company;
import com.liferay.portal.model.User;
import org.junit.BeforeClass;

import com.dotcms.contenttype.business.ContentTypeAPI;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.util.BaseMessageResources;
import com.dotmarketing.util.Config;

import com.liferay.portal.model.Company;
import com.liferay.portal.model.User;
import java.util.TimeZone;
import org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.mockito.Mockito;

public abstract class UnitTestBase extends BaseMessageResources {

protected static final ContentTypeAPI contentTypeAPI = mock(ContentTypeAPI.class);
protected static final CompanyAPI companyAPI = mock(CompanyAPI.class);

private static WeldContainer weld;

public static class MyAPILocator extends APILocator {

static {
Expand All @@ -44,6 +47,9 @@ protected CompanyAPI getCompanyAPIImpl() {
@BeforeClass
public static void prepare () throws DotDataException, DotSecurityException, Exception {

weld = new Weld().containerId(RegistrySingletonProvider.STATIC_INSTANCE)
.initialize();

Config.initializeConfig();
Config.setProperty("API_LOCATOR_IMPLEMENTATION", MyAPILocator.class.getName());
Config.setProperty("SYSTEM_EXIT_ON_STARTUP_FAILURE", false);
Expand All @@ -55,4 +61,11 @@ public static void prepare () throws DotDataException, DotSecurityException, Exc
Mockito.lenient().when(company.getTimeZone()).thenReturn(TimeZone.getDefault());
Mockito.lenient().when(companyAPI.getDefaultCompany()).thenReturn(company);
}

@AfterClass
public static void cleanup() {
if( null != weld && weld.isRunning() ){
weld.shutdown();
}
}
}
9 changes: 9 additions & 0 deletions dotCMS/src/test/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
version="2.0" bean-discovery-mode="annotated">
<scan>
<exclude name="org.apache.**"/>
</scan>
</beans>
17 changes: 17 additions & 0 deletions dotcms-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,23 @@
<artifactId>jackson-annotations</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit5</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-shaded</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.dotmarketing.util.Logger;
import com.liferay.util.SystemProperties;
import org.awaitility.Awaitility;
import org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.mockito.Mockito;

import java.time.Duration;
Expand All @@ -29,6 +32,8 @@ public class IntegrationTestInitService {

private static final AtomicBoolean initCompleted = new AtomicBoolean(false);

private static WeldContainer weld;

static {
SystemProperties.getProperties();
}
Expand All @@ -44,6 +49,10 @@ public static IntegrationTestInitService getInstance() {
public void init() throws Exception {
try {
if (initCompleted.compareAndSet(false, true)) {

weld = new Weld().containerId(RegistrySingletonProvider.STATIC_INSTANCE)
.initialize();

System.setProperty(TestUtil.DOTCMS_INTEGRATION_TEST, TestUtil.DOTCMS_INTEGRATION_TEST);

Awaitility.setDefaultPollInterval(10, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit 2d1519f

Please sign in to comment.