Skip to content

Commit

Permalink
- URI Delimiter
Browse files Browse the repository at this point in the history
- Github Actions Consolidation
- More tests
  • Loading branch information
lmajano committed Nov 20, 2024
1 parent fd24322 commit c935ca4
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 74 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
// You must run `./gradle build -x test` in the BoxLang project
compileOnly files( '../../boxlang/build/distributions/boxlang-' + boxlangVersion + '-all.jar' )
compileOnly files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '-all.jar' )
implementation 'org.apache.derby:derby:10.17.1.0'

// Testing Dependencies
testImplementation files( '../../boxlang/build/distributions/boxlang-' + boxlangVersion + '-all.jar' )
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- URI Delimiter
- Github Actions Consolidation
- More tests

## [1.0.0] => 2024-APR-05

* First iteration of this module
2 changes: 1 addition & 1 deletion src/main/bx/ModuleConfig.bx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class {
* The BoxLang mapping for your module. All BoxLang modules are registered with an internal
* mapping prefix of : bxModules.{this.mapping}, /bxmodules/{this.mapping}. Ex: bxModules.test, /bxmodules/test
*/
this.mapping = "bxderby";
this.mapping = "derby";

/**
* Who built the module
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/ortus/boxlang/modules/derby/DerbyDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public DerbyDriver() {
this.driverClassName = "org.apache.derby.jdbc.EmbeddedDriver";
this.defaultDelimiter = ";";
this.defaultURIDelimiter = ";";
this.defaultCustomParams = Struct.of(
"create", "true" );
this.defaultCustomParams = Struct.of( "create", "true" );
this.defaultProperties = Struct.of();
}

Expand Down
74 changes: 74 additions & 0 deletions src/test/java/ortus/boxlang/modules/derby/BaseIntegrationTest.java
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 );
}

}
71 changes: 0 additions & 71 deletions src/test/java/ortus/boxlang/modules/derby/DerbyDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@

import static com.google.common.truth.Truth.assertThat;

import java.nio.file.Paths;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import ortus.boxlang.runtime.BoxRuntime;
import ortus.boxlang.runtime.config.segments.DatasourceConfig;
import ortus.boxlang.runtime.context.IBoxContext;
import ortus.boxlang.runtime.context.ScriptingRequestBoxContext;
import ortus.boxlang.runtime.jdbc.drivers.DatabaseDriverType;
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.DatasourceService;
import ortus.boxlang.runtime.services.ModuleService;
import ortus.boxlang.runtime.types.Query;
import ortus.boxlang.runtime.types.Struct;

public class DerbyDriverTest {

Expand Down Expand Up @@ -84,63 +72,4 @@ public void testBuildConnectionURLNoDatabase() {
}
}

@DisplayName( "Test the module loads in BoxLang" )
@Test
public void testModuleLoads() {
// Given
Key moduleName = new Key( "bx-derby" );
String physicalPath = Paths.get( "./build/module" ).toAbsolutePath().toString();
ModuleRecord moduleRecord = new ModuleRecord( physicalPath );
IBoxContext context = new ScriptingRequestBoxContext();
BoxRuntime runtime = BoxRuntime.getInstance( true );
ModuleService moduleService = runtime.getModuleService();
DatasourceService datasourceService = runtime.getDataSourceService();
IScope variables = context.getScopeNearby( VariablesScope.name );

// When
moduleRecord
.loadDescriptor( context )
.register( context )
.activate( context );

moduleService.getRegistry().put( moduleName, moduleRecord );

// Then
assertThat( moduleService.getRegistry().containsKey( moduleName ) ).isTrue();
assertThat( datasourceService.hasDriver( Key.of( "derby" ) ) ).isTrue();

// Register a named datasource
runtime.getConfiguration().runtime.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 );
}

}
74 changes: 74 additions & 0 deletions src/test/java/ortus/boxlang/modules/derby/IntegrationTest.java
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 );

}
}
3 changes: 3 additions & 0 deletions src/test/resources/boxlang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"modules": {}
}

0 comments on commit c935ca4

Please sign in to comment.