Weird error when trying to use orm event handling in my testing application.cfc

Alright - I have a weird error:

coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.runtime.ObjectDuplicator$UnableToDuplicateCFCException :
Unable to duplicate a ColdFusion
Component.org.hibernate.HibernateException:
coldfusion.runtime.CustomException: ColdBox Controller Not Found]

This is occurring when I try to run integration tests using MXUnit and
Eclipse.

This is in my site/test/Application.cfc file:

  <cfset this.ormsettings["eventHandling"] = true>
  <cfset this.ormsettings["eventHandler"] =
"site.model.ORMEventHandler">

site.model.ORMEventHandler extends coldbox.system.EventHandler

Any clue what is going on here? I did a search for this error and
nothing came up (so I'm sorry if this has been answered).

Here is the reason I need this, some of my ORM objects have settings
and other items injected into them, which require eventHandling to be
turned on and an eventHandler specified.

Any help is appreciated.

Thanks,
Cory

The ORMEvent handler is not for standard ColdBox events, if I am reading you
correctly there. If you are wanting this feature then you need to use the
property with the inject as per normal injection would be.

Have you got an example of what you are doing to cause this?

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Cory Miller
Sent: Friday, 8 April 2011 4:15 AM
To: ColdBox Platform
Subject: [coldbox:9268] Weird error when trying to use orm event handling

in

my testing application.cfc

Alright - I have a weird error:

coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.runtime.ObjectDuplicator$UnableToDuplicateCFCException :
Unable to duplicate a ColdFusion
Component.org.hibernate.HibernateException:
coldfusion.runtime.CustomException: ColdBox Controller Not Found]

This is occurring when I try to run integration tests using MXUnit and

Eclipse.

This is in my site/test/Application.cfc file:

  <cfset this.ormsettings["eventHandling"] = true>
  <cfset this.ormsettings["eventHandler"] =
"site.model.ORMEventHandler">

site.model.ORMEventHandler extends coldbox.system.EventHandler

Any clue what is going on here? I did a search for this error and nothing

came

up (so I'm sorry if this has been answered).

Here is the reason I need this, some of my ORM objects have settings and
other items injected into them, which require eventHandling to be turned

on

Hey Andrew - thx for quick reply.

I am not sure I completely understand what you are trying to say.

Basically here is the scenario:

1) Doing an integration test on handlerA.doSomething
2) handlerA.doSomething contains the following code (prc.store is set
in onRequestStart)

var test = prc.store.getContentObjects(); (this function uses the
property SKIN_CONFIG_FILE in below code fragment)

3) prc.store is a reference to a store object with the definistion as
follows:

<cfcomponent persistent="true" entityname="Store" output="false">

  <cfproperty name="CONFIG_DEFAULTS"
inject="model:configKeyService:getDefaultKeys" scope="variables"
persistent="false">
  <cfproperty name="SKIN_CONFIG_FILE"
inject="coldbox:setting:skinConfigFile" scope="variables"
persistent="false">

These two properties are always populated in the app when I inspect
prc.store, yet they are NULL when I do integration testing without
ormsettings['eventHandling']=true (and specify an event handler) in my
test/application.cfc file.

I am pretty sure this setting needs to be true to allow for DI into
ORM objects (I have confirmed this in the main app as well - both
properties are NULL if this setting is false and no eventhandler is
specified).

Does this make sense? The basis for the post is when I try to set it
to true in the testing application.cfc, I get the error:

coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.runtime.ObjectDuplicator$UnableToDuplicateCFCException :
Unable to duplicate a ColdFusion
Component.org.hibernate.HibernateException:
coldfusion.runtime.CustomException: ColdBox Controller Not Found]

So even if I am not doing something right with my test, having this
setting = true and specifying an event handler causes all sorts of
chaos.

Cory

How is your unit test written, what is in setup and what test is failing,
can you show this snippet of code.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Cory Miller
Sent: Friday, 8 April 2011 4:50 AM
To: ColdBox Platform
Subject: [coldbox:9274] Re: Weird error when trying to use orm event
handling in my testing application.cfc

Hey Andrew - thx for quick reply.

I am not sure I completely understand what you are trying to say.

Basically here is the scenario:

1) Doing an integration test on handlerA.doSomething
2) handlerA.doSomething contains the following code (prc.store is set in
onRequestStart)

var test = prc.store.getContentObjects(); (this function uses the property
SKIN_CONFIG_FILE in below code fragment)

3) prc.store is a reference to a store object with the definistion as
follows:

<cfcomponent persistent="true" entityname="Store" output="false">

  <cfproperty name="CONFIG_DEFAULTS"
inject="model:configKeyService:getDefaultKeys" scope="variables"
persistent="false">
  <cfproperty name="SKIN_CONFIG_FILE"
