generated from ortus-boxlang/boxlang-module-template
-
-
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.
- Github Actions Consolidation - More tests
- Loading branch information
Showing
8 changed files
with
160 additions
and
74 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
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
74 changes: 74 additions & 0 deletions
74
src/test/java/ortus/boxlang/modules/derby/BaseIntegrationTest.java
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,74 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
package ortus.boxlang.modules.derby; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import ortus.boxlang.runtime.BoxRuntime; | ||
import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; | ||
import ortus.boxlang.runtime.modules.ModuleRecord; | ||
import ortus.boxlang.runtime.scopes.IScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.scopes.VariablesScope; | ||
import ortus.boxlang.runtime.services.ModuleService; | ||
|
||
/** | ||
* Use this as a base integration test for your non web-support package | ||
* modules. If you want web based testing, use the BaseWebIntegrationTest | ||
*/ | ||
public abstract class BaseIntegrationTest { | ||
|
||
protected static BoxRuntime runtime; | ||
protected static ModuleService moduleService; | ||
protected static ModuleRecord moduleRecord; | ||
protected static Key result = new Key( "result" ); | ||
protected static Key moduleName = new Key( "derby" ); | ||
protected ScriptingRequestBoxContext context; | ||
protected IScope variables; | ||
|
||
@BeforeAll | ||
public static void setup() { | ||
runtime = BoxRuntime.getInstance( true, Path.of( "src/test/resources/boxlang.json" ).toString() ); | ||
moduleService = runtime.getModuleService(); | ||
} | ||
|
||
@BeforeEach | ||
public void setupEach() { | ||
|
||
// Create the mock contexts | ||
context = new ScriptingRequestBoxContext(); | ||
variables = context.getScopeNearby( VariablesScope.name ); | ||
|
||
// Load the module | ||
loadModule(); | ||
} | ||
|
||
protected void loadModule() { | ||
String physicalPath = Paths.get( "./build/module" ).toAbsolutePath().toString(); | ||
moduleRecord = new ModuleRecord( physicalPath ); | ||
|
||
moduleService.getRegistry().put( moduleName, moduleRecord ); | ||
|
||
moduleRecord | ||
.loadDescriptor( context ) | ||
.register( context ) | ||
.activate( context ); | ||
} | ||
|
||
} |
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
74 changes: 74 additions & 0 deletions
74
src/test/java/ortus/boxlang/modules/derby/IntegrationTest.java
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,74 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
package ortus.boxlang.modules.derby; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import ortus.boxlang.runtime.config.segments.DatasourceConfig; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.types.Query; | ||
import ortus.boxlang.runtime.types.Struct; | ||
|
||
/** | ||
* This loads the module and runs an integration test on the module. | ||
*/ | ||
public class IntegrationTest extends BaseIntegrationTest { | ||
|
||
@DisplayName( "Test the module loads in BoxLang" ) | ||
@Test | ||
public void testModuleLoads() { | ||
// Given | ||
|
||
// Then | ||
assertThat( moduleService.getRegistry().containsKey( moduleName ) ).isTrue(); | ||
|
||
// Register a named datasource | ||
runtime.getConfiguration().datasources.put( | ||
Key.of( "derby" ), | ||
new DatasourceConfig( | ||
"derby", | ||
Struct.of( | ||
"driver", "derby", | ||
"database", "testDB", | ||
"protocol", "memory" | ||
) | ||
) | ||
); | ||
|
||
// @formatter:off | ||
runtime.executeSource( | ||
""" | ||
try{ | ||
queryExecute( "DROP table developers", [], { "datasource": "derby" } ); | ||
}catch( any e ){ | ||
// Ignore | ||
} | ||
queryExecute( "CREATE TABLE developers ( id INTEGER, name VARCHAR(155), role VARCHAR(155) )", [], { "datasource": "derby" } ); | ||
queryExecute( "INSERT INTO developers ( id, name, role ) VALUES ( 77, 'Michael Born', 'Developer' )", [], { "datasource": "derby" } ); | ||
result = queryExecute( "SELECT * FROM developers ORDER BY id", [], { "datasource": "derby" } ); | ||
""", | ||
context | ||
); | ||
// @formatter:on | ||
|
||
// Assert it executes | ||
Query result = ( Query ) variables.get( Key.result ); | ||
assertThat( result.size() ).isEqualTo( 1 ); | ||
|
||
} | ||
} |
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,3 @@ | ||
{ | ||
"modules": {} | ||
} |