|
| 1 | +component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { |
| 2 | + |
| 3 | + function beforeAll() { |
| 4 | + // Need WARN-or-lower for the LDEV-6340 bug message to land in orm.log; |
| 5 | + // default server level may be ERROR. logging.cfc uses the same pattern. |
| 6 | + configImport( type: "server", password: request.SERVERADMINPASSWORD, data: { |
| 7 | + loggers: { |
| 8 | + orm: { |
| 9 | + appender : "resource", |
| 10 | + appenderArguments: { path: "{lucee-config}/logs/orm.log" }, |
| 11 | + level : "trace", |
| 12 | + layout : "classic" |
| 13 | + } |
| 14 | + } |
| 15 | + }); |
| 16 | + } |
| 17 | + |
| 18 | + function run( testResults, testBox ) { |
| 19 | + |
| 20 | + describe( "mappedSuperClass — LDEV-6340 log noise", function() { |
| 21 | + |
| 22 | + it( "User extends mappedSuperClass BaseEntity — entity ops work and log stays clean", function() { |
| 23 | + var appId = createUUID(); |
| 24 | + var offsetBefore = getLogLength(); |
| 25 | + |
| 26 | + var result = _InternalRequest( |
| 27 | + template: "#uri( "basic" )#/index.cfm", |
| 28 | + url : { appId: appId } |
| 29 | + ); |
| 30 | + expect( trim( result.filecontent ) ).toBe( "ok" ); |
| 31 | + |
| 32 | + var logContent = getLogContentSince( offsetBefore ); |
| 33 | + systemOutput( "LDEV-6340 LOG: [#logContent#]", true ); |
| 34 | + |
| 35 | + expect( logContent ).notToInclude( "failed to resolve parent entity" ); |
| 36 | + expect( logContent ).notToInclude( "Entity [BaseEntity] does not exist" ); |
| 37 | + }); |
| 38 | + |
| 39 | + }); |
| 40 | + |
| 41 | + describe( "mappedSuperClass — property inheritance shapes", function() { |
| 42 | + |
| 43 | + it( "parent declares @Id — child inherits the id field", function() { |
| 44 | + var result = _InternalRequest( |
| 45 | + template: "#uri( "parentId" )#/index.cfm", |
| 46 | + url : { appId: createUUID() } |
| 47 | + ); |
| 48 | + expect( trim( result.filecontent ) ).toBe( "ok" ); |
| 49 | + }); |
| 50 | + |
| 51 | + it( "multi-level chain — child inherits properties from grand-mappedSuperClass", function() { |
| 52 | + var result = _InternalRequest( |
| 53 | + template: "#uri( "multiLevel" )#/index.cfm", |
| 54 | + url : { appId: createUUID() } |
| 55 | + ); |
| 56 | + expect( trim( result.filecontent ) ).toBe( "ok" ); |
| 57 | + }); |
| 58 | + |
| 59 | + it( "mappedSuperClass + real entity TPH inheritance — Car gets mappedSuperClass props two levels up", function() { |
| 60 | + var result = _InternalRequest( |
| 61 | + template: "#uri( "mixedInheritance" )#/index.cfm", |
| 62 | + url : { appId: createUUID() } |
| 63 | + ); |
| 64 | + expect( trim( result.filecontent ) ).toBe( "ok" ); |
| 65 | + }); |
| 66 | + |
| 67 | + it( "child redeclares parent property with different column + length — child wins", function() { |
| 68 | + var result = _InternalRequest( |
| 69 | + template: "#uri( "attrOverride" )#/index.cfm", |
| 70 | + url : { appId: createUUID() } |
| 71 | + ); |
| 72 | + expect( trim( result.filecontent ) ).toBe( "ok" ); |
| 73 | + }); |
| 74 | + |
| 75 | + }); |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + private string function uri( required string scenario ) { |
| 80 | + return getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ) & "mappedSuperClass/" & arguments.scenario; |
| 81 | + } |
| 82 | + |
| 83 | + private numeric function getLogLength() { |
| 84 | + var logFile = expandPath( "{lucee-config}/logs/orm.log" ); |
| 85 | + if ( !fileExists( logFile ) ) return 0; |
| 86 | + return len( fileRead( logFile ) ); |
| 87 | + } |
| 88 | + |
| 89 | + private string function getLogContentSince( required numeric offset ) { |
| 90 | + var logFile = expandPath( "{lucee-config}/logs/orm.log" ); |
| 91 | + if ( !fileExists( logFile ) ) return ""; |
| 92 | + var content = fileRead( logFile ); |
| 93 | + if ( len( content ) <= arguments.offset ) return ""; |
| 94 | + return content.mid( arguments.offset + 1, len( content ) ); |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments