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

Use correct file root when testing against embedded distribution #1798

Merged
merged 6 commits into from
Jan 18, 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
2 changes: 1 addition & 1 deletion src/org/labkey/junit/runner/WebTestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Collection<String> put(Class<?> key, String module)

private static List<String> getInstalledModules()
{
File modulesDir = new File(TestFileUtils.getDefaultDeployDir(), "modules");
File modulesDir = TestFileUtils.getModulesDir();

if (!modulesDir.exists())
return Collections.emptyList();
Expand Down
36 changes: 33 additions & 3 deletions src/org/labkey/test/TestFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public abstract class TestFileUtils
private static File _labkeyRoot = null;
private static File _buildDir = null;
private static File _testRoot = null;
private static File _modulesDir = null;
private static Set<File> _sampledataDirs = null;

public static String getFileContents(String rootRelativePath)
Expand Down Expand Up @@ -186,24 +187,53 @@ public static File getTestBuildDir()
return _buildDir;
}

private static File getBaseFileRoot()
{
// Files are a sibling of the modules directory
return new File(getModulesDir().getParentFile(), "files");
}

public static File getGradleReportDir()
{
return new File(getTestBuildDir(), "test/logs/reports");
}

public static File getDefaultDeployDir()
/**
* Private because deployment structure varies between Non-embedded, locally built embedded, and deployed embedded
* distribution.
*/
private static File getDefaultDeployDir()
{
return new File(getLabKeyRoot(), "build/deploy");
}

public static File getModulesDir()
{
if (_modulesDir == null)
{
_modulesDir = new File(getDefaultDeployDir(), "modules");
if (TestProperties.isEmbeddedTomcat() && !_modulesDir.isDirectory())
{
// Module root when deploying from embedded distribution
_modulesDir = new File(getDefaultDeployDir(), "embedded/server/modules");
}
}
return _modulesDir;
}

public static File getDefaultFileRoot(String containerPath)
{
return new File(getLabKeyRoot(), "build/deploy/files/" + containerPath + "/@files");
return new File(getBaseFileRoot(), containerPath + "/@files");
}

public static String getDefaultWebAppRoot()
{
File path = new File(getLabKeyRoot(), "build/deploy/labkeyWebapp");
File path = new File(getModulesDir().getParentFile(), "labkeyWebapp");
if (!path.isDirectory())
{
// Casing is different when deployed from an embedded distribution
path = new File(getModulesDir().getParentFile(), "labkeywebapp");
}
return path.toString();
}

Expand Down
11 changes: 5 additions & 6 deletions src/org/labkey/test/tests/CustomizeEmailTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class CustomizeEmailTemplateTest extends SpecimenBaseTest
private static final String _shipping = "123 main street";
private static final String _comments = "this is my comment";
private static final String _studyName = "Study 001";
private static final String _delim = "::";
private static final String _notificationDivName = "params";
private static final List<String> replacementParams = Arrays.asList(
"action",
Expand Down Expand Up @@ -151,7 +150,7 @@ protected void doVerifySteps() throws Exception
EmailRecordTable emailRecordTable = goToEmailRecord();
EmailRecordTable.EmailMessage message = emailRecordTable.getEmailAtTableIndex(3);
emailRecordTable.clickMessage(message);
String[] bodyContents = Locator.name(_notificationDivName).findElement(getDriver()).getText().split(_delim);
String[] bodyContents = Locator.name(_notificationDivName).findElement(getDriver()).getText().split("\n");
Map<String, String> emailNVPs = new HashMap<>();
for (String line : bodyContents)
{
Expand All @@ -168,7 +167,7 @@ protected void doVerifySteps() throws Exception
assertEquals(_studyName, message.getSubject());
assertEquals("New Request", emailNVPs.get("status"));
assertEquals("New Request Created", emailNVPs.get("action"));
assertEquals("/labkey", emailNVPs.get("contextPath"));
assertEquals(WebTestHelper.getContextPath(), emailNVPs.getOrDefault("contextPath", ""));
assertEquals("My Study", emailNVPs.get("folderName"));
assertEquals("/EmailTemplateProject/My Study", emailNVPs.get("folderPath"));
assertEquals(WebTestHelper.getBaseURL(), emailNVPs.get("homePageURL"));
Expand All @@ -178,14 +177,14 @@ private String buildTemplateBody()
{
String delimiter = "";
StringBuilder templateBuilder = new StringBuilder();
templateBuilder.append("<div name=\"").append(_notificationDivName).append("\">");
templateBuilder.append("<div name=\"").append(_notificationDivName).append("\">\n");
for (String param : replacementParams)
{
templateBuilder.append(delimiter);
templateBuilder.append(String.format("^%s|%s==%%s^", param, param));
delimiter = _delim + "\n";
delimiter = "<br>\n";
}
templateBuilder.append("</div>");
templateBuilder.append("\n</div>");
return templateBuilder.toString();
}

Expand Down