Search code examples
restfitnesse

Fitnesse smartrics.rest.fitnesse.fixture.RestFixture.setBaseUrl


I have a requirement for a test to make a call to one REST endpoint that generates a security token then make a second to the actual system under test. In order to do this I am using smartrics.rest.fitnesse.fixture.RestFixture and setting the baseurl in instantiation to the first base. I am trying to make this call and then set the new baseurl to the new location but am having trouble doing so.

It appears from perusing the code that there is a method setBaseUrl(Url url) but I cannot find an example of using this and am failing trying to figure it out myself.

Has anyone had any luck with this or is there another, better/easier way to achieve this?


Solution

  • The problem lies in RestFixture:processRow - since it uses Java reflection, it attempts to call method without parameters. This will fail since setBaseUrl accepts one argument (Url). I have tried one modification, though not the best way to achieve it - current code RestFixture v3.0 (RestFixture.processRow()):

    method1 = getClass().getMethod(methodName);
    method1.invoke(this);
    

    Modified code in RestFixture.processRow():

    Method[] methods = getClass().getMethods();
    
    int i = 0;
    for(i = 0; i < methods.length; i++){
        if(methodName.equals(methods[i].getName())){
            method1 = methods[i];
            break;
        }
    }
    
    Class[] paramTypes = method1.getParameterTypes();
    
    List<Object> params = new ArrayList<Object>();
    
    for(i = 0; i < paramTypes.length; i++){
        String cellText = row.getCell(i+1).text();
        Object param = paramTypes[i].getConstructor(String.class).newInstance(cellText);
        params.add(param);
    }
    
    method1.invoke(this, params.toArray());
    

    Once this modification is done (you might need to add required imports - java.lang.InstantiationException, java.lang.Object, java.util.ArrayList; and an exception handler for InstantiationException), re-build the RestFixture and that should work.