pa-media-group / xquery-unit

Automatically exported from code.google.com/p/xquery-unit
0 stars 0 forks source link

No flexibility in specifying Marklogic Connection URI #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The XQueryTestCase in xquery-unit looks for a specific file to pick xdbc 
connection string. These filenames are hardcoded into a field called 
DEFAULT_PROPS_LOCATIONS in the XQueryTestCase class. The setUp method searches 
for specific property file names as defined by DEFAULT_PROPS_LOCATIONS, loads 
the properties, searches for a very SPECIFIC property ("connectionUri")  to 
load the connectionURI, gets the session and stores it in a PRIVATE field. This 
session is used at multiple places in the class.

    In my code base, we store marklogic connection details in a file called shared.properties and we do not wish to replicate this in another property file. The shared.properties stores connection settings for each developer. Each developer connects to his own specific instance of marklogic and we generate the connection url dynamically depending on current logged in user. The hardcodings in XQueryTestCase makes it almost unusable in the current scenario. Probably the only workaround solution is to generate a  xdbc.property file dynamically while the test class is loaded but this is not a very elegant solution.

 It would be very helpful if we can pass the connectionURI from subclasses of XQueryTestCase, without having it hardcoded in specific property files, with specific connection property name. Having a protected method, "getConnectionURI" invoked from "setUp" would solve the purpose.

Original issue reported on code.google.com by rath.swa...@gmail.com on 16 Aug 2011 at 11:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Adding my work contact details.

Swaroop Rath
Desk Phone - 0044-2079484597
Email - swaroop.rath@uk.bp.com
BP Oil International Limited, 20 Canada Square, Canary Wharf, London, E14 5NJ

Original comment by rath.swa...@gmail.com on 16 Aug 2011 at 11:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
My earlier workaround suggestion to generate xdbc.property file dynamically in 
a static loader in a superclass of all xquery unit test cases might not work. 
This is because XQueryTestCase uses "getResourceAsStream" method on "Class" to 
load the property file and locations on classpath might not be writeable. 
Anyway, its far from neat and should not be attempted.

I instead found an easier workaround solution for the time being. Overload 
"setUp" and set the private field "sesssion" in XQueryTestCase using 
reflection. 

Not very confident if this would work for all class loaders. Example attached 
below.

An updated version of XQueryTestCase with session declared with protected 
modifier will be much helpful. 

Example of workaround solution - 

 protected void setUp() throws Exception {
        ContentSource cs = ContentSourceFactory.newContentSource(mlConnectionUri);
        Session mlSession = cs.newSession();
        Field fields[] = XQueryTestCase.class.getDeclaredFields();
        for (Field field : fields)
        {
            if (field.getType().equals(Session.class))
            {
                field.setAccessible(true);
                field.set(this, mlSession);
            }
        }
    }

- Swaroop Rath

Original comment by rath.swa...@gmail.com on 16 Aug 2011 at 3:36