Skip to content

Commit

Permalink
add addional test cases for createObject:java
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 5, 2024
1 parent 3a4412a commit 66d7142
Showing 1 changed file with 297 additions and 0 deletions.
297 changes: 297 additions & 0 deletions test/functions/createObject.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(PromptContext.of("test").hasTools()).toBeFalse();
});





it( title = "Checking the createObject(..,javasettings:{maven:...}) with guava", body = function( currentSpec ) {
var ImmutableList=createObject("java","com.google.common.collect.ImmutableList",{
"maven":[
Expand All @@ -40,6 +44,37 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(ImmutableList.of("a", "b", "c").size()).toBe(3);
});

it( title = "Checking the createObject(..,directory) with guava", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "com.google.guava",
"artifactId" : "guava",
"version" : "31.0.1-jre");
try {
var ImmutableList=createObject("java","com.google.common.collect.ImmutableList",data.directory);
expect(ImmutableList.of("a", "b", "c").size()).toBe(3);
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with guava", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "com.google.guava",
"artifactId" : "guava",
"version" : "31.0.1-jre");
try {
var ImmutableList=createObject("java","com.google.common.collect.ImmutableList",data.jars);
expect(ImmutableList.of("a", "b", "c").size()).toBe(3);
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});






it( title = "Checking the createObject(..,javasettings:{maven:...}) with jackson-databind", body = function( currentSpec ) {
var ObjectMapper=createObject("java","com.fasterxml.jackson.databind.ObjectMapper",{
"maven":[
Expand All @@ -53,6 +88,38 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(ObjectMapper.writeValueAsString({"key":"value"})).toBe('{"key":"value"}');
});

it( title = "Checking the createObject(..,directory) with jackson-databind", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "com.fasterxml.jackson.core",
"artifactId" : "jackson-databind",
"version" : "2.12.5");
try {
var ObjectMapper=createObject("java","com.fasterxml.jackson.databind.ObjectMapper",data.directory);
expect(ObjectMapper.writeValueAsString({"key":"value"})).toBe('{"key":"value"}');
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with jackson-databind", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "com.fasterxml.jackson.core",
"artifactId" : "jackson-databind",
"version" : "2.12.5");
try {
var ObjectMapper=createObject("java","com.fasterxml.jackson.databind.ObjectMapper",data.jars);
expect(ObjectMapper.writeValueAsString({"key":"value"})).toBe('{"key":"value"}');
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});







it( title = "Checking the createObject(..,javasettings:{maven:...}) with slf4j", body = function( currentSpec ) {
var Logger=createObject("java","org.slf4j.LoggerFactory",{
"maven":[
Expand All @@ -66,6 +133,38 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(Logger.getLogger("TestLogger").isDebugEnabled()).toBeFalse();
});

it( title = "Checking the createObject(..,directory) with slf4j", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.slf4j",
"artifactId" : "slf4j-api",
"version" : "1.7.32");
try {
var Logger=createObject("java","org.slf4j.LoggerFactory",data.directory);
expect(Logger.getLogger("TestLogger").isDebugEnabled()).toBeFalse();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with slf4j", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.slf4j",
"artifactId" : "slf4j-api",
"version" : "1.7.32");
try {
var Logger=createObject("java","org.slf4j.LoggerFactory",data.jars);
expect(Logger.getLogger("TestLogger").isDebugEnabled()).toBeFalse();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});







it( title = "Checking the createObject(..,javasettings:{maven:...}) with commons-lang3", body = function( currentSpec ) {
var StringUtils=createObject("java","org.apache.commons.lang3.StringUtils",{
"maven":[
Expand All @@ -79,6 +178,37 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(StringUtils.isEmpty("")).toBeTrue();
});

it( title = "Checking the createObject(..,directory) with commons-lang3", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.apache.commons",
"artifactId" : "commons-lang3",
"version" : "3.12.0");
try {
var StringUtils=createObject("java","org.apache.commons.lang3.StringUtils",data.directory);
expect(StringUtils.isEmpty("")).toBeTrue();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with commons-lang3", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.apache.commons",
"artifactId" : "commons-lang3",
"version" : "3.12.0");
try {
var StringUtils=createObject("java","org.apache.commons.lang3.StringUtils",data.jars);
expect(StringUtils.isEmpty("")).toBeTrue();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});






it( title = "Checking the createObject(..,javasettings:{maven:...}) with apache-httpclient", body = function( currentSpec ) {
var HttpClients=createObject("java","org.apache.http.impl.client.HttpClients",{
"maven":[
Expand All @@ -92,6 +222,38 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(HttpClients.createDefault().getClass().getSimpleName()).toBe("InternalHttpClient");
});

it( title = "Checking the createObject(..,directory) with apache-httpclient", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.apache.httpcomponents",
"artifactId" : "httpclient",
"version" : "4.5.13");
try {
var HttpClients=createObject("java","org.apache.http.impl.client.HttpClients",data.directory);
expect(HttpClients.createDefault().getClass().getSimpleName()).toBe("InternalHttpClient");
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with apache-httpclient", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.apache.httpcomponents",
"artifactId" : "httpclient",
"version" : "4.5.13");
try {
var HttpClients=createObject("java","org.apache.http.impl.client.HttpClients",data.jars);
expect(HttpClients.createDefault().getClass().getSimpleName()).toBe("InternalHttpClient");
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});







it( title = "Checking the createObject(..,javasettings:{maven:...}) with logback-classic", body = function( currentSpec ) {
var LoggerFactory=createObject("java","ch.qos.logback.classic.Logger",{
"maven":[
Expand All @@ -105,6 +267,38 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
// expect(LoggerFactory.getName()).toBeDefined();
});

it( title = "Checking the createObject(..,jars) with logback-classic", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "ch.qos.logback",
"artifactId" : "logback-classic",
"version" : "1.2.11");
try {
var LoggerFactory=createObject("java","ch.qos.logback.classic.Logger",data.jars);
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,directory) with logback-classic", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "ch.qos.logback",
"artifactId" : "logback-classic",
"version" : "1.2.11");
try {
var LoggerFactory=createObject("java","ch.qos.logback.classic.Logger",data.directory);
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});









it( title = "Checking the createObject(..,javasettings:{maven:...}) with hamcrest", body = function( currentSpec ) {
var Matchers=createObject("java","org.hamcrest.Matchers",{
"maven":[
Expand All @@ -118,6 +312,35 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(Matchers.is(1).matches(1)).toBeTrue();
});

it( title = "Checking the createObject(..,directory) with hamcrest", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.hamcrest",
"artifactId" : "hamcrest",
"version" : "2.2");
try {
var Matchers=createObject("java","org.hamcrest.Matchers",data.directory);
expect(Matchers.is(1).matches(1)).toBeTrue();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with hamcrest", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "org.hamcrest",
"artifactId" : "hamcrest",
"version" : "2.2");
try {
var Matchers=createObject("java","org.hamcrest.Matchers",data.jars);
expect(Matchers.is(1).matches(1)).toBeTrue();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});




it( title = "Checking the createObject(..,javasettings:{maven:...}) with rxjava", body = function( currentSpec ) {
var Observable=createObject("java","io.reactivex.rxjava3.core.Observable",{
"maven":[
Expand All @@ -131,6 +354,36 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(Observable.just("Hello").blockingFirst()).toBe("Hello");
});

it( title = "Checking the createObject(..,directory) with rxjava", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "io.reactivex.rxjava3",
"artifactId" : "rxjava",
"version" : "3.0.13");
try {
var Observable=createObject("java","io.reactivex.rxjava3.core.Observable",data.directory);
expect(Observable.just("Hello").blockingFirst()).toBe("Hello");
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with rxjava", body = function( currentSpec ) {
var data=getJarsFor("groupId" : "io.reactivex.rxjava3",
"artifactId" : "rxjava",
"version" : "3.0.13");
try {
var Observable=createObject("java","io.reactivex.rxjava3.core.Observable",data.jars);
expect(Observable.just("Hello").blockingFirst()).toBe("Hello");
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});





it( title = "Checking the createObject(..,javasettings:{maven:...}) with maven-core", body = function( currentSpec ) {
var MissingModuleException=createObject("java","org.apache.maven.MissingModuleException",{
"maven":[
Expand All @@ -147,9 +400,53 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
expect(len(msg)>0).toBeTrue();
});

it( title = "Checking the createObject(..,directory) with maven-core", body = function( currentSpec ) {
var data=getJarsFor("org.apache.maven", "maven-core", "3.8.1");
try {
var MissingModuleException=createObject("java","org.apache.maven.MissingModuleException",data.directory);
var curr=createObject("java","java.io.File").init(getCurrentTemplatePath());
var msg=MissingModuleException.init("Test",curr,curr).getMessage();
expect(len(msg)>0).toBeTrue();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});

it( title = "Checking the createObject(..,jars) with maven-core", body = function( currentSpec ) {
var data=getJarsFor("org.apache.maven", "maven-core", "3.8.1");
try {
var MissingModuleException=createObject("java","org.apache.maven.MissingModuleException",data.jars);
var curr=createObject("java","java.io.File").init(getCurrentTemplatePath());
var msg=MissingModuleException.init("Test",curr,curr).getMessage();
expect(len(msg)>0).toBeTrue();
}
finally {
if(directoryExists(data.directory)) directoryDelete(data.directory, true);
}
});



});
}


private function getJarsFor(groupId,artifactId,version) {
var jars=mavenLoad({
"groupId" : groupId,
"artifactId" : artifactId,
"version" : version
});

var trg=expandPath("{temp-directory}/#createUniqueID()#/");
if(!directoryExists(trg)) directoryCreate(trg);
var rtn={"jars":[],"directory":trg};
loop array=jars item="local.jar" {
var tmp=trg&listLast(jar,"\/");
arrayAppend(rtn.jars, tmp);
fileCopy(jar, tmp);
}
return rtn;
}
}

0 comments on commit 66d7142

Please sign in to comment.