From 01cc59e74f3ad1fd03cb36ab6ec5640e01614c30 Mon Sep 17 00:00:00 2001 From: Jacob Beers Date: Thu, 11 Apr 2024 11:47:27 -0500 Subject: [PATCH] Sketch out some tests and boxlang bifs --- .../bx/{ModuleConfig.bx => ModuleConfig.cfc} | 8 +-- src/main/bx/bifs/ExampleBxBif.bx | 4 +- src/main/bx/bifs/ORMTestBIF.bx | 33 ++++++++++++ .../com/ortussolutions/bifs/ORMFlush.java | 21 ++++++++ .../com/ortussolutions/bifs/ORMFlushTest.java | 51 +++++++++++++++++++ src/test/resources/boxlang.json | 49 ++++++++++++++++++ 6 files changed, 160 insertions(+), 6 deletions(-) rename src/main/bx/{ModuleConfig.bx => ModuleConfig.cfc} (96%) create mode 100644 src/main/bx/bifs/ORMTestBIF.bx create mode 100644 src/main/java/com/ortussolutions/bifs/ORMFlush.java create mode 100644 src/test/java/com/ortussolutions/bifs/ORMFlushTest.java create mode 100644 src/test/resources/boxlang.json diff --git a/src/main/bx/ModuleConfig.bx b/src/main/bx/ModuleConfig.cfc similarity index 96% rename from src/main/bx/ModuleConfig.bx rename to src/main/bx/ModuleConfig.cfc index f28a6f9..06755d9 100644 --- a/src/main/bx/ModuleConfig.bx +++ b/src/main/bx/ModuleConfig.cfc @@ -102,10 +102,10 @@ */ interceptors = [ // { class="path.to.Interceptor", properties={} } - { class : "#moduleRecord.invocationPath#.interceptors.Listener", properties : { - createdOn : now(), - by : "Luis Majano" - } } + // { class : "#moduleRecord.invocationPath#.interceptors.Listener", properties : { + // createdOn : now(), + // by : "Luis Majano" + // } } ]; /** diff --git a/src/main/bx/bifs/ExampleBxBif.bx b/src/main/bx/bifs/ExampleBxBif.bx index a7d465f..5dc2282 100644 --- a/src/main/bx/bifs/ExampleBxBif.bx +++ b/src/main/bx/bifs/ExampleBxBif.bx @@ -17,8 +17,8 @@ * - interceptorService : The BoxLang InterceptorService * - moduleRecord : The ModuleRecord instance */ -@BoxBIF "ExampleBxBIF" -component { +// @BoxBIF "ExampleBxBIF" +class { /** * An example BOXLANG BIF diff --git a/src/main/bx/bifs/ORMTestBIF.bx b/src/main/bx/bifs/ORMTestBIF.bx new file mode 100644 index 0000000..2bd51cc --- /dev/null +++ b/src/main/bx/bifs/ORMTestBIF.bx @@ -0,0 +1,33 @@ +/** + * This is a BOXLANG BIF + * + * Annotations you can use on a BIF: + *
+ * // The alias of the BIF, defaults to the name of the Class
+ * @BoxBIF 'myBifAlias'
+ * @BoxBIF [ 'myBifAlias', 'myOtherBifAlias' ]
+ * @BoxMember 'string'
+ * @BoxMember { 'string' : { name : '', objectArgument : '' }, 'array' : { name : '', objectArgument : '' } }
+ * 
+ * + * The runtime injects the following into the `variables` scope: + * - boxRuntime : BoxLangRuntime + * - log : A logger + * - functionService : The BoxLang FunctionService + * - interceptorService : The BoxLang InterceptorService + * - moduleRecord : The ModuleRecord instance + */ +@BoxBIF "ORMTestBIF" +class { + + /** + * An example BOXLANG BIF + * + * @name + * @age + */ + function invoke() { + return "Hello from an ORMTestBIF!"; + } + +} diff --git a/src/main/java/com/ortussolutions/bifs/ORMFlush.java b/src/main/java/com/ortussolutions/bifs/ORMFlush.java new file mode 100644 index 0000000..29f6450 --- /dev/null +++ b/src/main/java/com/ortussolutions/bifs/ORMFlush.java @@ -0,0 +1,21 @@ +package com.ortussolutions.bifs; + +import ortus.boxlang.runtime.bifs.BIF; +import ortus.boxlang.runtime.bifs.BoxBIF; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.scopes.ArgumentsScope; + +@BoxBIF +public class ORMFlush extends BIF { + + /** + * ExampleBIF + * + * @param context The context in which the BIF is being invoked. + * @param arguments Argument scope for the BIF. + */ + public String _invoke(IBoxContext context, ArgumentsScope arguments) { + return "Hello from an ORMFlush!"; + } + +} diff --git a/src/test/java/com/ortussolutions/bifs/ORMFlushTest.java b/src/test/java/com/ortussolutions/bifs/ORMFlushTest.java new file mode 100644 index 0000000..1c87578 --- /dev/null +++ b/src/test/java/com/ortussolutions/bifs/ORMFlushTest.java @@ -0,0 +1,51 @@ +package com.ortussolutions.bifs; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.nio.file.Path; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import ortus.boxlang.runtime.BoxRuntime; +import ortus.boxlang.runtime.context.IBoxContext; +import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; +import ortus.boxlang.runtime.scopes.IScope; +import ortus.boxlang.runtime.scopes.Key; +import ortus.boxlang.runtime.scopes.VariablesScope; + +public class ORMFlushTest { + + static BoxRuntime instance; + IBoxContext context; + IScope variables; + static Key result = new Key("result"); + + @BeforeAll + public static void setUp() { + instance = BoxRuntime.getInstance(true, Path.of("src/test/resources/boxlang.json").toString()); + } + + @BeforeEach + public void setupEach() { + context = new ScriptingRequestBoxContext(instance.getRuntimeContext()); + variables = context.getScopeNearby(VariablesScope.name); + } + + @DisplayName("It can test the ExampleBIF") + @Test + public void testExampleBIF() { + instance.executeSource("result = ORMFlush()", context); + assertEquals("Hello from an ORMFlush!", variables.get(result)); + } + + @DisplayName("It can test the ExampleBIF") + @Test + public void testTestBIF() { + instance.executeSource("result = ORMTestBIF()", context); + assertEquals("Hello from an ORMTestBIF!", variables.get(result)); + } + +} diff --git a/src/test/resources/boxlang.json b/src/test/resources/boxlang.json new file mode 100644 index 0000000..ccedd5b --- /dev/null +++ b/src/test/resources/boxlang.json @@ -0,0 +1,49 @@ +{ + "compiler": { + "classGenerationDirectory": "${java-temp}boxlangtests" + }, + "runtime": { + "mappings": {}, + // This can be more than one location + "modulesDirectory": [ + "${user-dir}/src/main" + ], + "datasources": { + "testDB": { + "driver": "derby", + "properties": { + "connectionString": "jdbc:derby:memory:testDB;create=true" + } + } + }, + "defaultCache": { + "evictCount": 1, + "evictionPolicy": "LRU", + "freeMemoryPercentageThreshold": 0, + "maxObjects": 1000, + "defaultLastAccessTimeout": 30, + "defaultTimeout": 120, + "objectStore": "ConcurrentSoftReferenceStore", + "reapFrequency": 2, + "resetTimeoutOnAccess": false, + "useLastAccessTimeouts": true + }, + "caches": { + "imports": { + "provider": "BoxCacheProvider", + "properties": { + "evictCount": 1, + "evictionPolicy": "LRU", + "freeMemoryPercentageThreshold": 0, + "maxObjects": 200, + "defaultLastAccessTimeout": 30, + "defaultTimeout": 60, + "objectStore": "ConcurrentStore", + "reapFrequency": 2, + "resetTimeoutOnAccess": false, + "useLastAccessTimeouts": true + } + } + } + } +} \ No newline at end of file