Skip to content

Commit dd2e3e3

Browse files
committed
List test
1 parent 7903851 commit dd2e3e3

3 files changed

Lines changed: 45 additions & 61 deletions

File tree

experiment/src/org/labkey/experiment/api/ExpDataClassDataTestCase.jsp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
<%@ page import="org.labkey.api.query.QueryUpdateService" %>
7474
<%@ page import="org.labkey.api.query.SchemaKey" %>
7575
<%@ page import="org.labkey.api.query.UserSchema" %>
76-
<%@ page import="org.labkey.api.query.ValidationException" %>
7776
<%@ page import="org.labkey.api.search.SearchService" %>
7877
<%@ page import="org.labkey.api.security.SecurityManager" %>
7978
<%@ page import="org.labkey.api.security.User" %>
@@ -473,9 +472,7 @@ public void testDataClassFromTemplate() throws Exception
473472
474473
DomainTemplateGroup templateGroup = DomainTemplateGroup.get(c, "TestingFromTemplate");
475474
assertNotNull(templateGroup);
476-
assertFalse(
477-
"Errors in template: " + StringUtils.join(templateGroup.getErrors(), ", "),
478-
templateGroup.hasErrors());
475+
assertFalse("Errors in template: " + StringUtils.join(templateGroup.getErrors(), ", "), templateGroup.hasErrors());
479476
480477
DomainTemplate template = templateGroup.getTemplate("testingFromTemplate");
481478
assertNotNull(template);
@@ -494,31 +491,7 @@ public void testDataClassFromTemplate() throws Exception
494491
Set<String> mandatory = kind.getMandatoryPropertyNames(domain);
495492
assertTrue("Expected template to set 'aa' as mandatory: " + mandatory, mandatory.contains("aa"));
496493
497-
// Verify <reservedColumnNames> from the template are honored by the DomainKind
498-
Set<String> reservedNames = kind.getReservedPropertyNames(domain, _user);
499-
assertTrue("Expected template reserved name 'reservedOne' in: " + reservedNames,
500-
reservedNames.stream().anyMatch(n -> n.equalsIgnoreCase("reservedOne")));
501-
assertTrue("Expected template reserved name 'ReservedTwo' in: " + reservedNames,
502-
reservedNames.stream().anyMatch(n -> n.equalsIgnoreCase("ReservedTwo")));
503-
504-
// Attempt to add a field whose name collides with a template-reserved name (mixed case)
505-
GWTDomain<GWTPropertyDescriptor> origGwt = DomainUtil.getDomainDescriptor(_user, domain);
506-
GWTDomain<GWTPropertyDescriptor> updateGwt = new GWTDomain<>(origGwt);
507-
List<GWTPropertyDescriptor> updatedFields = new ArrayList<>(updateGwt.getFields());
508-
updatedFields.add(new GWTPropertyDescriptor("RESERVEDONE", "http://www.w3.org/2001/XMLSchema#string"));
509-
updateGwt.setFields(updatedFields);
510-
ValidationException ve = DomainUtil.updateDomainDescriptor(origGwt, updateGwt, c, _user);
511-
assertTrue("Expected a validation error when adding a reserved-name field", ve.hasErrors());
512-
assertTrue("Expected error message to flag the reserved name: " + ve.getMessage(),
513-
ve.getMessage().toLowerCase().contains("reserved"));
514-
515-
// A non-reserved field name should validate cleanly
516-
GWTDomain<GWTPropertyDescriptor> okUpdate = new GWTDomain<>(origGwt);
517-
List<GWTPropertyDescriptor> okFields = new ArrayList<>(okUpdate.getFields());
518-
okFields.add(new GWTPropertyDescriptor("nonReservedField", "http://www.w3.org/2001/XMLSchema#string"));
519-
okUpdate.setFields(okFields);
520-
ValidationException okVe = DomainUtil.validateProperties(domain, okUpdate, kind, origGwt, _user);
521-
assertFalse("Did not expect validation errors for a non-reserved field: " + okVe.getMessage(), okVe.hasErrors());
494+
helper.verifyReservedColumnNames(c, _user, domain);
522495
523496
ExpDataClassImpl dataClass = (ExpDataClassImpl)ExperimentService.get().getDataClass(c, domainName);
524497
assertNotNull(dataClass);
@@ -571,7 +544,7 @@ public void testDomainTemplate() throws Exception
571544
assertNotNull(templateGroup);
572545
assertFalse("Errors in template: " + StringUtils.join(templateGroup.getErrors(), ", "), templateGroup.hasErrors());
573546
574-
List<Domain> created = templateGroup.createAndImport(sub, _user, true, true);
547+
templateGroup.createAndImport(sub, _user, true, true);
575548
576549
// verify the "Priority" list was created and data was imported
577550
UserSchema listSchema = QueryService.get().getUserSchema(_user, sub, "lists");
@@ -646,6 +619,13 @@ public void testDomainTemplate() throws Exception
646619
647620
Collection<String> aliases = data.getAliases();
648621
assertTrue("Expected aliases to contain 'xsd' and 'domain templates', got: " + aliases, aliases.containsAll(List.of("xsd", "domain templates")));
622+
623+
// Verify reserved column names on lists
624+
TableInfo categoryTable = listSchema.getTable("Category");
625+
Domain categoryDomain = categoryTable.getDomain();
626+
assertNotNull(categoryDomain);
627+
628+
helper.verifyReservedColumnNames(c, _user, categoryTable.getDomain());
649629
}
650630
651631
// Issue 25224: NPE trying to delete a folder with a DataClass with at least one result row in it

