ACS-9844 added extension point for providing additional context configuration files (#3507)

This commit is contained in:
jakubkochman
2025-08-08 10:33:06 +02:00
committed by GitHub
parent 4aae383637
commit efe053167d
2 changed files with 53 additions and 9 deletions

View File

@@ -25,6 +25,8 @@
*/
package org.alfresco.rest.api.tests;
import java.util.Arrays;
import org.alfresco.repo.web.util.JettyComponent;
public class EnterprisePublicApiTestFixture extends EnterpriseTestFixture
@@ -40,32 +42,53 @@ public class EnterprisePublicApiTestFixture extends EnterpriseTestFixture
public final static String[] CLASS_LOCATIONS = new String[]{"classpath*:/publicapi/lucene/"};
private static EnterprisePublicApiTestFixture instance;
private String[] customConfigLocations;
/* Note: synchronized for multi-threaded test access */
public synchronized static EnterprisePublicApiTestFixture getInstance(boolean createTestData) throws Exception
public synchronized static EnterprisePublicApiTestFixture getInstance(boolean createTestData, String... customConfigLocations)
{
if (instance == null)
{
instance = new EnterprisePublicApiTestFixture();
instance.setup(createTestData);
instance = new EnterprisePublicApiTestFixture(customConfigLocations);
try
{
instance.setup(createTestData);
}
catch (Exception e)
{
String errorMessage = "Exception was thrown during setup EnterprisePublicApiTestFixture: " + e.getClass() + " - " + e.getMessage();
throw new RuntimeException(errorMessage, e);
}
}
return instance;
}
public static EnterprisePublicApiTestFixture getInstance() throws Exception
public static EnterprisePublicApiTestFixture getInstance(String... customConfigLocations)
{
return getInstance(true);
return getInstance(true, customConfigLocations);
}
private EnterprisePublicApiTestFixture()
public static EnterprisePublicApiTestFixture getInstance()
{
return getInstance(true, null);
}
public static EnterprisePublicApiTestFixture getInstance(boolean createTestData)
{
return getInstance(createTestData, null);
}
private EnterprisePublicApiTestFixture(String... customConfigLocations)
{
super(CONFIG_LOCATIONS, CLASS_LOCATIONS, PORT, CONTEXT_PATH, PUBLIC_API_SERVLET_NAME, DEFAULT_NUM_MEMBERS_PER_SITE, false);
this.customConfigLocations = customConfigLocations;
}
@Override
protected JettyComponent makeJettyComponent()
{
JettyComponent jettyComponent = new EnterpriseJettyComponent(getPort(), getContextPath(), getConfigLocations(), getClassLocations());
String[] configLocations = mergeLocations(getConfigLocations(), this.customConfigLocations);
JettyComponent jettyComponent = new EnterpriseJettyComponent(getPort(), getContextPath(), configLocations, getClassLocations());
return jettyComponent;
}
@@ -74,4 +97,19 @@ public class EnterprisePublicApiTestFixture extends EnterpriseTestFixture
{
return new RepoService(applicationContext);
}
private String[] mergeLocations(String[]... locations)
{
String[] mergedLocations = new String[0];
for (String[] location : locations)
{
if (location == null || location.length == 0)
{
continue;
}
mergedLocations = Arrays.copyOf(mergedLocations, mergedLocations.length + location.length);
System.arraycopy(location, 0, mergedLocations, mergedLocations.length - location.length, location.length);
}
return mergedLocations;
}
}

View File

@@ -36,15 +36,21 @@ public class EnterpriseTestApi extends AbstractTestApi
getTestFixture().getRandomNetwork();
}
protected String[] getCustomConfigLocations()
{
return new String[]{};
}
@Override
protected TestFixture getTestFixture() throws Exception
{
return EnterprisePublicApiTestFixture.getInstance();
return EnterprisePublicApiTestFixture.getInstance(getCustomConfigLocations());
}
@Override
protected TestFixture getTestFixture(boolean createTestData) throws Exception
{
return EnterprisePublicApiTestFixture.getInstance(createTestData);
return EnterprisePublicApiTestFixture.getInstance(createTestData, getCustomConfigLocations());
}
}