From bff36600f9f4b6ee746d283d618fb0dc533849ea Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Sat, 3 Jun 2023 10:22:25 +0200 Subject: [PATCH] import tests --- tests/autogenmap.cfc | 22 ++++++++++++ tests/autogenmap/Application.cfc | 40 +++++++++++++++++++++ tests/autogenmap/Auto.cfc | 8 +++++ tests/autogenmap/Auto.cfc.hbm.xml | 15 ++++++++ tests/autogenmap/Dealership.cfc | 7 ++++ tests/autogenmap/Dealership.cfc.hbm.xml | 12 +++++++ tests/autogenmap/index.cfm | 26 ++++++++++++++ tests/datasources.cfc | 22 ++++++++++++ tests/datasources/Application.cfc | 40 +++++++++++++++++++++ tests/datasources/Auto.cfc | 8 +++++ tests/datasources/Auto.cfc.hbm.xml | 20 +++++++++++ tests/datasources/Dealership.cfc | 7 ++++ tests/datasources/Dealership.cfc.hbm.xml | 17 +++++++++ tests/datasources/index.cfm | 26 ++++++++++++++ tests/docker-compose.yml | 46 ++++++++++++++++++++++++ tests/docker/mssql/create.sql | 4 +++ tests/docker/mssql/entrypoint.sh | 22 ++++++++++++ tests/ehcache.cfc | 22 ++++++++++++ tests/ehcache/Application.cfc | 43 ++++++++++++++++++++++ tests/ehcache/Auto.cfc | 8 +++++ tests/ehcache/ehcache.xml | 19 ++++++++++ tests/ehcache/index.cfm | 24 +++++++++++++ tests/ormconfig.cfc | 22 ++++++++++++ tests/ormconfig/Application.cfc | 39 ++++++++++++++++++++ tests/ormconfig/Auto.cfc | 8 +++++ tests/ormconfig/hibernate.cfg.xml | 13 +++++++ tests/ormconfig/index.cfm | 12 +++++++ tests/savepoints.cfc | 19 ++++++++++ tests/savepoints/Application.cfc | 37 +++++++++++++++++++ tests/savepoints/Auto.cfc | 8 +++++ tests/savepoints/index.cfm | 13 +++++++ tests/tickets/LDEV3907.cfc | 30 ++++++++++++++++ tests/tickets/LDEV3907/Application.cfc | 11 ++++++ tests/tickets/LDEV3907/Brand.cfc | 7 ++++ tests/tickets/LDEV3907/LDEV3907.cfm | 6 ++++ tests/tickets/LDEV4150.cfc | 35 ++++++++++++++++++ tests/tickets/LDEV4150/Application.cfc | 9 +++++ tests/tickets/LDEV4150/LDEV4150.cfm | 15 ++++++++ tests/tickets/LDEV4150/test4150.cfc | 10 ++++++ 39 files changed, 752 insertions(+) create mode 100644 tests/autogenmap.cfc create mode 100644 tests/autogenmap/Application.cfc create mode 100644 tests/autogenmap/Auto.cfc create mode 100644 tests/autogenmap/Auto.cfc.hbm.xml create mode 100644 tests/autogenmap/Dealership.cfc create mode 100644 tests/autogenmap/Dealership.cfc.hbm.xml create mode 100644 tests/autogenmap/index.cfm create mode 100644 tests/datasources.cfc create mode 100644 tests/datasources/Application.cfc create mode 100644 tests/datasources/Auto.cfc create mode 100644 tests/datasources/Auto.cfc.hbm.xml create mode 100644 tests/datasources/Dealership.cfc create mode 100644 tests/datasources/Dealership.cfc.hbm.xml create mode 100644 tests/datasources/index.cfm create mode 100644 tests/docker-compose.yml create mode 100644 tests/docker/mssql/create.sql create mode 100644 tests/docker/mssql/entrypoint.sh create mode 100644 tests/ehcache.cfc create mode 100644 tests/ehcache/Application.cfc create mode 100644 tests/ehcache/Auto.cfc create mode 100644 tests/ehcache/ehcache.xml create mode 100644 tests/ehcache/index.cfm create mode 100644 tests/ormconfig.cfc create mode 100644 tests/ormconfig/Application.cfc create mode 100644 tests/ormconfig/Auto.cfc create mode 100644 tests/ormconfig/hibernate.cfg.xml create mode 100644 tests/ormconfig/index.cfm create mode 100644 tests/savepoints.cfc create mode 100644 tests/savepoints/Application.cfc create mode 100644 tests/savepoints/Auto.cfc create mode 100644 tests/savepoints/index.cfm create mode 100644 tests/tickets/LDEV3907.cfc create mode 100644 tests/tickets/LDEV3907/Application.cfc create mode 100644 tests/tickets/LDEV3907/Brand.cfc create mode 100644 tests/tickets/LDEV3907/LDEV3907.cfm create mode 100644 tests/tickets/LDEV4150.cfc create mode 100644 tests/tickets/LDEV4150/Application.cfc create mode 100644 tests/tickets/LDEV4150/LDEV4150.cfm create mode 100644 tests/tickets/LDEV4150/test4150.cfc diff --git a/tests/autogenmap.cfc b/tests/autogenmap.cfc new file mode 100644 index 00000000..35fd6f92 --- /dev/null +++ b/tests/autogenmap.cfc @@ -0,0 +1,22 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + + public void function testAutoGenMap(){ + + local.uri=createURI("autogenmap/index.cfm"); + local.result=_InternalRequest(uri); + expect( result.status ).toBe( 200 ); + // var res = deserializeJson(result.fileContent); + // if (len(res.errors)){ + // loop array=res.errors, item="local.err"{ + // systemOutput("ERROR: " & err.error, true, true); + // } + // } + } + + private string function createURI(string calledName){ + systemOutput("", true); + systemOutput("-------------- #calledName#----------------", true); + var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ); + return baseURI&""&calledName; + } +} \ No newline at end of file diff --git a/tests/autogenmap/Application.cfc b/tests/autogenmap/Application.cfc new file mode 100644 index 00000000..d52df072 --- /dev/null +++ b/tests/autogenmap/Application.cfc @@ -0,0 +1,40 @@ +component { + + this.name = "orm-autogenmap"; + this.datasources["h2"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/db" ); + this.datasources["h2_otherDB"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/otherDB" ); + this.ormEnabled = true; + this.ormSettings = { + dbcreate: "dropcreate", + dialect: "h2", + skipCFCWithError : false, + datasource : "h2", + autogenmap : false + }; + + function onApplicationStart() { + } + + public function onRequestStart() { + setting requesttimeout=10; + if ( url.keyExists( "flushcache" ) ){ + componentCacheClear(); + } + } + + function onRequestEnd() { + var javaIoFile=createObject("java","java.io.File"); + loop array = DirectoryList( + path = getDirectoryFromPath( getCurrentTemplatePath() ), + recurse = true, filter="*.db") item="local.path" { + fileDeleteOnExit(javaIoFile,path); + } + } + + private function fileDeleteOnExit(required javaIoFile, required string path) { + var file=javaIoFile.init(arguments.path); + if(!file.isFile())file=javaIoFile.init(expandPath(arguments.path)); + if(file.isFile()) file.deleteOnExit(); + } + +} \ No newline at end of file diff --git a/tests/autogenmap/Auto.cfc b/tests/autogenmap/Auto.cfc new file mode 100644 index 00000000..5f4e14e4 --- /dev/null +++ b/tests/autogenmap/Auto.cfc @@ -0,0 +1,8 @@ +component persistent="true" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="make" type="string"; + property name="model" type="string"; + + this.name = "Auto"; +} \ No newline at end of file diff --git a/tests/autogenmap/Auto.cfc.hbm.xml b/tests/autogenmap/Auto.cfc.hbm.xml new file mode 100644 index 00000000..e0269b95 --- /dev/null +++ b/tests/autogenmap/Auto.cfc.hbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/tests/autogenmap/Dealership.cfc b/tests/autogenmap/Dealership.cfc new file mode 100644 index 00000000..6dd58e3a --- /dev/null +++ b/tests/autogenmap/Dealership.cfc @@ -0,0 +1,7 @@ +component persistent="true" datasource="h2_otherDB" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="name" type="string"; + + this.name = "Dealership"; +} \ No newline at end of file diff --git a/tests/autogenmap/Dealership.cfc.hbm.xml b/tests/autogenmap/Dealership.cfc.hbm.xml new file mode 100644 index 00000000..477a76f1 --- /dev/null +++ b/tests/autogenmap/Dealership.cfc.hbm.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/autogenmap/index.cfm b/tests/autogenmap/index.cfm new file mode 100644 index 00000000..5603f8d8 --- /dev/null +++ b/tests/autogenmap/index.cfm @@ -0,0 +1,26 @@ + + transaction{ + car = entityNew( "Auto" ); + car.setId( createUUID() ); + car.setMake( "Ford" ); + car.setModel( "F-150" ); + entitySave( car ); + + dealer = entityNew( "Dealership" ); + dealer.setId( createUUID() ); + dealer.setName( "Sedgewick Subaru" ); + entitySave( dealer ); + + ormFlush(); + } + + autoResults = queryExecute( "SELECT * FROM Auto WHERE id=:id", { id : car.getId() }, { datasource: "h2" } ); + if ( !autoResults.recordCount ){ + throw( "auto #car.getId()# not found in datasource table" ); + } + + dealerResults = queryExecute( "SELECT * FROM Dealership WHERE id=:id", { id : dealer.getId() }, { datasource: "h2_otherDB" } ); + if ( !dealerResults.recordCount ){ + throw( "Dealership #dealer.getId()# not found in datasource table" ); + } + \ No newline at end of file diff --git a/tests/datasources.cfc b/tests/datasources.cfc new file mode 100644 index 00000000..09f7c024 --- /dev/null +++ b/tests/datasources.cfc @@ -0,0 +1,22 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + + public void function testDatasources(){ + + local.uri=createURI("datasources/index.cfm"); + local.result=_InternalRequest(uri); + expect( result.status ).toBe( 200 ); + // var res = deserializeJson(result.fileContent); + // if (len(res.errors)){ + // loop array=res.errors, item="local.err"{ + // systemOutput("ERROR: " & err.error, true, true); + // } + // } + } + + private string function createURI(string calledName){ + systemOutput("", true); + systemOutput("-------------- #calledName#----------------", true); + var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ); + return baseURI&""&calledName; + } +} \ No newline at end of file diff --git a/tests/datasources/Application.cfc b/tests/datasources/Application.cfc new file mode 100644 index 00000000..8d749407 --- /dev/null +++ b/tests/datasources/Application.cfc @@ -0,0 +1,40 @@ +component { + + this.name = "orm-datasources"; + this.datasources["h2"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/db" ); + this.datasources["h2_otherDB"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/otherDB" ); + this.ormEnabled = true; + this.ormSettings = { + dbcreate: "dropcreate", + dialect: "h2", + skipCFCWithError : false, + datasource : "h2", + saveMapping : false + }; + + function onApplicationStart() { + } + + public function onRequestStart() { + setting requesttimeout=10; + if ( url.keyExists( "flushcache" ) ){ + componentCacheClear(); + } + } + + function onRequestEnd() { + var javaIoFile=createObject("java","java.io.File"); + loop array = DirectoryList( + path = getDirectoryFromPath( getCurrentTemplatePath() ), + recurse = true, filter="*.db") item="local.path" { + fileDeleteOnExit(javaIoFile,path); + } + } + + private function fileDeleteOnExit(required javaIoFile, required string path) { + var file=javaIoFile.init(arguments.path); + if(!file.isFile())file=javaIoFile.init(expandPath(arguments.path)); + if(file.isFile()) file.deleteOnExit(); + } + +} \ No newline at end of file diff --git a/tests/datasources/Auto.cfc b/tests/datasources/Auto.cfc new file mode 100644 index 00000000..5f4e14e4 --- /dev/null +++ b/tests/datasources/Auto.cfc @@ -0,0 +1,8 @@ +component persistent="true" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="make" type="string"; + property name="model" type="string"; + + this.name = "Auto"; +} \ No newline at end of file diff --git a/tests/datasources/Auto.cfc.hbm.xml b/tests/datasources/Auto.cfc.hbm.xml new file mode 100644 index 00000000..8c260280 --- /dev/null +++ b/tests/datasources/Auto.cfc.hbm.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + diff --git a/tests/datasources/Dealership.cfc b/tests/datasources/Dealership.cfc new file mode 100644 index 00000000..6dd58e3a --- /dev/null +++ b/tests/datasources/Dealership.cfc @@ -0,0 +1,7 @@ +component persistent="true" datasource="h2_otherDB" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="name" type="string"; + + this.name = "Dealership"; +} \ No newline at end of file diff --git a/tests/datasources/Dealership.cfc.hbm.xml b/tests/datasources/Dealership.cfc.hbm.xml new file mode 100644 index 00000000..e407d331 --- /dev/null +++ b/tests/datasources/Dealership.cfc.hbm.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/tests/datasources/index.cfm b/tests/datasources/index.cfm new file mode 100644 index 00000000..5603f8d8 --- /dev/null +++ b/tests/datasources/index.cfm @@ -0,0 +1,26 @@ + + transaction{ + car = entityNew( "Auto" ); + car.setId( createUUID() ); + car.setMake( "Ford" ); + car.setModel( "F-150" ); + entitySave( car ); + + dealer = entityNew( "Dealership" ); + dealer.setId( createUUID() ); + dealer.setName( "Sedgewick Subaru" ); + entitySave( dealer ); + + ormFlush(); + } + + autoResults = queryExecute( "SELECT * FROM Auto WHERE id=:id", { id : car.getId() }, { datasource: "h2" } ); + if ( !autoResults.recordCount ){ + throw( "auto #car.getId()# not found in datasource table" ); + } + + dealerResults = queryExecute( "SELECT * FROM Dealership WHERE id=:id", { id : dealer.getId() }, { datasource: "h2_otherDB" } ); + if ( !dealerResults.recordCount ){ + throw( "Dealership #dealer.getId()# not found in datasource table" ); + } + \ No newline at end of file diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 00000000..1d212e3d --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,46 @@ + +version: "3.9" +services: + + mysql: + platform: linux/x86_64 # Needed for Mac's on the M1 chip + image: mysql:5 + environment: + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD} + ports: + - "${MYSQL_PORT}:3306" + + postgres: + image: postgres:11.3 + environment: + POSTGRES_USER: ${POSTGRES_USERNAME} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DATABASE} + ports: + - "${POSTGRES_PORT}:5432" + + mssql: + image: mcr.microsoft.com/mssql/server:2017-latest + environment: + MSSQL_SA_PASSWORD: ${MSSQL_PASSWORD} + ACCEPT_EULA: "Y" + MSSQL_PID: "Developer" + volumes: + # Mounted entrypoint for initdb scripts + - ./docker/mssql:/docker-entrypoint-initdb.d + ports: + - "${MSSQL_PORT}:1433" + entrypoint: /docker-entrypoint-initdb.d/entrypoint.sh /opt/mssql/bin/sqlservr + + # TODO: Re-enable when MongoDB testing is fixed in Lucee 6 + # mongo: + # image: mongo + # environment: + # MONGO_INITDB_ROOT_USERNAME: ${MONGODB_USERNAME} + # MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_PASSWORD} + # MONGO_INITDB_DATABASE: ${MONGODB_DB} + # volumes: + # - ./docker/mongo:/docker-entrypoint-initdb.d + # ports: + # - "${MONGODB_PORT}:27017" \ No newline at end of file diff --git a/tests/docker/mssql/create.sql b/tests/docker/mssql/create.sql new file mode 100644 index 00000000..1193cadb --- /dev/null +++ b/tests/docker/mssql/create.sql @@ -0,0 +1,4 @@ +CREATE DATABASE hibernateDB; +GO +USE hibernateDB; +GO \ No newline at end of file diff --git a/tests/docker/mssql/entrypoint.sh b/tests/docker/mssql/entrypoint.sh new file mode 100644 index 00000000..4aee548f --- /dev/null +++ b/tests/docker/mssql/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +if [ "$1" = '/opt/mssql/bin/sqlservr' ]; then + # If this is the container's first run, initialize the application database + if [ ! -f /tmp/app-initialized ]; then + # Initialize the application database asynchronously in a background process. This allows a) the SQL Server process to be the main process in the container, which allows graceful shutdown and other goodies, and b) us to only start the SQL Server process once, as opposed to starting, stopping, then starting it again. + function initialize_app_database() { + # Wait a bit for SQL Server to start. SQL Server's process doesn't provide a clever way to check if it's up or not, and it needs to be up before we can import the application database + sleep 10s + + #run the setup script to create the DB and the schema in the DB + /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P hib3rnate_DB -d master -i /docker-entrypoint-initdb.d/create.sql + + # Note that the container has been initialized so future starts won't wipe changes to the data + touch /tmp/app-initialized + } + initialize_app_database & + fi +fi + +exec "$@" \ No newline at end of file diff --git a/tests/ehcache.cfc b/tests/ehcache.cfc new file mode 100644 index 00000000..dc42f70e --- /dev/null +++ b/tests/ehcache.cfc @@ -0,0 +1,22 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + + public void function testEHCache(){ + + local.uri=createURI("ehcache/index.cfm"); + local.result=_InternalRequest(uri); + expect( result.status ).toBe( 200 ); + // var res = deserializeJson(result.fileContent); + // if (len(res.errors)){ + // loop array=res.errors, item="local.err"{ + // systemOutput("ERROR: " & err.error, true, true); + // } + // } + } + + private string function createURI(string calledName){ + systemOutput("", true); + systemOutput("-------------- #calledName#----------------", true); + var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ); + return baseURI&""&calledName; + } +} \ No newline at end of file diff --git a/tests/ehcache/Application.cfc b/tests/ehcache/Application.cfc new file mode 100644 index 00000000..f56081fd --- /dev/null +++ b/tests/ehcache/Application.cfc @@ -0,0 +1,43 @@ +component { + + this.name = "orm-ehcache"; + this.datasources["h2"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/db" ); + this.ormEnabled = true; + this.ormSettings = { + dbcreate: "dropcreate", + dialect: "h2", + skipCFCWithError : false, + datasource : "h2", + + // ehcache setup + secondarycacheenabled : true, + cacheprovider : "ehcache", + cacheconfig : "ehcache.xml" + }; + + function onApplicationStart() { + } + + public function onRequestStart() { + setting requesttimeout=10; + if ( url.keyExists( "flushcache" ) ){ + componentCacheClear(); + } + } + + function onRequestEnd() { + var javaIoFile=createObject("java","java.io.File"); + loop array = DirectoryList( + path = getDirectoryFromPath( getCurrentTemplatePath() ), + recurse = true, filter="*.db") item="local.path" { + fileDeleteOnExit(javaIoFile,path); + } + } + + private function fileDeleteOnExit(required javaIoFile, required string path) { + var file=javaIoFile.init(arguments.path); + if(!file.isFile())file=javaIoFile.init(expandPath(arguments.path)); + if(file.isFile()) file.deleteOnExit(); + } + +} \ No newline at end of file diff --git a/tests/ehcache/Auto.cfc b/tests/ehcache/Auto.cfc new file mode 100644 index 00000000..b2fc47a8 --- /dev/null +++ b/tests/ehcache/Auto.cfc @@ -0,0 +1,8 @@ +component persistent="true" cachename="Autos" cacheuse="read-only" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="make" type="string"; + property name="model" type="string"; + + this.name = "Auto"; +} \ No newline at end of file diff --git a/tests/ehcache/ehcache.xml b/tests/ehcache/ehcache.xml new file mode 100644 index 00000000..08e8e0fd --- /dev/null +++ b/tests/ehcache/ehcache.xml @@ -0,0 +1,19 @@ + + + + + + + + + \ No newline at end of file diff --git a/tests/ehcache/index.cfm b/tests/ehcache/index.cfm new file mode 100644 index 00000000..4e012bb4 --- /dev/null +++ b/tests/ehcache/index.cfm @@ -0,0 +1,24 @@ + + /** + * TODO: Verify that the hibernate config is loaded and in effect. + */ + transaction{ + car = entityNew( "Auto" ); + car.setId( createUUID() ); + car.setMake( "Ford" ); + entitySave( car ); + ormFlush(); + } + + // Delete the item from the DB + queryExecute( "DELETE FROM Auto WHERE id=:id", { id : car.getId() }, { datasource : "h2" } ); + + // don't let Hibernate load from the first-level cache( the session ) + ormClearSession(); + + // test that it loads from the cache. + otherCar = entityLoad( "Auto", car.getId() ); + if ( isNull( otherCar ) ){ + throw( "Car #car.getId()# not found in 2nd-level cache!" ); + } + \ No newline at end of file diff --git a/tests/ormconfig.cfc b/tests/ormconfig.cfc new file mode 100644 index 00000000..ce2266d8 --- /dev/null +++ b/tests/ormconfig.cfc @@ -0,0 +1,22 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + + public void function testORMConfig(){ + + local.uri=createURI("ormconfig/index.cfm"); + local.result=_InternalRequest(uri); + expect( result.status ).toBe( 200 ); + // var res = deserializeJson(result.fileContent); + // if (len(res.errors)){ + // loop array=res.errors, item="local.err"{ + // systemOutput("ERROR: " & err.error, true, true); + // } + // } + } + + private string function createURI(string calledName){ + systemOutput("", true); + systemOutput("-------------- #calledName#----------------", true); + var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ); + return baseURI&""&calledName; + } +} \ No newline at end of file diff --git a/tests/ormconfig/Application.cfc b/tests/ormconfig/Application.cfc new file mode 100644 index 00000000..b0c32247 --- /dev/null +++ b/tests/ormconfig/Application.cfc @@ -0,0 +1,39 @@ +component { + + this.name = "orm-ormconfig"; + this.datasources["h2"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/db" ); + this.ormEnabled = true; + this.ormSettings = { + dbcreate: "dropcreate", + dialect: "h2", + skipCFCWithError : false, + datasource : "h2", + ormConfig : "hibernate.cfg.xml" + }; + + function onApplicationStart() { + } + + public function onRequestStart() { + setting requesttimeout=10; + if ( url.keyExists( "flushcache" ) ){ + componentCacheClear(); + } + } + + function onRequestEnd() { + var javaIoFile=createObject("java","java.io.File"); + loop array = DirectoryList( + path = getDirectoryFromPath( getCurrentTemplatePath() ), + recurse = true, filter="*.db") item="local.path" { + fileDeleteOnExit(javaIoFile,path); + } + } + + private function fileDeleteOnExit(required javaIoFile, required string path) { + var file=javaIoFile.init(arguments.path); + if(!file.isFile())file=javaIoFile.init(expandPath(arguments.path)); + if(file.isFile()) file.deleteOnExit(); + } + +} \ No newline at end of file diff --git a/tests/ormconfig/Auto.cfc b/tests/ormconfig/Auto.cfc new file mode 100644 index 00000000..5f4e14e4 --- /dev/null +++ b/tests/ormconfig/Auto.cfc @@ -0,0 +1,8 @@ +component persistent="true" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="make" type="string"; + property name="model" type="string"; + + this.name = "Auto"; +} \ No newline at end of file diff --git a/tests/ormconfig/hibernate.cfg.xml b/tests/ormconfig/hibernate.cfg.xml new file mode 100644 index 00000000..27e853db --- /dev/null +++ b/tests/ormconfig/hibernate.cfg.xml @@ -0,0 +1,13 @@ + + + + + + + true + true + + + \ No newline at end of file diff --git a/tests/ormconfig/index.cfm b/tests/ormconfig/index.cfm new file mode 100644 index 00000000..4e618c66 --- /dev/null +++ b/tests/ormconfig/index.cfm @@ -0,0 +1,12 @@ + + /** + * TODO: Verify that the hibernate config is loaded and in effect. + */ + transaction{ + car = entityNew( "Auto" ); + car.setId( createUUID() ); + car.setMake( "Ford" ); + entitySave( car ); + ormFlush(); + } + \ No newline at end of file diff --git a/tests/savepoints.cfc b/tests/savepoints.cfc new file mode 100644 index 00000000..06e001ae --- /dev/null +++ b/tests/savepoints.cfc @@ -0,0 +1,19 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + + function run( testResults, testBox ) { + describe("ORM Savepoint Support", function() { + it( title="can use transaction savepoint", skip="true" body=function( currentSpec ) { + local.uri=createURI("savepoints/index.cfm"); + local.result=_InternalRequest(uri); + expect( result.status ).toBe( 200 ); + }); + }); + } + + private string function createURI(string calledName){ + systemOutput("", true); + systemOutput("-------------- #calledName#----------------", true); + var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ); + return baseURI&""&calledName; + } +} \ No newline at end of file diff --git a/tests/savepoints/Application.cfc b/tests/savepoints/Application.cfc new file mode 100644 index 00000000..c8b04ac6 --- /dev/null +++ b/tests/savepoints/Application.cfc @@ -0,0 +1,37 @@ +component { + + this.name = "orm-dialects"; + this.datasources["h2"] = server.getDatasource("h2", "#getDirectoryFromPath(getCurrentTemplatePath())#/datasource/db" ); + this.ormEnabled = true; + this.ormSettings = { + dbcreate: "dropcreate", + skipCFCWithError : false, + datasource : "h2", + }; + + function onApplicationStart() { + } + + public function onRequestStart() { + setting requesttimeout=10; + if ( url.keyExists( "flushcache" ) ){ + componentCacheClear(); + } + } + + function onRequestEnd() { + var javaIoFile=createObject("java","java.io.File"); + loop array = DirectoryList( + path = getDirectoryFromPath( getCurrentTemplatePath() ), + recurse = true, filter="*.db") item="local.path" { + fileDeleteOnExit(javaIoFile,path); + } + } + + private function fileDeleteOnExit(required javaIoFile, required string path) { + var file=javaIoFile.init(arguments.path); + if(!file.isFile())file=javaIoFile.init(expandPath(arguments.path)); + if(file.isFile()) file.deleteOnExit(); + } + +} \ No newline at end of file diff --git a/tests/savepoints/Auto.cfc b/tests/savepoints/Auto.cfc new file mode 100644 index 00000000..5f4e14e4 --- /dev/null +++ b/tests/savepoints/Auto.cfc @@ -0,0 +1,8 @@ +component persistent="true" { + + property name="id" type="string" fieldtype="id" ormtype="string"; + property name="make" type="string"; + property name="model" type="string"; + + this.name = "Auto"; +} \ No newline at end of file diff --git a/tests/savepoints/index.cfm b/tests/savepoints/index.cfm new file mode 100644 index 00000000..3646523c --- /dev/null +++ b/tests/savepoints/index.cfm @@ -0,0 +1,13 @@ + + ormReload(); + transaction{ + myEntity = entityNew( "Auto", { + "make" : "Hyundai", + "model" : "Accent", + "id" : createUUID() + } ); + + entitySave( myEntity ); + transactionSetSavepoint(); // throws "This feature not supported". + } + \ No newline at end of file diff --git a/tests/tickets/LDEV3907.cfc b/tests/tickets/LDEV3907.cfc new file mode 100644 index 00000000..9e5bab65 --- /dev/null +++ b/tests/tickets/LDEV3907.cfc @@ -0,0 +1,30 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + function beforeAll(){ + variables.uri = createURI("LDEV3907"); + } + + function run( testResults, testBox ) { + describe("Testcase for LDEV-3907", function() { + it( title="Setting the default value in the primary key in ORM entity", body=function( currentSpec ) { + try { + local.result = _InternalRequest( + template : "#uri#\LDEV3907.cfm" + ).filecontent; + } + catch(any e) { + result = e.message; + } + expect(trim(result)).toBe("LDEV3907"); + } skip="#notHasMssql()#"); + }); + } + + private function notHasMssql() { + return structCount(server.getDatasource("mssql")) == 0; + } + + private string function createURI(string calledName) { + var baseURI = "/testAdditional/#listLast(getDirectoryFromPath(getCurrenttemplatepath()),"\/")#/"; + return baseURI&""&calledName; + } +} \ No newline at end of file diff --git a/tests/tickets/LDEV3907/Application.cfc b/tests/tickets/LDEV3907/Application.cfc new file mode 100644 index 00000000..97820149 --- /dev/null +++ b/tests/tickets/LDEV3907/Application.cfc @@ -0,0 +1,11 @@ +component { + this.name = "LDEV-3907"; + this.ormenabled = true; + this.ormsettings = { + dbcreate="dropCreate" + ,dialect="MicrosoftSQLServer" + } + mssql = getDatasource(); + this.datasources["LDEV_3907"] = server.getDatasource("mssql"); + this.datasource = "LDEV_3907"; +} \ No newline at end of file diff --git a/tests/tickets/LDEV3907/Brand.cfc b/tests/tickets/LDEV3907/Brand.cfc new file mode 100644 index 00000000..9db1aef8 --- /dev/null +++ b/tests/tickets/LDEV3907/Brand.cfc @@ -0,0 +1,7 @@ +component displayname="brand" entityname="brand" table="brand" persistent=true output=false accessors=true { + // Persistent Properties + property name="brandID" ormtype="string" length="32" fieldtype="id" generator="uuid" unsavedvalue="" default="1"; + property name="activeFlag" ormtype="boolean"; + property name="urlTitle" ormtype="string"; + property name="brandName" ormtype="string"; +} \ No newline at end of file diff --git a/tests/tickets/LDEV3907/LDEV3907.cfm b/tests/tickets/LDEV3907/LDEV3907.cfm new file mode 100644 index 00000000..044c66bc --- /dev/null +++ b/tests/tickets/LDEV3907/LDEV3907.cfm @@ -0,0 +1,6 @@ + + + + + +#brand.getBrandName()# \ No newline at end of file diff --git a/tests/tickets/LDEV4150.cfc b/tests/tickets/LDEV4150.cfc new file mode 100644 index 00000000..d0bd0309 --- /dev/null +++ b/tests/tickets/LDEV4150.cfc @@ -0,0 +1,35 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { + + function beforeAll() { + variables.uri = createURI("LDEV4150"); + } + + function afterAll() { + if (!notHasMssql()) { + queryExecute( sql="DROP TABLE IF EXISTS test4150", options: { + datasource: server.getDatasource("mssql") + }); + } + } + + function run( testResults, testBox ) { + describe("Testcase for LDEV-4150", function() { + it( title="checking length property value to sqltype=varchar on ORM Entity", skip="#notHasMssql()#", body=function( currentSpec ) { + local.result = _InternalRequest( + template : "#uri#\LDEV4150.cfm" + ).filecontent; + expect(trim(result)).tobe("Success"); + }); + }); + } + + private function notHasMssql() { + return structCount(server.getDatasource("mssql")) == 0; + } + + private string function createURI(string calledName) { + var baseURI = "/testAdditional/#listLast(getDirectoryFromPath(getCurrenttemplatepath()),"\/")#/"; + return baseURI&""&calledName; + } + +} \ No newline at end of file diff --git a/tests/tickets/LDEV4150/Application.cfc b/tests/tickets/LDEV4150/Application.cfc new file mode 100644 index 00000000..066c7fe3 --- /dev/null +++ b/tests/tickets/LDEV4150/Application.cfc @@ -0,0 +1,9 @@ +component { + this.name = "LDEV4150" + this.ORMenabled = true; + this.datasource = server.getDatasource("mssql"); + this.ormSettings = { + dbcreate = "dropcreate", + dialect = "MicrosoftSQLServer" + }; +} \ No newline at end of file diff --git a/tests/tickets/LDEV4150/LDEV4150.cfm b/tests/tickets/LDEV4150/LDEV4150.cfm new file mode 100644 index 00000000..94f894c8 --- /dev/null +++ b/tests/tickets/LDEV4150/LDEV4150.cfm @@ -0,0 +1,15 @@ + + try { + test = entityNew( "test4150" ); + test.setName( "Steve" ); + test.setAddress( "116 Sunny Ave" ); + test.setId( createUUID() ); + entitySave( test ); + ormFlush(); + + writeOutput( "success" ); + } + catch(any e) { + writeoutput(e.message); + } + \ No newline at end of file diff --git a/tests/tickets/LDEV4150/test4150.cfc b/tests/tickets/LDEV4150/test4150.cfc new file mode 100644 index 00000000..f785f310 --- /dev/null +++ b/tests/tickets/LDEV4150/test4150.cfc @@ -0,0 +1,10 @@ + +component accessors="true" persistent="true" { + property name="id" type="string"; + property name="name" type="string" sqltype="varchar" length="100"; + property name="address" type="string" sqltype="nvarchar" length="150"; + + public component function init() { + return this; + } +} \ No newline at end of file