Permalink
Browse files

fixed #1380

WireBox doesn't observe inherited annotations
  • Loading branch information...
1 parent 2e9c35a commit cf9d11891fd11e9f6fe537de1f3c8a19a486865c @lmajano lmajano committed Jul 16, 2012
@@ -417,7 +417,7 @@ Description :
// Do we have an incoming target id?
if( NOT len(arguments.targetID) ){
// need to get metadata to verify identity
- md = getMetadata(arguments.target);
+ md = instance.utility.getInheritedMetaData(arguments.target, getBinder().getStopRecursions());
// We have identity now, use the full location path
arguments.targetID = md.path;
}
@@ -426,9 +426,9 @@ Description :
if( NOT instance.binder.mappingExists( arguments.targetID ) ){
// No mapping found, means we need to map this object for the first time.
// Is md retreived? If not, retrieve it as we need to register it for the first time.
- if( isSimpleValue(md) ){ md = getMetadata(arguments.target); }
+ if( isSimpleValue(md) ){ md = instance.utility.getInheritedMetaData(arguments.target, getBinder().getStopRecursions()); }
// register new mapping instance
- registerNewInstance(arguments.targetID,md.path);
+ registerNewInstance(arguments.targetID, md.path);
// get Mapping created
arguments.mapping = instance.binder.getMapping( arguments.targetID );
// process it with current metadata
@@ -575,7 +575,7 @@ Description :
md = arguments.metadata;
}
else{
- md = getComponentMetadata( instance.path );
+ md = arguments.binder.utility.getInheritedMetaData(instance.path, arguments.binder.getStopRecursions());
}
// Store Metadata
@@ -887,33 +887,6 @@ Description :
}//end loop of functions
}//end if functions found
- // Start Registering inheritances, if the exists
- if ( structKeyExists(md, "extends")
- AND
- stopClassRecursion(md.extends.name,arguments.binder) EQ FALSE){
- // Recursive lookup
- processDIMetadata(arguments.binder, md.extends, arguments.dependencies);
- }
- </cfscript>
- </cffunction>
-
- <!--- stopClassRecursion --->
- <cffunction name="stopClassRecursion" access="private" returntype="any" hint="Should we stop recursion or not due to class name found: Boolean" output="false" colddoc:generic="Boolean">
- <cfargument name="classname" required="true" hint="The class name to check">
- <cfargument name="binder" required="true" hint="The binder requesting the processing"/>
- <cfscript>
- var x = 1;
- var stopRecursions = arguments.binder.getStopRecursions();
- var stopLen = arrayLen(stopRecursions);
-
- // Try to find a match
- for(x=1;x lte stopLen; x=x+1){
- if( CompareNoCase( stopRecursions[x], arguments.classname) eq 0){
- return true;
- }
- }
-
- return false;
</cfscript>
</cffunction>
@@ -0,0 +1,11 @@
+<cfcomponent extends="class2" displayName="class1" output="true" scope="server" annotationClass1Only="Class1Value" annotationClass1and2and3="class1Value">
+ <cfproperty name="propClass1Only" default="class1Value">
+ <cfproperty name="propClass1and2and3" default="class1Value">
+
+ <cffunction name="funcClass1Only" hint="Function defined in Class1">
+ </cffunction>
+
+ <cffunction name="funcClass1and2and3" hint="Function defined in Class1">
+ </cffunction>
+
+</cfcomponent>
@@ -0,0 +1,11 @@
+<cfcomponent extends="class3" displayName="class2" output="false" scope="session" annotationClass2Only="Class2Value" annotationClass1and2and3="class2Value">
+ <cfproperty name="propClass2Only" default="class2Value">
+ <cfproperty name="propClass1and2and3" default="class2Value">
+
+ <cffunction name="funcClass2Only" hint="Function defined in Class2">
+ </cffunction>
+
+ <cffunction name="funcClass1and2and3" hint="Function defined in Class2">
+ </cffunction>
+
+</cfcomponent>
@@ -0,0 +1,11 @@
+<cfcomponent displayName="class3" scope="request" annotationClass3Only="Class3Value" annotationClass1and2and3="class3Value">
+ <cfproperty name="propClass3Only" default="class3Value">
+ <cfproperty name="propClass1and2and3" default="class3Value">
+
+ <cffunction name="funcClass3Only" hint="Function defined in Class3">
+ </cffunction>
+
+ <cffunction name="funcClass1and2and3" hint="Function defined in Class3">
+ </cffunction>
+
+</cfcomponent>
@@ -2,18 +2,144 @@
<cfscript>
function setup(){
util = CreateObject("component","coldbox.system.core.util.Util");
+ class1 = CreateObject("component","coldbox.testing.cases.core.util.class1");
}
-
+
function isInstanceCheck(){
test = createObject("component","coldbox.testing.testhandlers.BaseTest");
assertTrue( util.isInstanceCheck( test, "coldbox.system.EventHandler") );
-
+
test = createObject("component","coldbox.testing.testhandlers.ehTest");
assertTrue( util.isInstanceCheck( test, "coldbox.system.EventHandler") );
-
+
test = createObject("component","coldbox.testing.testhandlers.TestNoInheritance");
- assertFalse( util.isInstanceCheck( test, "coldbox.system.EventHandler") );
+ assertFalse( util.isInstanceCheck( test, "coldbox.system.EventHandler") );
}
-
+
+ function testStopClassRecursion(){
+ stopRecursions = ["com.foo.bar","com.foobar","coldbox.system.coldbox"];
+
+ makePublic(util,"stopClassRecursion");
+ assertFalse( util.stopClassRecursion( "com.google", stopRecursions ) );
+ assertTrue( util.stopClassRecursion( "com.foobar", stopRecursions ) );
+ }
+
+ function testGetInheritedMetaData(){
+ md = util.getInheritedMetaData(class1);
+ testGetInheritedMetaDataHelper(md);
+
+ md = util.getInheritedMetaData("class1");
+ testGetInheritedMetaDataHelper(md);
+
+ }
+
+ function testGetInheritedMetaDataStopRecursion(){
+ stopRecursions = ["coldbox.testing.cases.core.util.class2"];
+
+ md = util.getInheritedMetaData(class1,stopRecursions);
+ testGetInheritedMetaDataStopRecursionHelper(md);
+
+ md = util.getInheritedMetaData("class1",stopRecursions);
+ testGetInheritedMetaDataStopRecursionHelper(md);
+
+ }
+
+ private function testGetInheritedMetaDataHelper(md){
+
+ assertTrue( structKeyExists( md, "inheritanceTrail") );
+ assertEquals( arrayLen(md.inheritanceTrail), 4 );
+ assertEquals( md.inheritanceTrail[1], "coldbox.testing.cases.core.util.class1" );
+ assertEquals( md.inheritanceTrail[2], "coldbox.testing.cases.core.util.class2" );
+ assertEquals( md.inheritanceTrail[3], "coldbox.testing.cases.core.util.class3" );
+ assertEquals( md.inheritanceTrail[4], "WEB-INF.cftags.component" );
+
+ assertEquals( md.output, true );
+ assertEquals( md.scope, "server" );
+
+ assertTrue( structKeyExists( md, "annotationClass1Only") );
+ assertTrue( structKeyExists( md, "annotationClass2Only") );
+ assertTrue( structKeyExists( md, "annotationClass3Only") );
+ assertTrue( structKeyExists( md, "annotationClass1and2and3") );
+ assertEquals( md.annotationClass1Only, "class1Value" );
+ assertEquals( md.annotationClass2Only, "class2Value" );
+ assertEquals( md.annotationClass3Only, "class3Value" );
+ assertEquals( md.annotationClass1and2and3, "class1Value" );
+
+
+ assertEquals( arrayLen(md.functions), 4 );
+ assertTrue( itemExists(md.functions, "funcClass1Only") );
+ assertEquals( getItemKey(md.functions, "funcClass1Only", "hint"), "Function defined in Class1" );
+ assertTrue( itemExists(md.functions, "funcClass2Only") );
+ assertEquals( getItemKey(md.functions, "funcClass2Only", "hint"), "Function defined in Class2" );
+ assertTrue( itemExists(md.functions, "funcClass3Only") );
+ assertEquals( getItemKey(md.functions, "funcClass3Only", "hint"), "Function defined in Class3" );
+ assertTrue( itemExists(md.functions, "funcClass1and2and3") );
+ assertEquals( getItemKey(md.functions, "funcClass1and2and3", "hint"), "Function defined in Class1" );
+
+ assertEquals( arrayLen(md.properties), 4 );
+ assertTrue( itemExists(md.properties, "propClass1Only") );
+ assertEquals( getItemKey(md.properties, "propClass1Only", "default"), "class1Value" );
+ assertTrue( itemExists(md.properties, "propClass2Only") );
+ assertEquals( getItemKey(md.properties, "propClass2Only", "default"), "class2Value" );
+ assertTrue( itemExists(md.properties, "propClass3Only") );
+ assertEquals( getItemKey(md.properties, "propClass3Only", "default"), "class3Value" );
+ assertTrue( itemExists(md.properties, "propClass1and2and3") );
+ assertEquals( getItemKey(md.properties, "propClass1and2and3", "default"), "class1Value" );
+
+ }
+
+ private function testGetInheritedMetaDataStopRecursionHelper(md){
+
+ assertTrue( structKeyExists( md, "inheritanceTrail") );
+ assertEquals( arrayLen(md.inheritanceTrail), 1 );
+ assertEquals( md.inheritanceTrail[1], "coldbox.testing.cases.core.util.class1" );
+
+ assertEquals( md.output, true );
+ assertEquals( md.scope, "server" );
+
+ assertTrue( structKeyExists( md, "annotationClass1Only") );
+ assertFalse( structKeyExists( md, "annotationClass2Only") );
+ assertFalse( structKeyExists( md, "annotationClass3Only") );
+ assertTrue( structKeyExists( md, "annotationClass1and2and3") );
+ assertEquals( md.annotationClass1Only, "class1Value" );
+ assertEquals( md.annotationClass1and2and3, "class1Value" );
+
+ assertEquals( arrayLen(md.functions), 2 );
+ assertTrue( itemExists(md.functions, "funcClass1Only") );
+ assertEquals( getItemKey(md.functions, "funcClass1Only", "hint"), "Function defined in Class1" );
+ assertFalse( itemExists(md.functions, "funcClass2Only") );
+ assertFalse( itemExists(md.functions, "funcClass3Only") );
+ assertTrue( itemExists(md.functions, "funcClass1and2and3") );
+ assertEquals( getItemKey(md.functions, "funcClass1and2and3", "hint"), "Function defined in Class1" );
+
+ assertEquals( arrayLen(md.properties), 2 );
+ assertTrue( itemExists(md.properties, "propClass1Only") );
+ assertEquals( getItemKey(md.properties, "propClass1Only", "default"), "class1Value" );
+ assertFalse( itemExists(md.properties, "propClass2Only") );
+ assertFalse( itemExists(md.properties, "propClass3Only") );
+ assertTrue( itemExists(md.properties, "propClass1and2and3") );
+ assertEquals( getItemKey(md.properties, "propClass1and2and3", "default"), "class1Value" );
+
+ }
+
+
+ private function itemExists(itemArray, itemName){
+ for(i=1; i<=arrayLen(itemArray); i++){
+ if(itemArray[i].name == itemName){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private function getItemKey(itemArray, itemName, key){
+ for(i=1; i<=arrayLen(itemArray); i++){
+ if(itemArray[i].name == itemName){
+ return itemArray[i][key];
+ }
+ }
+ fail("Item '#itemName#' doesn't exists.");
+ }
+
</cfscript>
</cfcomponent>
Oops, something went wrong. Retry.

0 comments on commit cf9d118

Please sign in to comment.