inject="coldbox:setting:skinConfigFile" scope="variables"
persistent="false">

These two properties are always populated in the app when I inspect
prc.store, yet they are NULL when I do integration testing without
ormsettings['eventHandling']=true (and specify an event handler) in my
test/application.cfc file.

I am pretty sure this setting needs to be true to allow for DI into ORM

objects

(I have confirmed this in the main app as well - both properties are NULL

if

this setting is false and no eventhandler is specified).

Does this make sense? The basis for the post is when I try to set it to

true in

the testing application.cfc, I get the error:

coldfusion.xml.rpc.CFCInvocationException:
[coldfusion.runtime.ObjectDuplicator$UnableToDuplicateCFCException :
Unable to duplicate a ColdFusion
Component.org.hibernate.HibernateException:
coldfusion.runtime.CustomException: ColdBox Controller Not Found]

So even if I am not doing something right with my test, having this

setting =

<cfcomponent extends="coldbox.system.testing.BaseTestCase"
appMapping="/site">

  <cffunction name="setUp" returntype="void" output="false">
    <cfscript>

    super.setup();
    //Initialize app level dependancies
    execute("admin.Main.onAppInit");

    // Login a valid user
    url.username='admin';
    url.password='admin';
    execute("admin.User.doLogin");
    execute("admin.Main.onRequestStart");
    </cfscript>
  </cffunction>

  <cffunction name="testindex">
    <cfscript>
    var event = "";

    event = execute("admin.Page.index");
    debug(event.getCollection());
                debug(event.getCollection(private=true));
    assertEquals("admin.Page.list", event.getValue("setnextevent",""),
"Relocation Test");

    </cfscript>
  </cffunction>
</cfcomponent>

When I do NOT have ormsettings['eventhandling'] = true I get this
error:

variable SKIN_CONFIG_FILE is not defined....

from this function inside Store.cfc:

  <cffunction name="getContentObjectArray" access="public"
