Hi Peter,
what about following:
------------
1- you have to get a reference to the project used by the AntBuilder.
Sadly AntBuilder.getProject() is protected (should probably be changed).
The easiest way currently is probably to define the ant property again
and provide it your own Project instance
def project = new Project()
ant = new AntBuilder(project)
2- place your closure as reference into the project
def c = {
HttpInvokerProxyFactoryBean factoryBean = new
HttpInvokerProxyFactoryBean()
factoryBean.setServiceUrl(step.webtestProperties.ssUrl)
...
}
project.references['foo'] = c
3- in your webtest, get this reference - the closure - and execute it
ant.groovy("step.project.references['foo']()")
------------
I can imagine that this would be of general interest when using webtest
(or in fact simply ant) from AntBuilder and that a general helper like
that could make sense:
ant.doFromAnt { ... some code here ...}
with
doFromAnt = { closure ->
project.references['somekey'] = c // 'somekey' has to be computed with
a counter or something like that
ant.groovy { "step.project.references['somekey']()" }
}
Let me know if you play with this idea.
Cheers,
Marc.
--
Blog: http://mguillem.wordpress.com
Peter Ledbrook wrote:
> On 19/09/2007, Peter Ledbrook <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> Sorry for hitting the list again, but I have a significant problem
>> with the functional tests of my Grails app.
>>
>> I have a security service which is accessed via Spring's HttpInvoker,
>> and a user interface that allows a user to configure that service. For
>> my functional tests, I want to test that changes made via the user
>> interface are reflected in the responses from the security service.
>>
>> I am currently creating webtests and adding some 'assert' statements
>> between steps that access the security service and check the response.
>> However, this isn't working because the security service calls are
>> happening before any of the steps within a single webtest (I assume
>> because WebTest builds the test in memory before executing it once the
>> closure has completed).
>>
>> So, is it feasible to mix webtest steps and calls to a remote service
>> like this? One option might be to embed calls to the security service
>> in 'groovy' or 'scriptStep' steps, but in that case, how do I pass the
>> security service client object and other parameters into the step? Are
>> there any other approaches that I can take?
>>
>> Thanks for any help,
>>
>> Peter
>
> If anyone's interested, I have gone for a really horrible hack by
> adding this group to the beginning of each webtest:
>
>
> ant.group(description: 'Bind the security service to Groovy steps.'){
> // Store the security service URL in a webtest property
> storeProperty(
> property: 'ssUrl',
> value:
> "${configMap.protocol}://${configMap.host}:${configMap.port}/\
> ${configMap.basepath}/httpinvoker/SecurityService")
>
> // Store the security service client in the webtest's binding.
> // Big hack!
> groovy('''\
> import net.ixico.security.IxicoSecurityService
> import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
>
> HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean()
> factoryBean.setServiceUrl(step.webtestProperties.ssUrl)
> factoryBean.setServiceInterface(IxicoSecurityService.class)
> factoryBean.afterPropertiesSet()
> def ss = factoryBean.getObject()
>
> def binding =
> step.webtestProperties.get('com.canoo.webtest.extension.groovy.GroovyInvoker#binding')
> binding.setVariable('securityService', ss)
> ''')
> }
>
> I can then use 'groovy' steps and reference the 'securityService'
> variable directly from within them.
>
> Cheers,
>
> Peter
> _______________________________________________
> WebTest mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/webtest
>
_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest