-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sketch out some tests and boxlang bifs
- Loading branch information
Showing
6 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} |