experiment/src/org/labkey/experiment/api/ExpProvisionedTableTestHelper.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.labkey.experiment.api;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
45
import org.junit.Assert;
56
import org.junit.Assume;
67
import org.labkey.api.collections.ArrayListMap;
78
import org.labkey.api.data.Container;
89
import org.labkey.api.data.TableInfo;
910
import org.labkey.api.exp.property.Domain;
11+
import org.labkey.api.exp.property.DomainKind;
1012
import org.labkey.api.exp.property.DomainUtil;
1113
import org.labkey.api.exp.query.ExpSchema;
1214
import org.labkey.api.gwt.client.model.GWTDomain;
@@ -165,4 +167,36 @@ static void assertMultiValue(Object value, String... expected) throws Exception
165167
for (String e : expected)
166168
Assert.assertTrue("Failed to find '" + e + "' in multivalue '" + s + "'", s.contains(e));
167169
}
170+
171+
public void verifyReservedColumnNames(Container c, User user, @NotNull Domain domain)
172+
{
173+
DomainKind<?> kind = domain.getDomainKind();
174+
Assert.assertNotNull(kind);
175+
176+
// Verify <reservedColumnNames> from the template are honored by the DomainKind
177+
Set<String> reservedNames = kind.getReservedPropertyNames(domain, user);
178+
Assert.assertTrue("Expected template reserved name 'reservedOne' in: " + reservedNames,
179+
reservedNames.stream().anyMatch(n -> n.equalsIgnoreCase("reservedOne")));
180+
Assert.assertTrue("Expected template reserved name 'ReservedTwo' in: " + reservedNames,
181+
reservedNames.stream().anyMatch(n -> n.equalsIgnoreCase("ReservedTwo")));
182+
183+
// Attempt to add a field whose name collides with a template-reserved name (mixed case)
184+
GWTDomain<GWTPropertyDescriptor> origGwt = DomainUtil.getDomainDescriptor(user, domain);
185+
GWTDomain<GWTPropertyDescriptor> updateGwt = new GWTDomain<>(origGwt);
186+
List<GWTPropertyDescriptor> updatedFields = new ArrayList<>(updateGwt.getFields());
187+
updatedFields.add(new GWTPropertyDescriptor("RESERVEDONE", "http://www.w3.org/2001/XMLSchema#string"));
188+
updateGwt.setFields(updatedFields);
189+
ValidationException ve = DomainUtil.updateDomainDescriptor(origGwt, updateGwt, c, user);
190+
Assert.assertTrue("Expected a validation error when adding a reserved-name field", ve.hasErrors());
191+
Assert.assertTrue("Expected error message to flag the reserved name: " + ve.getMessage(),
192+
ve.getMessage().toLowerCase().contains("reserved"));
193+
194+
// A non-reserved field name should validate cleanly
195+
GWTDomain<GWTPropertyDescriptor> okUpdate = new GWTDomain<>(origGwt);
196+
List<GWTPropertyDescriptor> okFields = new ArrayList<>(okUpdate.getFields());
197+
okFields.add(new GWTPropertyDescriptor("nonReservedField", "http://www.w3.org/2001/XMLSchema#string"));
198+
okUpdate.setFields(okFields);
199+
ValidationException okVe = DomainUtil.validateProperties(domain, okUpdate, kind, origGwt, user);
200+
Assert.assertFalse("Did not expect validation errors for a non-reserved field: " + okVe.getMessage(), okVe.hasErrors());
201+
}
168202
}

