Skip to content

Commit ee2ede7

Browse files
committed
manageColumns disabled test
1 parent 33efac4 commit ee2ede7

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var console = require("console");
2+
3+
function managedColumns() {
4+
return false;
5+
}
6+
7+
function beforeInsert(row, errors) {
8+
console.log("list: beforeInsert: row is: " + row);
9+
10+
// Flower is not marked as a managed column, but managed columns are disabled
11+
if (row.type === 'A') {
12+
row.flower = 'Rose';
13+
}
14+
}
15+
16+
function beforeUpdate(row, oldRow, errors) {
17+
console.log("list: beforeUpdate: row is: " + row);
18+
19+
if (row.type === 'A') {
20+
row.hemisphere = 'Northern';
21+
}
22+
}

src/org/labkey/test/tests/TriggerScriptTest.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class TriggerScriptTest extends BaseWebDriverTest
7777
private static final String SUBFOLDER_NAME = "SubfolderA";
7878
private static final String SUBFOLDER_PATH = "/" + PROJECT_NAME + "/" + SUBFOLDER_NAME;
7979

80-
//List constants
80+
// List constants
8181
private static final String TRIGGER_MODULE = "triggerTestModule";
8282
private static final String SIMPLE_MODULE = "simpletest";
8383
private static final String LIST_NAME = "Employees";
@@ -91,7 +91,7 @@ public class TriggerScriptTest extends BaseWebDriverTest
9191
private static final String MANAGED_STRUCT_ADD_ERROR = "attempted to add";
9292
private static final String MANAGED_STRUCT_REMOVE_ERROR = "attempted to remove";
9393

94-
//Dataset constants
94+
// Dataset constants
9595
private static final String STUDY_SCHEMA = "study";
9696
private static final String DATASET_NAME = "Demographics";
9797
private static final String INDIVIDUAL_TEST = "Individual Test";
@@ -640,6 +640,42 @@ public void testDatasetManagedColumnsTriggers() throws Exception
640640
doManagedColumnsTriggerTest(STUDY_SCHEMA, DATASET_NAME, "ParticipantId", true, COMMENTS_FIELD);
641641
}
642642

643+
@Test
644+
public void testNonIteratorTriggerManagedColumnsDisabled() throws Exception
645+
{
646+
// List insert is not backed by data iterator, so expect the trigger mutations to apply without error
647+
var keyField = new FieldDefinition("type").setLabel("Type");
648+
649+
var unmanagedList = new VarListDefinition("Unmanaged")
650+
.setKeyName(keyField.getName())
651+
.setFields(List.of(keyField, new FieldDefinition("color"), new FieldDefinition("flower"), new FieldDefinition("hemisphere")));
652+
653+
var cn = createDefaultConnection();
654+
unmanagedList.create(cn, getProjectName());
655+
656+
var insCmd = new InsertRowsCommand(LIST_SCHEMA, unmanagedList.getName());
657+
insCmd.addRow(Map.of("type", "A", "color", "Red"));
658+
insCmd.execute(cn, getProjectName());
659+
660+
var queryHelper = new QueryApiHelper(cn, getProjectName(), LIST_SCHEMA, unmanagedList.getName());
661+
662+
var row = queryHelper.selectRows().getRows().getFirst();
663+
Assert.assertEquals("A", row.get("type"));
664+
Assert.assertEquals("Red", row.get("color"));
665+
Assert.assertEquals("Rose", row.get("flower"));
666+
Assert.assertNull(row.get("hemisphere"));
667+
668+
var updCmd = new UpdateRowsCommand(LIST_SCHEMA, unmanagedList.getName());
669+
updCmd.addRow(Map.of("type", "A", "flower", "Tulip"));
670+
updCmd.execute(cn, getProjectName());
671+
672+
row = queryHelper.selectRows().getRows().getFirst();
673+
Assert.assertEquals("A", row.get("type"));
674+
Assert.assertEquals("Red", row.get("color"));
675+
Assert.assertEquals("Tulip", row.get("flower"));
676+
Assert.assertEquals("Northern", row.get("hemisphere"));
677+
}
678+
643679
/**
644680
* Shared test of managed columns trigger behavior across data types.
645681
* Verifies that the framework enforces managed column declarations and detects structural violations.

0 commit comments

Comments
 (0)