Skip to content

DatabaseIdentifier #540

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.panoramapublic.query;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
Expand Down Expand Up @@ -155,33 +156,45 @@ public String getJoinTableCol()

public static class TestCase extends Assert
{
void assertSQLEquals(Object Oexpected, Object Oactual)
{
String expected = Oexpected instanceof SQLFragment s ? s.getRawSQL() : String.valueOf(Oexpected);
String actual = Oactual instanceof SQLFragment s ? s.getRawSQL() : String.valueOf(Oactual);

// strip "'s to make this less sensitive to SQL generation changes
expected = StringUtils.replace(expected, "\"", "").trim();
actual = StringUtils.replace(actual, "\"", "").trim();
assertEquals(expected, actual);
}


@Test
public void testContainerJoin()
{
ContainerJoin cj = new ContainerJoin("ExperimentAnnotationsId", PanoramaPublicManager.getTableInfoExperimentAnnotations());
assertEquals("INNER JOIN panoramapublic.experimentannotations J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".ExperimentAnnotationsId", cj.getJoinSql().getSQL().trim());
assertEquals("J1.Container", cj.getContainerSql().getRawSQL().trim());
assertSQLEquals("INNER JOIN panoramapublic.experimentannotations J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".ExperimentAnnotationsId", cj.getJoinSql());
assertSQLEquals("J1.Container", cj.getContainerSql());
assertEquals(FieldKey.fromParts("ExperimentAnnotationsId", "Container"), cj.getContainerFieldKey());

cj = cj.addJoin("DataValidationId", PanoramaPublicManager.getTableInfoDataValidation());
assertEquals(
assertSQLEquals(
"INNER JOIN panoramapublic.datavalidation J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".DataValidationId " +
" INNER JOIN panoramapublic.experimentannotations J2 ON J2.id = J1.ExperimentAnnotationsId", cj.getJoinSql().getSQL().trim());
assertEquals("J2.Container", cj.getContainerSql().getRawSQL().trim());
" INNER JOIN panoramapublic.experimentannotations J2 ON J2.id = J1.ExperimentAnnotationsId", cj.getJoinSql());
assertSQLEquals("J2.Container", cj.getContainerSql());
assertEquals(FieldKey.fromParts("DataValidationId", "ExperimentAnnotationsId", "Container"), cj.getContainerFieldKey());

cj = cj.addJoin("SkylineDocValidationId", PanoramaPublicManager.getTableInfoSkylineDocValidation());
assertEquals(
assertSQLEquals(
"INNER JOIN panoramapublic.skylinedocvalidation J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".SkylineDocValidationId " +
" INNER JOIN panoramapublic.datavalidation J2 ON J2.id = J1.DataValidationId " +
" INNER JOIN panoramapublic.experimentannotations J3 ON J3.id = J2.ExperimentAnnotationsId", cj.getJoinSql().getSQL().trim());
assertEquals("J3.Container", cj.getContainerSql().getRawSQL().trim());
" INNER JOIN panoramapublic.experimentannotations J3 ON J3.id = J2.ExperimentAnnotationsId", cj.getJoinSql());
assertSQLEquals("J3.Container", cj.getContainerSql());
assertEquals(FieldKey.fromParts("SkylineDocValidationId", "DataValidationId", "ExperimentAnnotationsId", "Container"), cj.getContainerFieldKey());

cj = new ContainerJoin("ShortUrl", PanoramaPublicManager.getTableInfoExperimentAnnotations(), "ShortUrl");
assertEquals(
"INNER JOIN panoramapublic.experimentannotations J1 ON J1.ShortUrl = " + PanoramaPublicTable.TABLE_ALIAS + ".ShortUrl", cj.getJoinSql().getSQL().trim());
assertEquals("J1.Container", cj.getContainerSql().getRawSQL().trim());
assertSQLEquals(
"INNER JOIN panoramapublic.experimentannotations J1 ON J1.ShortUrl = " + PanoramaPublicTable.TABLE_ALIAS + ".ShortUrl", cj.getJoinSql());
assertSQLEquals("J1.Container", cj.getContainerSql());
assertEquals(FieldKey.fromParts("ShortUrl", "Container"), cj.getContainerFieldKey());
}
}
Expand Down