From 99c94b36ba8a27e25ee20be10038cfc8b78f8b97 Mon Sep 17 00:00:00 2001 From: Alexander Kell Date: Sun, 26 May 2024 17:33:09 +0700 Subject: [PATCH] extend script demo based on user request ... with focus of using java classes in my js functions --- .../resources/demo/script/scriptdb2.ben.xml | 47 +++++++++++++++++++ .../engine/DemoIntegrationNoExtDBTest.java | 11 +++++ 2 files changed, 58 insertions(+) create mode 100644 src/demo/resources/demo/script/scriptdb2.ben.xml diff --git a/src/demo/resources/demo/script/scriptdb2.ben.xml b/src/demo/resources/demo/script/scriptdb2.ben.xml new file mode 100644 index 00000000..05dbcc98 --- /dev/null +++ b/src/demo/resources/demo/script/scriptdb2.ben.xml @@ -0,0 +1,47 @@ + + + + + + define a database that will be referred by the id 'db' subsequently + + + + + + + DROP TABLE IF EXISTS db_user; + + + + CREATE TABLE db_user ( + id int NOT NULL, + name varchar(16) NOT NULL, + PRIMARY KEY (id) + ); + + + + + print('DB-URL: ' + db.getUrl()); + + Entity = Java.type('com.rapiddweller.model.data.Entity'); + + // Create 1000 users using a loop + for (var i = 1; i <= 1000; i++) { + var user = new Entity('db_user', context.getLocalDescriptorProvider()); + user.set('id', i); + user.set('name', 'User' + i); + db.store(user); + } + + // Persist everything + db.flush(); + + print('Created 1000 users successfully.'); + + + Printing generated data + + \ No newline at end of file diff --git a/src/test/java/com/rapiddweller/benerator/engine/DemoIntegrationNoExtDBTest.java b/src/test/java/com/rapiddweller/benerator/engine/DemoIntegrationNoExtDBTest.java index 4e0e0b82..17f8eba7 100644 --- a/src/test/java/com/rapiddweller/benerator/engine/DemoIntegrationNoExtDBTest.java +++ b/src/test/java/com/rapiddweller/benerator/engine/DemoIntegrationNoExtDBTest.java @@ -246,6 +246,17 @@ public void demoScriptDb() { } + /** + * Demo script db. + */ + @Test + public void demoScriptDb2() { + context.setContextUri("/demo/script"); + BeneratorContext benCtx = parseAndExecuteFile("/demo/script/scriptdb2.ben.xml"); + Assert.assertEquals("/demo/script", benCtx.getContextUri()); + + } + /** * Demo script code. */