experiment/src/org/labkey/experiment/api/ExpSampleTypeTestCase.jsp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@
4545
<%@ page import="org.labkey.api.exp.api.ExperimentService" %>
4646
<%@ page import="org.labkey.api.exp.api.SampleTypeService" %>
4747
<%@ page import="org.labkey.api.exp.property.Domain" %>
48-
<%@ page import="org.labkey.api.exp.property.DomainKind" %>
4948
<%@ page import="org.labkey.api.exp.property.DomainTemplate" %>
5049
<%@ page import="org.labkey.api.exp.property.DomainTemplateGroup" %>
51-
<%@ page import="org.labkey.api.exp.property.DomainUtil" %>
52-
<%@ page import="org.labkey.api.gwt.client.model.GWTDomain" %>
53-
<%@ page import="org.labkey.api.query.ValidationException" %>
5450
<%@ page import="org.labkey.api.exp.query.ExpSchema" %>
5551
<%@ page import="org.labkey.api.exp.query.SamplesSchema" %>
5652
<%@ page import="org.labkey.api.gwt.client.AuditBehaviorType" %>
@@ -1393,33 +1389,7 @@ public void testSampleTypeFromTemplateReservedColumnNames() throws Exception
13931389
final Domain domain = template.createAndImport(c, _user, domainName, true, false);
13941390
assertNotNull(domain);
13951391
1396-
DomainKind kind = domain.getDomainKind();
1397-
1398-
// Verify <reservedColumnNames> from the template are honored by the DomainKind
1399-
Set<String> reservedNames = kind.getReservedPropertyNames(domain, _user);
1400-
assertTrue("Expected template reserved name 'reservedOne' in: " + reservedNames,
1401-
reservedNames.stream().anyMatch(n -> n.equalsIgnoreCase("reservedOne")));
1402-
assertTrue("Expected template reserved name 'ReservedTwo' in: " + reservedNames,
1403-
reservedNames.stream().anyMatch(n -> n.equalsIgnoreCase("ReservedTwo")));
1404-
1405-
// Attempt to add a field whose name collides with a template-reserved name (mixed case to exercise case-insensitivity)
1406-
GWTDomain<GWTPropertyDescriptor> origGwt = DomainUtil.getDomainDescriptor(_user, domain.getTypeURI(), c);
1407-
GWTDomain<GWTPropertyDescriptor> updateGwt = new GWTDomain<>(origGwt);
1408-
List<GWTPropertyDescriptor> updatedFields = new ArrayList<>(updateGwt.getFields());
1409-
updatedFields.add(new GWTPropertyDescriptor("RESERVEDONE", "http://www.w3.org/2001/XMLSchema#string"));
1410-
updateGwt.setFields(updatedFields);
1411-
ValidationException ve = DomainUtil.updateDomainDescriptor(origGwt, updateGwt, c, _user);
1412-
assertTrue("Expected a validation error when adding a reserved-name field", ve.hasErrors());
1413-
assertTrue("Expected error message to flag the reserved name: " + ve.getMessage(),
1414-
ve.getMessage().toLowerCase().contains("reserved"));
1415-
1416-
// Sanity check: a non-reserved field name should validate cleanly
1417-
GWTDomain<GWTPropertyDescriptor> okUpdate = new GWTDomain<>(origGwt);
1418-
List<GWTPropertyDescriptor> okFields = new ArrayList<>(okUpdate.getFields());
1419-
okFields.add(new GWTPropertyDescriptor("nonReservedField", "http://www.w3.org/2001/XMLSchema#string"));
1420-
okUpdate.setFields(okFields);
1421-
ValidationException okVe = DomainUtil.validateProperties(domain, okUpdate, kind, origGwt, _user);
1422-
assertFalse("Did not expect validation errors for a non-reserved field: " + okVe.getMessage(), okVe.hasErrors());
1392+
helper.verifyReservedColumnNames(c, _user, domain);
14231393
}
14241394
14251395
private void assertExpectedName(ExpSampleType st, String expectedName)

0 commit comments

Comments
 (0)