Skip to content

Commit

Permalink
Sketch out some tests and boxlang bifs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeers committed Apr 11, 2024
1 parent 4dabb03 commit 01cc59e
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/main/bx/ModuleConfig.bx → src/main/bx/ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// } }
];

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/bx/bifs/ExampleBxBif.bx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* - interceptorService : The BoxLang InterceptorService
* - moduleRecord : The ModuleRecord instance
*/
@BoxBIF "ExampleBxBIF"
component {
// @BoxBIF "ExampleBxBIF"
class {

/**
* An example BOXLANG BIF
Expand Down
33 changes: 33 additions & 0 deletions src/main/bx/bifs/ORMTestBIF.bx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This is a BOXLANG BIF
*
* Annotations you can use on a BIF:
* <pre>
* // 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 : '' } }
* </pre>
*
* 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!";
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/ortussolutions/bifs/ORMFlush.java
Original file line number Diff line number Diff line change
@@ -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!";
}

}
51 changes: 51 additions & 0 deletions src/test/java/com/ortussolutions/bifs/ORMFlushTest.java
Original file line number Diff line number Diff line change
@@ -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));
}

}
49 changes: 49 additions & 0 deletions src/test/resources/boxlang.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}

0 comments on commit 01cc59e

Please sign in to comment.