returntype="array" output="false">
    <cfscript>

    var xmlFile = XMLParse(ExpandPath(SKIN_CONFIG_FILE));
    var returnArray = ArrayNew(1);

    try{
      var objects = XMLSearch(xmlFile,'/stores/
store[@id="#this.getStoreID()#"]/contentObjects/contentObject');

      for(var i=1;i <= ArrayLen(objects);i++){
        var tempStruct = StructNew();
        tempStruct.display = objects[i].display.XmlText;
        tempStruct.value = objects[i].value.XmlText;
        ArrayAppend(returnArray,tempStruct);
      }
    }catch(any e){}

    return returnArray;

    </cfscript>
  </cffunction>

Thing is, I can do other tests fine (the admin.User.doLogin test case
is running fine) but when I try and set eventhandling=true I can't run
any tests at all.

-Cory

Please don't tell me that you have this defined in your eventHandler?

SKIN_CONFIG_FILE

And you setup should be something only like this.

  <cffunction name="setUp" returntype="void" output="false">
    <cfscript>
      setAppMapping("/");
      setConfigMapping(ExpandPath(instance.AppMapping &
"/config/coldbox.cfc"));
      super.setup();
    </cfscript>
  </cffunction>

Hope that helps, setup is wrapped around each test method call, and as you
can see in my setup. I am initialising the application and loading in the
application config file.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Cory Miller
Sent: Friday, 8 April 2011 6:27 AM
To: ColdBox Platform
Subject: [coldbox:9278] Re: Weird error when trying to use orm event
handling in my testing application.cfc

<cfcomponent extends="coldbox.system.testing.BaseTestCase"
appMapping="/site">

  <cffunction name="setUp" returntype="void" output="false">
    <cfscript>

    super.setup();
    //Initialize app level dependancies
    execute("admin.Main.onAppInit");

    // Login a valid user
    url.username='admin';
    url.password='admin';
    execute("admin.User.doLogin");
    execute("admin.Main.onRequestStart");
    </cfscript>
  </cffunction>

  <cffunction name="testindex">
    <cfscript>
    var event = "";

    event = execute("admin.Page.index");
    debug(event.getCollection());
                debug(event.getCollection(private=true));
    assertEquals("admin.Page.list",
event.getValue("setnextevent",""),
"Relocation Test");

    </cfscript>
  </cffunction>
</cfcomponent>

When I do NOT have ormsettings['eventhandling'] = true I get this
error:

variable SKIN_CONFIG_FILE is not defined....

from this function inside Store.cfc:

  <cffunction name="getContentObjectArray" access="public"
returntype="array" output="false">
    <cfscript>

    var xmlFile = XMLParse(ExpandPath(SKIN_CONFIG_FILE));
    var returnArray = ArrayNew(1);

    try{
      var objects = XMLSearch(xmlFile,'/stores/
store[@id="#this.getStoreID()#"]/contentObjects/contentObject');

      for(var i=1;i <= ArrayLen(objects);i++){
        var tempStruct = StructNew();
        tempStruct.display =
objects[i].display.XmlText;
        tempStruct.value = objects[i].value.XmlText;
        ArrayAppend(returnArray,tempStruct);
      }
    }catch(any e){}

    return returnArray;

    </cfscript>
  </cffunction>

Thing is, I can do other tests fine (the admin.User.doLogin test case is

running

fine) but when I try and set eventhandling=true I can't run any tests at

all.

SKIN_CONFIG_FILE is a coldbox setting injected into the store.cfc orm
object (which is why I am setting the eventhandling=true - required to
inject into orm objects is what I was told - if this isn't right then
that is my problem - I did some tests on the app and the injected
properties are not defined when this setting is false).

The reason I am executing admin.main.onRequestStart and
admin.user.dologin in setup() is because all of these handlers are
part of an admin and require an authorized user to be logged in - this
code will be ran before all handler methods so I see no reason to
place it in each individual method.

Not sure if I clarified or not but I have successful integration tests
(not unit tests yet) being ran - i am simply trying to figure out why
I am receiving the above error when I try to set an eventhandler in
application.cfc.

Thanks for helping btw.

ORMEventHandling is for events like preUpdate, preSave, postUpdate etc.

These events are good for adding say Auditing to your ORM Objects, or maybe
you want to default a date/time to now on save etc.

I would also be very interested to see what is in you ORMEventHandler, but
no this is NOT for what you think it is as I stated earlier. My guess is
that if it is not being injected into the domain, then the domain is not in
a convention defined by your application.

Hope that helps.

No problems on the helping, if you aren't sure it can all be very daunting.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Cory Miller
Sent: Friday, 8 April 2011 11:37 AM
To: ColdBox Platform
Subject: [coldbox:9290] Re: Weird error when trying to use orm event
handling in my testing application.cfc

SKIN_CONFIG_FILE is a coldbox setting injected into the store.cfc orm

object

(which is why I am setting the eventhandling=true - required to inject

into

orm objects is what I was told - if this isn't right then that is my

problem - I did

some tests on the app and the injected properties are not defined when

this

setting is false).

The reason I am executing admin.main.onRequestStart and
admin.user.dologin in setup() is because all of these handlers are part of

an

admin and require an authorized user to be logged in - this code will be

ran

before all handler methods so I see no reason to place it in each

individual

method.

Not sure if I clarified or not but I have successful integration tests

(not unit

tests yet) being ran - i am simply trying to figure out why I am receiving

the

I realize the ORM Event Handler is used for this - we are using it to
handle preUpdate and preInsert events but it is also required to allow
DI into Entity objects in Coldbox:

http://groups.google.com/group/coldbox/browse_thread/thread/595e6f1a445782aa/68746a51c1ba719c?#68746a51c1ba719c

This doesn't explain everything, but it does mention that in order for
DI to work in Entity objects eventhandling MUST be turned on for ORM.

Like I said - all tests up to this one are working (as I had
eventhandling=false and forgot I had this false) - when I got to this
test I remembered this caveat in ORM Entity objects and DI. Turned it
to true and ALL tests failed with this error.

If you have your tests working, maybe create an ORMEventHandler that
extends coldbox.system.EventHandler and set your testing
application.cfc to use ORM event handling. I'd like to see if you
have the same error - it is like the event handling code can't find
the coldbox controller for the testing 'app'.

Thanks,
Cory

Also - official wiki docs:

http://wiki.coldbox.org/wiki/Extras:ORMEventHandler.cfm

Specifically under the heading "Entity Injection Capabilities"

-Cory

So let me get this write.

You created an ORMEventHandler and placed it somewhere within your
application, you then setup the application to enable this and told the
application where to find the ORMEventHandler. And last but not least you
are extending the right Component for the ORMEventHandling?

I think I can see you problem, you are using

site.model.ORMEventHandler extends coldbox.system.EventHandler

when you should be using what that wiki page is says to use.

component extends="coldbox.system.orm.hibernate.EventHandler"{
}

Regards,
Andrew Scott
http://www.andyscott.id.au/

You are right - I had that wrong in the post, but it was actually what
you said in the code (not sure why I typed
coldbox.system.EventHandler). So that is the same too.

-Cory

Kk, and the ORMEventHandler resides in the same directory as where your
other entities are stored?

I am not getting your problem, so it sounds like a very simple configuration
problem.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Cory Miller
Sent: Saturday, 9 April 2011 7:00 AM
To: ColdBox Platform
Subject: [coldbox:9321] Re: Weird error when trying to use orm event
handling in my testing application.cfc

You are right - I had that wrong in the post, but it was actually what you

said

in the code (not sure why I typed coldbox.system.EventHandler). So that

is