|
1 | 1 | package org.labkey.panoramapublic.query; |
2 | 2 |
|
| 3 | +import org.apache.commons.lang3.StringUtils; |
3 | 4 | import org.jetbrains.annotations.NotNull; |
4 | 5 | import org.jetbrains.annotations.Nullable; |
5 | 6 | import org.junit.Assert; |
@@ -155,33 +156,45 @@ public String getJoinTableCol() |
155 | 156 |
|
156 | 157 | public static class TestCase extends Assert |
157 | 158 | { |
| 159 | + void assertSQLEquals(Object Oexpected, Object Oactual) |
| 160 | + { |
| 161 | + String expected = Oexpected instanceof SQLFragment s ? s.getRawSQL() : String.valueOf(Oexpected); |
| 162 | + String actual = Oactual instanceof SQLFragment s ? s.getRawSQL() : String.valueOf(Oactual); |
| 163 | + |
| 164 | + // strip "'s to make this less sensitive to SQL generation changes |
| 165 | + expected = StringUtils.replace(expected, "\"", "").trim(); |
| 166 | + actual = StringUtils.replace(actual, "\"", "").trim(); |
| 167 | + assertEquals(expected, actual); |
| 168 | + } |
| 169 | + |
| 170 | + |
158 | 171 | @Test |
159 | 172 | public void testContainerJoin() |
160 | 173 | { |
161 | 174 | ContainerJoin cj = new ContainerJoin("ExperimentAnnotationsId", PanoramaPublicManager.getTableInfoExperimentAnnotations()); |
162 | | - assertEquals("INNER JOIN panoramapublic.experimentannotations J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".ExperimentAnnotationsId", cj.getJoinSql().getSQL().trim()); |
163 | | - assertEquals("J1.Container", cj.getContainerSql().getRawSQL().trim()); |
| 175 | + assertSQLEquals("INNER JOIN panoramapublic.experimentannotations J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".ExperimentAnnotationsId", cj.getJoinSql()); |
| 176 | + assertSQLEquals("J1.Container", cj.getContainerSql()); |
164 | 177 | assertEquals(FieldKey.fromParts("ExperimentAnnotationsId", "Container"), cj.getContainerFieldKey()); |
165 | 178 |
|
166 | 179 | cj = cj.addJoin("DataValidationId", PanoramaPublicManager.getTableInfoDataValidation()); |
167 | | - assertEquals( |
| 180 | + assertSQLEquals( |
168 | 181 | "INNER JOIN panoramapublic.datavalidation J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".DataValidationId " + |
169 | | - " INNER JOIN panoramapublic.experimentannotations J2 ON J2.id = J1.ExperimentAnnotationsId", cj.getJoinSql().getSQL().trim()); |
170 | | - assertEquals("J2.Container", cj.getContainerSql().getRawSQL().trim()); |
| 182 | + " INNER JOIN panoramapublic.experimentannotations J2 ON J2.id = J1.ExperimentAnnotationsId", cj.getJoinSql()); |
| 183 | + assertSQLEquals("J2.Container", cj.getContainerSql()); |
171 | 184 | assertEquals(FieldKey.fromParts("DataValidationId", "ExperimentAnnotationsId", "Container"), cj.getContainerFieldKey()); |
172 | 185 |
|
173 | 186 | cj = cj.addJoin("SkylineDocValidationId", PanoramaPublicManager.getTableInfoSkylineDocValidation()); |
174 | | - assertEquals( |
| 187 | + assertSQLEquals( |
175 | 188 | "INNER JOIN panoramapublic.skylinedocvalidation J1 ON J1.id = " + PanoramaPublicTable.TABLE_ALIAS + ".SkylineDocValidationId " + |
176 | 189 | " INNER JOIN panoramapublic.datavalidation J2 ON J2.id = J1.DataValidationId " + |
177 | | - " INNER JOIN panoramapublic.experimentannotations J3 ON J3.id = J2.ExperimentAnnotationsId", cj.getJoinSql().getSQL().trim()); |
178 | | - assertEquals("J3.Container", cj.getContainerSql().getRawSQL().trim()); |
| 190 | + " INNER JOIN panoramapublic.experimentannotations J3 ON J3.id = J2.ExperimentAnnotationsId", cj.getJoinSql()); |
| 191 | + assertSQLEquals("J3.Container", cj.getContainerSql()); |
179 | 192 | assertEquals(FieldKey.fromParts("SkylineDocValidationId", "DataValidationId", "ExperimentAnnotationsId", "Container"), cj.getContainerFieldKey()); |
180 | 193 |
|
181 | 194 | cj = new ContainerJoin("ShortUrl", PanoramaPublicManager.getTableInfoExperimentAnnotations(), "ShortUrl"); |
182 | | - assertEquals( |
183 | | - "INNER JOIN panoramapublic.experimentannotations J1 ON J1.ShortUrl = " + PanoramaPublicTable.TABLE_ALIAS + ".ShortUrl", cj.getJoinSql().getSQL().trim()); |
184 | | - assertEquals("J1.Container", cj.getContainerSql().getRawSQL().trim()); |
| 195 | + assertSQLEquals( |
| 196 | + "INNER JOIN panoramapublic.experimentannotations J1 ON J1.ShortUrl = " + PanoramaPublicTable.TABLE_ALIAS + ".ShortUrl", cj.getJoinSql()); |
| 197 | + assertSQLEquals("J1.Container", cj.getContainerSql()); |
185 | 198 | assertEquals(FieldKey.fromParts("ShortUrl", "Container"), cj.getContainerFieldKey()); |
186 | 199 | } |
187 | 200 | } |
|
0 commit comments