diff --git a/modules/triggerTestModule/resources/queries/exp.data/DataClassTest.js b/modules/triggerTestModule/resources/queries/exp.data/DataClassTest.js index 8df01a2fcf..15e5a4cea7 100644 --- a/modules/triggerTestModule/resources/queries/exp.data/DataClassTest.js +++ b/modules/triggerTestModule/resources/queries/exp.data/DataClassTest.js @@ -6,6 +6,13 @@ var shared = require("TriggerTestModule/EmployeeLib"); var console = require("console"); +function managedColumns() { + return { + insert: ["Country"], + update: ["Country"], + }; +} + function init(event, errors) { console.log("init got triggered with event: " + event); console.log(shared.sampleFunc("this is from the shared function")); @@ -13,43 +20,79 @@ function init(event, errors) { function beforeInsert(row, errors) { console.log("exp.data: beforeInsert: row is: " + row); - if(row.Comments) { - if (row.Comments == "Individual Test") { - row.Country = "Inserting Single"; - row.Comments = "BeforeDelete"; //set this for next test step - } - else if (row.Comments == "Import Test") - row.Country = "Importing TSV"; - else if (row.Comments == "API Test") - row.Country = "API BeforeInsert"; + var name = row.Name || row.name; + if (name === "Managed Insert") { + row.Country = "MANAGED-INS"; + } else if (name === "Managed Struct") { + row.Country = "MANAGED-STRUCT"; + row.undeclaredCol = "bad"; + } else if (name === "Managed Struct Remove") { + row.Country = "MANAGED-STRUCT-REM"; + delete row.Comments; + delete row.comments; + } + + if (name === "Managed Unhandled") { + delete row.Country; } else { - if (row.comments == "Individual Test") { - row.country = "Inserting Single"; - row.comments = "BeforeDelete"; //set this for next test step + if (row.Comments) { + if (row.Comments === "Individual Test") { + row.Country = "Inserting Single"; + row.Comments = "BeforeDelete"; //set this for next test step + } else if (row.Comments === "Import Test") { + row.Country = "Importing TSV"; + } else if (row.Comments === "API Test") { + row.Country = "API BeforeInsert"; + } + } else { + if (row.comments === "Individual Test") { + row.country = "Inserting Single"; + row.comments = "BeforeDelete"; //set this for next test step + } else if (row.comments === "Import Test") { + row.country = "Importing TSV"; + } else if (row.comments === "API Test") { + row.country = "API BeforeInsert"; + } } - else if (row.comments == "Import Test") - row.country = "Importing TSV"; - else if (row.comments == "API Test") - row.country = "API BeforeInsert"; + if (!row.Country) + row.Country = "DC-DEFAULT"; } - console.log("exp.data: edited row is: " + row); console.log(shared.sampleFunc("exp.data: this is from the shared function")); } function beforeUpdate(row, oldRow, errors) { console.log("exp.data: beforeUpdate: row is: " + row); - if(row.Comments == "BeforeUpdate") - row.Country = "Before Update changed me"; - else if(row.comments == "BeforeUpdate") - row.country = "Before Update changed me"; + var comments = row.Comments || row.comments; + if (comments === "Managed Update") { + row.Country = "MANAGED-UPD"; + } + else if (comments === "Managed Struct") { + row.Country = "MANAGED-STRUCT"; + row.undeclaredCol = "bad"; + } + else if (comments === "Managed Struct Remove") { + row.Country = "MANAGED-STRUCT-REM"; + delete row.Comments; + } + + if (comments === "Managed Unhandled") { + delete row.Country; + } else { + if (row.Comments === "BeforeUpdate") + row.Country = "Before Update changed me"; + else if (row.comments === "BeforeUpdate") + row.country = "Before Update changed me"; + if (!row.Country) + row.Country = "DC-DEFAULT-UPD"; + } console.log("exp.data: old row is: " + oldRow); console.log(shared.sampleFunc("exp.data: this is from the shared function")); } function beforeDelete(row, errors) { console.log("exp.data: beforeDelete: row is: " + row); - if(row.Comments == "BeforeDelete" || row.comments == "BeforeDelete") + if (row.comments === "BeforeDelete") errors[null] = "This is the Before Delete Error"; console.log(shared.sampleFunc("exp.data: this is from the shared function")); @@ -58,7 +101,7 @@ function beforeDelete(row, errors) { function afterInsert(row, errors) { console.log("exp.data: afterInsert: row is: " + row); - if(row.Comments == "AfterInsert" || row.comments == "AfterInsert") + if (row.comments === "AfterInsert") errors[null] = "This is the After Insert Error"; console.log(shared.sampleFunc("exp.data: this is from the shared function")); @@ -67,7 +110,7 @@ function afterInsert(row, errors) { function afterUpdate(row, oldRow, errors) { console.log("exp.data: afterUpdate: row is: " + row); - if(row.Comments == "AfterUpdate" || row.comments == "AfterUpdate") + if (row.comments === "AfterUpdate") errors[null] = "This is the After Update Error"; console.log("exp.data: old row is: " +oldRow); @@ -77,7 +120,7 @@ function afterUpdate(row, oldRow, errors) { function afterDelete(row, errors) { console.log("exp.data: afterDelete: row is: " + row); - if(row.Country == "Before Update changed me" || row.country == "Before Update changed me") + if (row.country === "Before Update changed me") errors[null] = "This is the After Delete Error"; console.log(shared.sampleFunc("exp.data: this is from the shared function")); diff --git a/modules/triggerTestModule/resources/queries/lists/Employees.js b/modules/triggerTestModule/resources/queries/lists/Employees.js index fdd8c2dab7..9e26754ca5 100644 --- a/modules/triggerTestModule/resources/queries/lists/Employees.js +++ b/modules/triggerTestModule/resources/queries/lists/Employees.js @@ -5,7 +5,15 @@ */ var shared = require("TriggerTestModule/EmployeeLib"); var console = require("console"); - + +function managedColumns() { + return { + insert: ["boomerang", "employeeId"], + update: ["boomerang", "company", "employeeId"], + ignored: ["notes"], + }; +} + function init(event, errors) { console.log("init got triggered with event: " + event); console.log(shared.sampleFunc("this is from the shared function")); @@ -13,27 +21,71 @@ function init(event, errors) { function beforeInsert(row, errors) { console.log("list: beforeInsert: row is: " + row); - if(row.name == "Emp 2") + if (row.name === "Emp 2") row.company = "Inserting Single"; - else if(row.name == "Emp 5") + else if (row.name === "Emp 5") row.company = "Importing TSV"; - else if(row.name == "Emp 6") + else if (row.name === "Emp 6") row.company = "API BeforeInsert"; + else if (row.name === "Managed Insert") + row.employeeId = "EMP-INS"; + else if (row.name === "Managed Struct") { + row.employeeId = "EMP-STRUCT"; + row.undeclaredCol = "bad"; + } + else if (row.name === "Managed Struct Remove") { + row.employeeId = "EMP-STRUCT-REM"; + delete row.SSN; + } + + if (!row.employeeId) { + row.employeeId = "EMP-INS1"; + } + + row.notes = "This is a note"; + + if (row.SSN !== "-123") { + row.boomeRANG = "Back at ya!"; + } console.log("list: edited row is: " + row); console.log(shared.sampleFunc("list: this is from the shared function")); } function beforeUpdate(row, oldRow, errors) { console.log("list: beforeUpdate: row is: " + row); - if(row.name == "Emp 3" || row.name == "Emp 8" ) + if (row.name === "Emp 3" || row.name === "Emp 8") row.company = "Before Update changed me"; + else if (row.name === "Managed Update") { + row.company = "Managed Co"; + row.employeeId = "EMP-UPD"; + } + else if (row.name === "Managed Struct") { + row.company = "Struct Co"; + row.employeeId = "EMP-STRUCT"; + row.undeclaredCol = "bad"; + } + else if (row.name === "Managed Struct Remove") { + row.company = "Struct Remove Co"; + row.employeeId = "EMP-STRUCT-REM"; + delete row.SSN; + } + + if (!row.employeeId) { + row.employeeId = "EMP-UPD1"; + } + + row.notes = "This is a note"; + + if (row.SSN !== "-123") { + row.boomeRANG = "Back at me!"; + } console.log("list: old row is: " + oldRow); console.log(shared.sampleFunc("list: this is from the shared function")); } function beforeDelete(row, errors) { console.log("list: beforeDelete: row is: " + row); - if(row.company == "Inserting Single" || row.company == "DeleteMe") + if (row.company === "Inserting Single" || row.company === "DeleteMe") errors[null] = "This is the Before Delete Error"; console.log(shared.sampleFunc("list: this is from the shared function")); @@ -42,7 +94,7 @@ function beforeDelete(row, errors) { function afterInsert(row, errors) { console.log("list: afterInsert: row is: " + row); - if(row.name == "Emp 1") + if (row.name === "Emp 1") errors[null] = "This is the After Insert Error"; console.log(shared.sampleFunc("list: this is from the shared function")); @@ -51,7 +103,7 @@ function afterInsert(row, errors) { function afterUpdate(row, oldRow, errors) { console.log("list: afterUpdate: row is: " + row); - if(row.name == "Emp 2" || row.name == "Emp 6" ) + if (row.name === "Emp 2" || row.name === "Emp 6" ) errors[null] = "This is the After Update Error"; //throw new Error("This is the After Update Error"); @@ -62,7 +114,7 @@ function afterUpdate(row, oldRow, errors) { function afterDelete(row, errors) { console.log("list: afterDelete: row is: " + row); - if(row.company == "Before Update changed me") + if (row.company === "Before Update changed me") errors[null] = "This is the After Delete Error"; console.log(shared.sampleFunc("list: this is from the shared function")); diff --git a/modules/triggerTestModule/resources/queries/samples/SampleTypeTest.js b/modules/triggerTestModule/resources/queries/samples/SampleTypeTest.js index 00f22dcb3a..dd8d5f8f38 100644 --- a/modules/triggerTestModule/resources/queries/samples/SampleTypeTest.js +++ b/modules/triggerTestModule/resources/queries/samples/SampleTypeTest.js @@ -6,6 +6,13 @@ var shared = require("TriggerTestModule/EmployeeLib"); var console = require("console"); +function managedColumns() { + return { + insert: ["Country"], + update: ["Country"], + }; +} + function init(event, errors) { console.log("init got triggered with event: " + event); console.log(shared.sampleFunc("this is from the shared function")); @@ -13,43 +20,76 @@ function init(event, errors) { function beforeInsert(row, errors) { console.log("samples: beforeInsert: row is: " + row); - if(row.Comments) { - if (row.Comments == "Individual Test") { - row.Country = "Inserting Single"; - row.Comments = "BeforeDelete"; //set this for next test step - } - else if (row.Comments == "Import Test") - row.Country = "Importing TSV"; - else if (row.Comments == "API Test") - row.Country = "API BeforeInsert"; + if (row.name === "Managed Insert") { + row.Country = "MANAGED-INS"; + } else if (row.name === "Managed Struct") { + row.Country = "MANAGED-STRUCT"; + row.undeclaredCol = "bad"; + } else if (row.name === "Managed Struct Remove") { + row.Country = "MANAGED-STRUCT-REM"; + delete row.Comments; + } + + if (row.name === "Managed Unhandled") { + delete row.Country; } else { - if (row.comments == "Individual Test") { - row.country = "Inserting Single"; - row.comments = "BeforeDelete"; //set this for next test step + if (row.Comments) { + if (row.Comments === "Individual Test") { + row.Country = "Inserting Single"; + row.Comments = "BeforeDelete"; + } + else if (row.Comments === "Import Test") + row.Country = "Importing TSV"; + else if (row.Comments === "API Test") + row.Country = "API BeforeInsert"; + } else { + if (row.Comments === "Individual Test") { + row.country = "Inserting Single"; + row.Comments = "BeforeDelete"; + } + else if (row.Comments === "Import Test") + row.country = "Importing TSV"; + else if (row.Comments === "API Test") + row.country = "API BeforeInsert"; } - else if (row.comments == "Import Test") - row.country = "Importing TSV"; - else if (row.comments == "API Test") - row.country = "API BeforeInsert"; + if (!row.Country) + row.Country = "ST-DEFAULT"; } - console.log("samples: edited row is: " + row); console.log(shared.sampleFunc("samples: this is from the shared function")); } function beforeUpdate(row, oldRow, errors) { console.log("samples: beforeUpdate: row is: " + row); - if(row.Comments == "BeforeUpdate") - row.Country = "Before Update changed me"; - else if(row.comments == "BeforeUpdate") - row.country = "Before Update changed me"; + if (row.Comments === "Managed Update") { + row.Country = "MANAGED-UPD"; + } else if (row.Comments === "Managed Struct") { + row.Country = "MANAGED-STRUCT"; + row.undeclaredCol = "bad"; + } else if (row.Comments === "Managed Struct Remove") { + row.Country = "MANAGED-STRUCT-REM"; + delete row.Comments; + } + + if (row.Comments === "Managed Unhandled") { + delete row.Country; + } else { + if (row.Comments === "BeforeUpdate") + row.Country = "Before Update changed me"; + else if (row.Comments === "BeforeUpdate") + row.country = "Before Update changed me"; + if (!row.Country) { + row.Country = "ST-DEFAULT-UPD"; + } + } + console.log("samples: old row is: " + oldRow); console.log(shared.sampleFunc("samples: this is from the shared function")); } function beforeDelete(row, errors) { console.log("samples: beforeDelete: row is: " + row); - if(row.Comments == "BeforeDelete" || row.comments == "BeforeDelete") + if (row.Comments === "BeforeDelete") errors[null] = "This is the Before Delete Error"; console.log(shared.sampleFunc("samples: this is from the shared function")); @@ -58,7 +98,7 @@ function beforeDelete(row, errors) { function afterInsert(row, errors) { console.log("samples: afterInsert: row is: " + row); - if(row.Comments == "AfterInsert" || row.comments == "AfterInsert") + if (row.Comments === "AfterInsert") errors[null] = "This is the After Insert Error"; console.log(shared.sampleFunc("samples: this is from the shared function")); @@ -67,7 +107,7 @@ function afterInsert(row, errors) { function afterUpdate(row, oldRow, errors) { console.log("samples: afterUpdate: row is: " + row); - if(row.Comments == "AfterUpdate" || row.comments == "AfterUpdate") + if (row.Comments === "AfterUpdate") errors[null] = "This is the After Update Error"; console.log("samples: old row is: " +oldRow); @@ -77,7 +117,7 @@ function afterUpdate(row, oldRow, errors) { function afterDelete(row, errors) { console.log("samples: afterDelete: row is: " + row); - if(row.Country == "Before Update changed me" || row.country == "Before Update changed me") + if (row.country === "Before Update changed me") errors[null] = "This is the After Delete Error"; console.log(shared.sampleFunc("samples: this is from the shared function")); diff --git a/modules/triggerTestModule/resources/queries/study/Demographics.js b/modules/triggerTestModule/resources/queries/study/Demographics.js index fbb39d073f..5239d75ee3 100644 --- a/modules/triggerTestModule/resources/queries/study/Demographics.js +++ b/modules/triggerTestModule/resources/queries/study/Demographics.js @@ -6,6 +6,13 @@ var shared = require("TriggerTestModule/EmployeeLib"); var console = require("console"); +function managedColumns() { + return { + insert: ["Country"], + update: ["Country"], + }; +} + function init(event, errors) { console.log("init got triggered with event: " + event); console.log(shared.sampleFunc("this is from the shared function")); @@ -13,42 +20,80 @@ function init(event, errors) { function beforeInsert(row, errors) { console.log("study: beforeInsert: row is: " + row); - if(row.Comments) { - if (row.Comments == "Individual Test") { - row.Country = "Inserting Single"; - row.Comments = "BeforeDelete"; //set this for next test step - } - else if (row.Comments == "Import Test") - row.Country = "Importing TSV"; - else if (row.Comments == "API Test") - row.Country = "API BeforeInsert"; + var comments = row.Comments; + if (comments === "Managed Insert") { + row.Country = "MANAGED-INS"; + } else if (comments === "Managed Struct") { + row.Country = "MANAGED-STRUCT"; + row.undeclaredCol = "bad"; + } else if (comments === "Managed Struct Remove") { + row.Country = "MANAGED-STRUCT-REM"; + delete row.Comments; + } + + if (comments === "Managed Unhandled") { + delete row.Country; } else { - if (row.comments == "Individual Test") { - row.country = "Inserting Single"; - row.comments = "BeforeDelete"; //set this for next test step + if (row.Comments) { + if (row.Comments === "Individual Test") { + row.Country = "Inserting Single"; + row.Comments = "BeforeDelete"; + } + else if (row.Comments === "Import Test") + row.Country = "Importing TSV"; + else if (row.Comments === "API Test") + row.Country = "API BeforeInsert"; + } else { + if (row.comments === "Individual Test") { + row.country = "Inserting Single"; + row.comments = "BeforeDelete"; + } + else if (row.comments === "Import Test") + row.country = "Importing TSV"; + else if (row.comments === "API Test") + row.country = "API BeforeInsert"; + } + if (!row.Country) { + row.Country = "STUDY-DEFAULT"; } - else if (row.comments == "Import Test") - row.country = "Importing TSV"; - else if (row.comments == "API Test") - row.country = "API BeforeInsert"; } + console.log("study: edited row is: " + row); console.log(shared.sampleFunc("study: this is from the shared function")); } function beforeUpdate(row, oldRow, errors) { console.log("study: beforeUpdate: row is: " + row); - if(row.Comments == "BeforeUpdate") - row.Country = "Before Update changed me"; - else if(row.comments == "BeforeUpdate") - row.country = "Before Update changed me"; + var comments = row.Comments || row.comments; + if (comments === "Managed Update") { + row.Country = "MANAGED-UPD"; + } else if (comments === "Managed Struct") { + row.Country = "MANAGED-STRUCT"; + row.undeclaredCol = "bad"; + } else if (comments === "Managed Struct Remove") { + row.Country = "MANAGED-STRUCT-REM"; + delete row.Comments; + delete row.comments; + } + + if (comments === "Managed Unhandled") { + delete row.Country; + } else { + if (row.Comments === "BeforeUpdate") + row.Country = "Before Update changed me"; + else if (row.comments === "BeforeUpdate") + row.country = "Before Update changed me"; + if (!row.Country && !row.country) + row.Country = "STUDY-DEFAULT-UPD"; + } + console.log("study: old row is: " + oldRow); console.log(shared.sampleFunc("study: this is from the shared function")); } function beforeDelete(row, errors) { console.log("study: beforeDelete: row is: " + row); - if(row.Comments == "BeforeDelete" || row.comments == "BeforeDelete") + if (row.Comments === "BeforeDelete" || row.comments === "BeforeDelete") errors[null] = "This is the Before Delete Error"; console.log(shared.sampleFunc("this is from the shared function")); @@ -57,7 +102,7 @@ function beforeDelete(row, errors) { function afterInsert(row, errors) { console.log("study: afterInsert: row is: " + row); - if(row.Comments == "AfterInsert" || row.comments == "AfterInsert") + if (row.Comments === "AfterInsert") errors[null] = "This is the After Insert Error"; console.log(shared.sampleFunc("study: this is from the shared function")); @@ -66,7 +111,7 @@ function afterInsert(row, errors) { function afterUpdate(row, oldRow, errors) { console.log("study: afterUpdate: row is: " + row); - if(row.Comments == "AfterUpdate" || row.comments == "AfterUpdate") + if (row.Comments === "AfterUpdate") errors[null] = "This is the After Update Error"; console.log("study: old row is: " +oldRow); @@ -76,7 +121,7 @@ function afterUpdate(row, oldRow, errors) { function afterDelete(row, errors) { console.log("study: afterDelete: row is: " + row); - if(row.Country == "Before Update changed me" || row.country == "Before Update changed me") + if (row.Country === "Before Update changed me") errors[null] = "This is the After Delete Error"; console.log(shared.sampleFunc("study: this is from the shared function")); diff --git a/src/org/labkey/test/tests/ScriptValidationTest.java b/src/org/labkey/test/tests/ScriptValidationTest.java index cb5e589d9b..ed28d05038 100644 --- a/src/org/labkey/test/tests/ScriptValidationTest.java +++ b/src/org/labkey/test/tests/ScriptValidationTest.java @@ -46,7 +46,6 @@ import org.labkey.test.util.query.QueryApiHelper; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; @@ -67,6 +66,7 @@ public class ScriptValidationTest extends BaseWebDriverTest public static final String MODULE_NAME = "simpletest"; public static final String VEHICLE_SCHEMA = "vehicle"; + public static final String COLORS_TABLE = "colors"; public static final String VEHICLES_TABLE = "vehicles"; public static class ColorRecord @@ -103,7 +103,7 @@ protected void doSetup() throws Exception _containerHelper.createProject(getProjectName(), null); _containerHelper.enableModule(getProjectName(), MODULE_NAME); new QueryApiHelper(createDefaultConnection(), getProjectName(), VEHICLE_SCHEMA, VEHICLES_TABLE).truncateTable(); - new QueryApiHelper(createDefaultConnection(), getProjectName(), VEHICLE_SCHEMA, "Colors").truncateTable(); + new QueryApiHelper(createDefaultConnection(), getProjectName(), VEHICLE_SCHEMA, COLORS_TABLE).truncateTable(); } @Test @@ -127,9 +127,7 @@ public void doTestCrossFolderSaveRows() throws Exception { Connection cn = createDefaultConnection(); - List colors = insertColors(Arrays.asList( - new ColorRecord("Yellow2", "#f00") - )); + List colors = insertColors(List.of(new ColorRecord("Yellow2", "#f00"))); // Create manufacturers: ArrayList> list1 = new ArrayList<>(); @@ -156,8 +154,8 @@ public void doTestCrossFolderSaveRows() throws Exception assertNotNull("RowId not returned for vehicles insert, keys found: " + StringUtils.join(row.keySet(), ","), vehicleRowId); SelectRowsCommand src = new SelectRowsCommand(VEHICLE_SCHEMA, VEHICLES_TABLE); - src.setColumns(Arrays.asList("Container", "TriggerScriptContainer", "RowId", "ModelId", "Milage")); - src.setSorts(Arrays.asList(new Sort("RowId", Sort.Direction.DESCENDING))); + src.setColumns(List.of("Container", "TriggerScriptContainer", "RowId", "ModelId", "Milage")); + src.setSorts(List.of(new Sort("RowId", Sort.Direction.DESCENDING))); SelectRowsResponse sr2 = src.execute(cn, getProjectName()); assertEquals("Incorrect model", modelId, sr2.getRows().get(0).get("ModelId")); assertEquals("Incorrect Milage", 1234, sr2.getRows().get(0).get("Milage")); @@ -224,7 +222,7 @@ private PostCommand prepareSaveRowsCommand(String command, Stri private void doTestTransformation() throws Exception { - List inserted = insertColors(Arrays.asList( + List inserted = insertColors(List.of( new ColorRecord("Yellow", "#f00"), new ColorRecord("Cyan", "#0f0") )); @@ -247,7 +245,7 @@ private void doTestValidation() throws Exception /* The following exception is logged to the server as it is meant to simulate an unexpected error in * script validation */ log("** Test errors: throw Error()'"); - insertColors(Arrays.asList(new ColorRecord("ShouldError", "not a hex value"))); + insertColors(List.of(new ColorRecord("ShouldError", "not a hex value"))); fail("Should throw an exception"); } catch (CommandException e) @@ -259,7 +257,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: Field='message' and test extraContext is echoed back"); - insertColors(Arrays.asList(new ColorRecord("TestFieldErrorMessage", null)), Maps.of("A", "a", "B", 3)); + insertColors(List.of(new ColorRecord("TestFieldErrorMessage", null)), Maps.of("A", "a", "B", 3)); fail("Should throw an exception"); } catch (CommandException e) @@ -298,7 +296,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: Field=[array of messages]"); - insertColors(Arrays.asList(new ColorRecord("TestFieldErrorArray", null))); + insertColors(List.of(new ColorRecord("TestFieldErrorArray", null))); fail("Should throw an exception"); } catch (CommandException e) @@ -333,7 +331,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: row level error"); - insertColors(Arrays.asList(new ColorRecord("TestRowError", null))); + insertColors(List.of(new ColorRecord("TestRowError", null))); fail("Should throw an exception"); } catch (CommandException e) @@ -366,7 +364,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: returning false"); - insertColors(Arrays.asList(new ColorRecord("TestReturnFalse", ""))); + insertColors(List.of(new ColorRecord("TestReturnFalse", ""))); fail("Should throw an exception"); } catch (CommandException e) @@ -402,7 +400,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: error in complete"); - insertColors(Arrays.asList( + insertColors(List.of( new ColorRecord("Yellow", "#f00"), new ColorRecord("Cyan", "#0f0"), new ColorRecord("TestErrorInComplete", "") @@ -438,7 +436,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: adding array of errors in complete"); - insertColors(Arrays.asList(new ColorRecord("TestFieldErrorArrayInComplete", ""))); + insertColors(List.of(new ColorRecord("TestFieldErrorArrayInComplete", ""))); fail("Should throw an exception"); } catch (CommandException e) @@ -485,7 +483,7 @@ private void doTestValidation() throws Exception try { log("** Test errors: script level variables, color regular expression"); - insertColors(Arrays.asList(new ColorRecord("ShouldError", "#still not a hex value"))); + insertColors(List.of(new ColorRecord("ShouldError", "#still not a hex value"))); fail("Should throw an exception"); } catch (CommandException e) @@ -498,7 +496,7 @@ private void doTestValidation() throws Exception log("** Test errors: updating hex value"); ColorRecord yellow = selectColor("Yellow?").get(0); yellow.hex = "shouldn't happen"; - updateColors(Arrays.asList(yellow)); + updateColors(List.of(yellow)); fail("Should throw an exception"); } catch (CommandException e) @@ -512,7 +510,7 @@ private List selectColor(String... names) throws Exception log("** Selecting colors..."); Connection cn = createDefaultConnection(); - SelectRowsCommand cmd = new SelectRowsCommand(VEHICLE_SCHEMA, "Colors"); + SelectRowsCommand cmd = new SelectRowsCommand(VEHICLE_SCHEMA, COLORS_TABLE); cmd.addFilter("Name", StringUtils.join(names, ";"), Filter.Operator.IN); SelectRowsResponse response = cmd.execute(cn, getProjectName()); assertEquals("Expected to select " + names.length + " rows.", names.length, response.getRowCount().intValue()); @@ -536,7 +534,7 @@ private List insertColors(List colors, Map updateColors(List colors, Map updateColors(List colors, Map getAssociatedModules() { - return Arrays.asList("simpletest"); + return List.of(MODULE_NAME); } @Override diff --git a/src/org/labkey/test/tests/TriggerScriptTest.java b/src/org/labkey/test/tests/TriggerScriptTest.java index cc89fd6093..6d34809e98 100644 --- a/src/org/labkey/test/tests/TriggerScriptTest.java +++ b/src/org/labkey/test/tests/TriggerScriptTest.java @@ -24,11 +24,13 @@ import org.junit.experimental.categories.Category; import org.labkey.remoteapi.CommandException; import org.labkey.remoteapi.Connection; +import org.labkey.remoteapi.collections.CaseInsensitiveHashMap; import org.labkey.remoteapi.query.DeleteRowsCommand; import org.labkey.remoteapi.query.InsertRowsCommand; import org.labkey.remoteapi.query.BaseRowsCommand; import org.labkey.remoteapi.query.MoveRowsCommand; import org.labkey.remoteapi.query.RowsResponse; +import org.labkey.remoteapi.query.TruncateTableCommand; import org.labkey.remoteapi.query.UpdateRowsCommand; import org.labkey.test.BaseWebDriverTest; import org.labkey.test.Locator; @@ -59,7 +61,7 @@ import java.util.Map; /** - * Test trigger script matrix, expands on ScriptValidationTest which covers custom schemas (Vehicles) + * Test trigger script matrix, expands on {@link ScriptValidationTest} which covers custom schemas (Vehicles) */ @Category({Daily.class, Data.class}) @BaseWebDriverTest.ClassTimeout(minutes = 8) @@ -80,6 +82,9 @@ public class TriggerScriptTest extends BaseWebDriverTest private static final String BEFORE_DELETE_ERROR = "This is the Before Delete Error"; private static final String AFTER_DELETE_ERROR = "This is the After Delete Error"; + private static final String MANAGED_STRUCT_ADD_ERROR = "attempted to add"; + private static final String MANAGED_STRUCT_REMOVE_ERROR = "attempted to remove"; + //Dataset constants private static final String STUDY_SCHEMA = "study"; private static final String DATASET_NAME = "Demographics"; @@ -121,7 +126,7 @@ public BrowserType bestBrowser() public static class EmployeeRecord { - public String name, ssn, company; + public String name, ssn, company, employeeId; public Integer key; public EmployeeRecord(String name, String ssn, String company) @@ -139,7 +144,7 @@ public EmployeeRecord(String name, String ssn, String company, Integer key) public Map toMap() { - return Maps.of("Name", name, "SSN", ssn, "Company", company, "Key", key); + return Maps.of("Name", name, "SSN", ssn, "Company", company, "Key", key, "employeeId", employeeId); } public Map toStringMap() @@ -149,7 +154,7 @@ public Map toStringMap() public String toDelimitedString(String delimiter) { - return name + delimiter + ssn + delimiter + company + "\n"; + return name + delimiter + ssn + delimiter + company + delimiter + (employeeId != null ? employeeId : "") + "\n"; } public static EmployeeRecord fromMap(Map map) @@ -157,13 +162,15 @@ public static EmployeeRecord fromMap(Map map) EmployeeRecord newbie = new EmployeeRecord((String)map.get("Name"), (String)map.get("ssn"), (String)map.get("Company")); if (map.containsKey("Key")) newbie.key = (Integer)map.get("Key"); + if (map.containsKey("employeeId")) + newbie.employeeId = (String)map.get("employeeId"); return newbie; } public static String getTsvHeaders() { - return "Name\tSSN\tCompany\n"; + return "Name\tSSN\tCompany\tEmployeeId\n"; } } @@ -186,23 +193,34 @@ protected void doSetup() throws Exception { _containerHelper.createProject(getProjectName(), null); _containerHelper.createSubfolder(getProjectName(), SUBFOLDER_NAME); - _containerHelper.enableModule(getProjectName(), "Query"); - _containerHelper.enableModule(getProjectName(), SIMPLE_MODULE); - _containerHelper.enableModule(getProjectName(), TRIGGER_MODULE); + _containerHelper.enableModules(getProjectName(), List.of("Query", SIMPLE_MODULE, TRIGGER_MODULE)); + + // Create a data class + new DataClassDefinition(DATA_CLASSES_NAME) + .setFields(List.of(new FieldDefinition(COMMENTS_FIELD), new FieldDefinition(COUNTRY_FIELD))) + .create(createDefaultConnection(), getProjectName()); + + // Create a sample type + SampleTypeAPIHelper.createEmptySampleType(getProjectName(), new SampleTypeDefinition(SAMPLE_TYPE_NAME) + .setFields(List.of(new FieldDefinition(COMMENTS_FIELD), new FieldDefinition(COUNTRY_FIELD)))); // Create lists { List fields = List.of( - new FieldDefinition("name", ColumnType.String).setLabel("Name"), - new FieldDefinition("ssn", ColumnType.String).setLabel("SSN"), - new FieldDefinition("company", ColumnType.String).setLabel("Company") + new FieldDefinition("name").setLabel("Name"), + new FieldDefinition("ssn").setLabel("SSN"), + new FieldDefinition("company").setLabel("Company"), + new FieldDefinition("employeeId").setLabel("Employee ID") + .setHidden(true) + .setShownInInsertView(false) + .setShownInUpdateView(false) ); EMPLOYEE_LIST = new IntListDefinition(LIST_NAME, "Key").setFields(fields); EMPLOYEE_LIST.create(createDefaultConnection(), getProjectName()); fields = List.of( - new FieldDefinition("Name", ColumnType.String).setDescription("Name"), + new FieldDefinition("Name").setDescription("Name"), new FieldDefinition("Age", ColumnType.Integer).setDescription("Age"), new FieldDefinition("FavoriteDateTime", ColumnType.DateAndTime).setDescription("Favorite date time. Who doesn't have one?"), new FieldDefinition("Crazy", ColumnType.Boolean).setDescription("Crazy?") @@ -213,6 +231,7 @@ protected void doSetup() throws Exception .create(createDefaultConnection(), getProjectName()); } + // Create dataset via import importFolderFromZip(TestFileUtils.getSampleData("studies/LabkeyDemoStudy.zip")); //Add webparts for dataset, data class, sample type setup @@ -334,13 +353,78 @@ public void testListMoveTriggers() throws Exception openServerJavaScriptConsole(); MoveRowsCommand command = new MoveRowsCommand(SUBFOLDER_PATH, LIST_SCHEMA, LIST_NAME); - command.setRows(List.of(Map.of("Key", records.get(0).key))); + command.setRows(List.of(Map.of("Key", records.getFirst().key))); command.execute(createDefaultConnection(), getProjectName()); waitForConsole("init got triggered with event: move", "complete got triggered with event: move"); closeServerJavaScriptConsole(); } + @Test + public void testListManagedColumnsTriggers() throws Exception + { + cleanUpListRows(); + Connection cn = WebTestHelper.getRemoteApiConnection(); + + // Insert: declared managed column not set by trigger + // "boomerang" is absent from the payload; trigger has no handler for this name and never sets it + InsertRowsCommand insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME); + insCmd.addRow(Map.of("Name", "Unhandled Name", "SSN", "-123", "Company", "Test Co")); + assertAPIErrorMessage(insCmd, "declared the managed column 'boomerang'", cn); + + // Insert: trigger sets the declared managed column "employeeId" + insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME); + insCmd.addRow(Map.of("Name", "Managed Insert", "SSN", "111222334", "Company", "Test Co")); + RowsResponse resp = insCmd.execute(cn, getProjectName()); + EmployeeRecord inserted = EmployeeRecord.fromMap(resp.getRows().getFirst()); + Assert.assertEquals("Trigger should have set employeeId", "EMP-INS", inserted.employeeId); + + // Insert: structural add error — trigger adds a column not declared as managed + insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME); + insCmd.addRow(Map.of("Name", "Managed Struct", "SSN", "111222335", "Company", "Test Co")); + assertAPIErrorMessage(insCmd, MANAGED_STRUCT_ADD_ERROR, cn); + + // Insert: structural remove error — trigger deletes a column not declared as managed + insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME); + insCmd.addRow(Map.of("Name", "Managed Struct Remove", "SSN", "111222336", "Company", "Test Co")); + assertAPIErrorMessage(insCmd, MANAGED_STRUCT_REMOVE_ERROR, cn); + + // Setup: insert rows for update tests; include "employeeId" in payload so insert validation passes + insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME); + insCmd.addRow(Map.of("Name", "MC Update Setup", "SSN", "111222340", "Company", "Setup Co", "employeeId", "OLD-ID")); + insCmd.addRow(Map.of("Name", "MC Struct Setup", "SSN", "111222341", "Company", "Setup Co", "employeeId", "OLD-ID-2")); + insCmd.addRow(Map.of("Name", "MC Struct Remove Setup", "SSN", "111222342", "Company", "Setup Co", "employeeId", "OLD-ID-3")); + resp = insCmd.execute(cn, getProjectName()); + Integer updateKey = (Integer) resp.getRows().getFirst().get("Key"); + Integer structKey = (Integer) resp.getRows().get(1).get("Key"); + Integer structRemoveKey = (Integer) resp.getRows().get(2).get("Key"); + + // Update: trigger sets both declared managed columns "company" and "employeeId" + UpdateRowsCommand updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME); + updCmd.addRow(Map.of("Key", updateKey, "Name", "Managed Update", "SSN", "111222340")); + resp = updCmd.execute(cn, getProjectName()); + EmployeeRecord updated = EmployeeRecord.fromMap(resp.getRows().getFirst()); + Assert.assertEquals("Trigger should have set company", "Managed Co", updated.company); + Assert.assertEquals("Trigger should have set employeeId", "EMP-UPD", updated.employeeId); + + // Update: declared managed column not set by trigger + // "boomerang" is absent from the payload; SSN="-123" causes the trigger to skip setting it + // Name is explicitly provided so the trigger does not accidentally match a named handler + updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME); + updCmd.addRow(Map.of("Key", updateKey, "Name", "MC Update Setup", "SSN", "-123", "Company", "Test Co")); + assertAPIErrorMessage(updCmd, "declared the managed column 'boomerang'", cn); + + // Update: structural add error — trigger adds a column not declared as managed + updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME); + updCmd.addRow(Map.of("Key", structKey, "Name", "Managed Struct", "SSN", "111222341")); + assertAPIErrorMessage(updCmd, MANAGED_STRUCT_ADD_ERROR, cn); + + // Update: structural remove error — trigger deletes a column not declared as managed + updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME); + updCmd.addRow(Map.of("Key", structRemoveKey, "Name", "Managed Struct Remove", "SSN", "111222342")); + assertAPIErrorMessage(updCmd, MANAGED_STRUCT_REMOVE_ERROR, cn); + } + /** Issue 52098 - ensure trigger scripts have a chance to do custom type conversion with the incoming row */ @Test public void testListAPITriggerTypeConversion() throws Exception @@ -355,7 +439,7 @@ public void testListAPITriggerTypeConversion() throws Exception List> insertedRows = insResp.getRows(); Assert.assertEquals(1, insertedRows.size()); - Map insertedRow = insertedRows.get(0); + Map insertedRow = insertedRows.getFirst(); Assert.assertEquals("Jimbo", insertedRow.get("Name")); Assert.assertEquals(25, insertedRow.get("Age")); Assert.assertEquals("2025-06-11 11:42:00.000", insertedRow.get("FavoriteDateTime")); @@ -368,7 +452,7 @@ public void testListAPITriggerTypeConversion() throws Exception List> updatedRows = upResp.getRows(); Assert.assertEquals(1, updatedRows.size()); - Map updatedRow = updatedRows.get(0); + Map updatedRow = updatedRows.getFirst(); Assert.assertEquals(26, updatedRow.get("Age")); } @@ -405,7 +489,7 @@ public void testListAPITriggers() throws Exception insCmd.addRow(row2.toMap()); insCmd.addRow(row3.toMap()); resp = insCmd.execute(cn, getProjectName()); - row2 = EmployeeRecord.fromMap(resp.getRows().get(0)); + row2 = EmployeeRecord.fromMap(resp.getRows().getFirst()); Assert.assertEquals("API BeforeInsert", row2.company); row3 = EmployeeRecord.fromMap(resp.getRows().get(1)); @@ -427,7 +511,7 @@ public void testListAPITriggers() throws Exception updCmd.addRow(row2.toMap()); updCmd.addRow(row3.toMap()); resp = updCmd.execute(cn, getProjectName()); - EmployeeRecord updateCo = EmployeeRecord.fromMap(resp.getRows().get(0)); + EmployeeRecord updateCo = EmployeeRecord.fromMap(resp.getRows().getFirst()); Assert.assertEquals(BEFORE_UPDATE_COMPANY, updateCo.company); //Check update persisted Assert.assertEquals(ssn1, updateCo.ssn); @@ -447,10 +531,6 @@ public void testListAPITriggers() throws Exception assertAPIErrorMessage(delCmd, BEFORE_DELETE_ERROR, cn); } - /******************************** - * Dataset Trigger Script Tests - ********************************/ - @Test public void testDatasetIndividualTriggers() { @@ -508,17 +588,14 @@ public void testDatasetAPITriggers() throws Exception doAPITriggerTest(STUDY_SCHEMA, DATASET_NAME, "ParticipantId", true); } - /******************************** - * Data Class Trigger Script Tests - ********************************/ - @Test public void testDataClassIndividualTriggers() throws Exception { + cleanUpTableRows(DATA_CLASSES_SCHEMA, DATA_CLASSES_NAME); + //Generate delegate to move to data class UI GoToDataUI goToDataClass = () -> goTo("Data Classes", DATA_CLASSES_NAME); - setupDataClass(); openServerJavaScriptConsole(); doIndividualTriggerTest("query", goToDataClass, "Name", false, "Yes, Delete", false); @@ -529,36 +606,172 @@ public void testDataClassIndividualTriggers() throws Exception closeServerJavaScriptConsole(); } - @Test public void testDataClassAPITriggers() throws Exception { - setupDataClass(); + cleanUpTableRows(DATA_CLASSES_SCHEMA, DATA_CLASSES_NAME); doAPITriggerTest(DATA_CLASSES_SCHEMA, DATA_CLASSES_NAME, "Name", false); } - /******************************** - * Sample Type Trigger Script Tests - ********************************/ - @Test public void testSampleTypeIndividualTriggers() throws Exception { + cleanUpTableRows(SAMPLE_TYPE_SCHEMA, SAMPLE_TYPE_NAME); + //Generate delegate to move to sample type UI GoToDataUI goToSampleType = () -> goTo("Sample Types", SAMPLE_TYPE_NAME); - setupSampleType(); doIndividualTriggerTest("Material", goToSampleType, "Name", false, "Yes, Delete", false); } - @Test public void testSampleTypeAPITriggers() throws Exception { - setupSampleType(); + cleanUpTableRows(SAMPLE_TYPE_SCHEMA, SAMPLE_TYPE_NAME); doAPITriggerTest(SAMPLE_TYPE_SCHEMA, SAMPLE_TYPE_NAME, "Name", false); } + @Test + public void testDataClassManagedColumnsTriggers() throws Exception + { + cleanUpTableRows(DATA_CLASSES_SCHEMA, DATA_CLASSES_NAME); + doManagedColumnsTriggerTest(DATA_CLASSES_SCHEMA, DATA_CLASSES_NAME, "Name", false, "Name"); + } + + @Test + public void testSampleTypeManagedColumnsTriggers() throws Exception + { + cleanUpTableRows(SAMPLE_TYPE_SCHEMA, SAMPLE_TYPE_NAME); + doManagedColumnsTriggerTest(SAMPLE_TYPE_SCHEMA, SAMPLE_TYPE_NAME, "Name", false, "Name"); + } + + @Test + public void testDatasetManagedColumnsTriggers() throws Exception + { + doManagedColumnsTriggerTest(STUDY_SCHEMA, DATASET_NAME, "ParticipantId", true, COMMENTS_FIELD); + } + + /** + * Shared test of managed columns trigger behavior across data types. + * Verifies that the framework enforces managed column declarations and detects structural violations. + * + * @param schemaName Schema containing the query + * @param queryName Query/table name + * @param keyColumnName Primary key column ("Name" for DC/ST, "ParticipantId" for Dataset) + * @param requiresDate Whether rows require a "Date" field (datasets) + * @param insertDispatchField Field that routes managed-column behavior in beforeInsert; + * equals keyColumnName for DC/ST, COMMENTS_FIELD for Dataset + */ + private void doManagedColumnsTriggerTest(String schemaName, String queryName, String keyColumnName, + boolean requiresDate, String insertDispatchField) throws Exception + { + Connection cn = WebTestHelper.getRemoteApiConnection(); + boolean dispatchIsKey = insertDispatchField.equals(keyColumnName); + + // Insert: declared managed column not set by trigger → error + InsertRowsCommand insCmd = new InsertRowsCommand(schemaName, queryName); + insCmd.addRow(makeInsertRow(keyColumnName, requiresDate, dispatchIsKey, insertDispatchField, + "Managed Unhandled", "MC-UN-001")); + assertAPIErrorMessage(insCmd, "declared the managed column", cn); + + // Insert: trigger sets managed column → success + insCmd = new InsertRowsCommand(schemaName, queryName); + insCmd.addRow(makeInsertRow(keyColumnName, requiresDate, dispatchIsKey, insertDispatchField, + "Managed Insert", "MC-IN-001")); + RowsResponse resp = insCmd.execute(cn, getProjectName()); + Assert.assertEquals("Trigger should have set " + COUNTRY_FIELD, "MANAGED-INS", + resp.getRows().getFirst().get(COUNTRY_FIELD)); + + // Insert: structural add error — trigger adds undeclared column → error + insCmd = new InsertRowsCommand(schemaName, queryName); + insCmd.addRow(makeInsertRow(keyColumnName, requiresDate, dispatchIsKey, insertDispatchField, + "Managed Struct", "MC-ST-001")); + assertAPIErrorMessage(insCmd, MANAGED_STRUCT_ADD_ERROR, cn); + + // Insert: structural remove error — trigger deletes column → error + insCmd = new InsertRowsCommand(schemaName, queryName); + insCmd.addRow(makeInsertRow(keyColumnName, requiresDate, dispatchIsKey, insertDispatchField, + "Managed Struct Remove", "MC-SR-001")); + assertAPIErrorMessage(insCmd, MANAGED_STRUCT_REMOVE_ERROR, cn); + + // Setup: insert rows for update tests with neutral Comments so the trigger fallback fires + InsertRowsCommand setupCmd = new InsertRowsCommand(schemaName, queryName); + setupCmd.addRow(makeSetupRow(keyColumnName, requiresDate, dispatchIsKey, "MC Update Setup", "MC-UPD-001")); + setupCmd.addRow(makeSetupRow(keyColumnName, requiresDate, dispatchIsKey, "MC Struct Setup", "MC-STR-001")); + setupCmd.addRow(makeSetupRow(keyColumnName, requiresDate, dispatchIsKey, "MC Struct Remove Setup", "MC-SRR-001")); + RowsResponse setupResp = setupCmd.execute(cn, getProjectName()); + Map updRow = new CaseInsensitiveHashMap<>(setupResp.getRows().getFirst()); + Map strRow = new CaseInsensitiveHashMap<>(setupResp.getRows().get(1)); + Map srrRow = new CaseInsensitiveHashMap<>(setupResp.getRows().get(2)); + + // Update: trigger sets managed column → success + UpdateRowsCommand updCmd = new UpdateRowsCommand(schemaName, queryName); + updRow.put(COMMENTS_FIELD, "Managed Update"); + updCmd.addRow(updRow); + resp = updCmd.execute(cn, getProjectName()); + Assert.assertEquals("Trigger should have set " + COUNTRY_FIELD, "MANAGED-UPD", + resp.getRows().getFirst().get(COUNTRY_FIELD)); + + // Update: declared managed column not set by trigger → error + updCmd = new UpdateRowsCommand(schemaName, queryName); + updRow.put(COMMENTS_FIELD, "Managed Unhandled"); + updCmd.addRow(updRow); + assertAPIErrorMessage(updCmd, "declared the managed column", cn); + + // Update: structural add error — trigger adds undeclared column → error + updCmd = new UpdateRowsCommand(schemaName, queryName); + strRow.put(COMMENTS_FIELD, "Managed Struct"); + updCmd.addRow(strRow); + assertAPIErrorMessage(updCmd, MANAGED_STRUCT_ADD_ERROR, cn); + + // Update: structural remove error — trigger deletes column → error + updCmd = new UpdateRowsCommand(schemaName, queryName); + srrRow.put(COMMENTS_FIELD, "Managed Struct Remove"); + updCmd.addRow(srrRow); + assertAPIErrorMessage(updCmd, MANAGED_STRUCT_REMOVE_ERROR, cn); + } + + /** + * Builds an insert row for the managed column trigger test. + * When dispatchIsKey, the dispatch value goes in the key column (DC/ST); otherwise it goes in + * the separate dispatch field (Dataset) and a generated unique value is used for the key. + */ + private Map makeInsertRow(String keyColumnName, boolean requiresDate, boolean dispatchIsKey, String dispatchField, String dispatchValue, String uniqueKey) + { + Map row = new HashMap<>(); + if (dispatchIsKey) + { + row.put(keyColumnName, dispatchValue); + row.put(COMMENTS_FIELD, "managed-test"); // ensure Comments exists for struct-remove test + } + else + { + row.put(keyColumnName, uniqueKey); + row.put(dispatchField, dispatchValue); + } + if (requiresDate) + row.put("Date", new Date()); + return row; + } + + /** + * Builds a neutral setup row for update-phase tests; trigger fallback fires for these rows. + */ + private Map makeSetupRow(String keyColumnName, boolean requiresDate, boolean dispatchIsKey, String nameValue, String uniqueKey) + { + Map row = new HashMap<>(); + row.put(keyColumnName, dispatchIsKey ? nameValue : uniqueKey); + row.put(COMMENTS_FIELD, "setup"); + if (requiresDate) + row.put("Date", new Date()); + return row; + } + + private void cleanUpTableRows(String schemaName, String queryName) throws Exception + { + new TruncateTableCommand(schemaName, queryName).execute(createDefaultConnection(), getProjectName()); + } + /** * Run an api test against a schema and query based on preset trigger script * @param keyColumnName Name of key column @@ -610,7 +823,7 @@ private void doAPITriggerTest(String schemaName, String queryName, String keyCol insCmd.addRow(row2); insCmd.addRow(row3); RowsResponse resp = insCmd.execute(cn, getProjectName()); - row2 = resp.getRows().get(0); + row2 = resp.getRows().getFirst(); Assert.assertEquals("API BeforeInsert", row2.get(COUNTRY_FIELD)); SearchAdminAPIHelper.waitForIndexer(); @@ -627,7 +840,7 @@ private void doAPITriggerTest(String schemaName, String queryName, String keyCol updCmd.addRow(row2); updCmd.addRow(row3); resp = updCmd.execute(cn, getProjectName()); - Map updateCo = resp.getRows().get(0); + Map updateCo = resp.getRows().getFirst(); Assert.assertEquals(BEFORE_UPDATE_COMPANY, updateCo.get(updateField)); //Check update persisted Assert.assertEquals("BeforeUpdate", updateCo.get(flagField)); @@ -879,41 +1092,6 @@ private String joinMapKeys(Map data, String delimiter) return sb.toString().trim(); } - /** - * Setup the data class - */ - private void setupDataClass() throws CommandException, IOException - { - //Setup Data Class - goToProjectHome(); - DataRegionTable drt = DataRegionTable.findDataRegionWithinWebpart(this, "Data Classes"); - int rowId = drt.getRowIndex("Name", DATA_CLASSES_NAME); - if (rowId >= 0) - { - drt.checkCheckbox(rowId); - drt.clickHeaderButtonAndWait("Delete"); - clickButton("Confirm Delete"); - } - - DataClassDefinition dataClass = new DataClassDefinition(DATA_CLASSES_NAME) - .setFields(List.of( - new FieldDefinition(COMMENTS_FIELD, ColumnType.String), - new FieldDefinition(COUNTRY_FIELD, ColumnType.String))); - dataClass.create(createDefaultConnection(), getProjectName()); - } - - /** - * Setup the sample type - */ - private void setupSampleType() - { - SampleTypeDefinition sampleType = new SampleTypeDefinition(SAMPLE_TYPE_NAME) - .setFields(List.of( - new FieldDefinition(COMMENTS_FIELD, ColumnType.String), - new FieldDefinition(COUNTRY_FIELD, ColumnType.String))); - SampleTypeAPIHelper.createEmptySampleType(getProjectName(), sampleType); - } - private void closeServerJavaScriptConsole() { switchToWindow(1);