https://issues.apache.org/jira/browse/TAP5-2107


On Tue, Apr 16, 2013 at 8:17 PM, Dmitry Gusev <dmitry.gu...@gmail.com>wrote:

> Here's a piece of SeleniumTestCase that does what I wanted:
>
>     private ServletContainerRunner servletContainerRunner;
>
>
>
>     public Registry getRegistry()
>
>     {
>
>         if (servletContainerRunner instanceof Jetty7Runner)
>
>         {
>
>             Server server = ((Jetty7Runner) servletContainerRunner
> ).getServer();
>
>
>
>             WebAppContext context = (WebAppContext) server.getHandler();
>
>
>
>             ServletContext servletContext = context.getServletContext();
>
>
>
>             Object registry = servletContext.getAttribute(TapestryFilter.
> REGISTRY_CONTEXT_NAME);
>
>
>
>             return (Registry) registry;
>
>         }
>
>
>
>         if (servletContainerRunner instanceof Tomcat6Runner)
>
>         {
>
>             try
>
>             {
>
>                 Field field = Tomcat6Runner.class.getDeclaredField(
> "tomcatServer");
>
>                 field.setAccessible(true);
>
>
>
>                 Embedded server = (Embedded) field.get(
> servletContainerRunner);
>
>                 Engine engine = (Engine) server.getContainer();
>
>                 Host host = (Host) engine.findChild("localhost");
>
>                 Context context = (Context) host.findChildren()[0];
>
>                 ServletContext servletContext =
> context.getServletContext();
>
>
>
>                 Object registry =
> servletContext.getAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME);
>
>
>
>                 return (Registry) registry;
>
>             }
>
>             catch (Exception e)
>
>             {
>
>                 throw new RuntimeException(e);
>
>             }
>
>         }
>
>
>
>         throw new RuntimeException("Unsupported runner " +
> servletContainerRunner);
>
>     }
>
>
>
>     protected Runnable launchWebServer(String container, String
> webAppFolder, String contextPath, int port, int sslPort)
>
>             throws Exception
>
>     {
>
>         final ServletContainerRunner runner;
>
>         if (TOMCAT_6.equals(container))
>
>             runner = new Tomcat6Runner(webAppFolder, contextPath, port,
> sslPort);
>
>         else if (JETTY_7.equals(container))
>
>             runner = new Jetty7Runner(webAppFolder, contextPath, port,
> sslPort);
>
>         else
>
>             throw new RuntimeException("Unknown servlet container: " +
> container);
>
>
>         this.servletContainerRunner = runner;
>
> Method getRegistry() could be easily implemented by ServletContainerRunner
> interface without any reflection.
> It would be nice to have it in there.
> Should I file a JIRA for this or somebody of committers will integrate
> this?
>
> On Tue, Apr 16, 2013 at 7:01 PM, Dmitry Gusev <dmitry.gu...@gmail.com>wrote:
>
>> Michael,
>>
>> I already use RegistryBuilder in some of my tests.
>> It allows me to test services, but in this case I'm working with my
>> application using Java API.
>>
>> With SeleniumTestCase I can trigger my application handlers using HTTP
>> requests via Selenium.
>> In this case my application already running and it has constructed
>> Registry instance and I'd like to get that instance somehow.
>>
>> I'm looking at implementation of SeleniumTestCase and see that there's
>> not API for obtaining that Registry instance directly.
>> Though, I can see that instance in debugger in my IDE, I think I'll use
>> reflection to get it.
>>
>> On Tue, Apr 16, 2013 at 6:50 PM, Michael Prescott <
>> michael.r.presc...@gmail.com> wrote:
>>
>>> You can use the RegistryBuilder to instantiate your tapestry services via
>>> Tapestry IOC, I'm finding that very handy.  That's described here:
>>>
>>> http://tapestry.apache.org/starting-the-ioc-registry.html
>>>
>>>
>>> On 16 April 2013 10:38, Dmitry Gusev <dmitry.gu...@gmail.com> wrote:
>>>
>>> > I'm writing integration tests (using SeleniumTestCase) and want to make
>>> > assertions against database state.
>>> >
>>> > I was thinking about getting one of my DAO services (or JPA
>>> > EntityManager/Source) and use it to run queries.
>>> >
>>> > Is it possible somehow? Or should I just write another client code that
>>> > would access database from integration tests?
>>> >
>>> > --
>>> > Dmitry Gusev
>>> >
>>> > AnjLab Team
>>> > http://anjlab.com
>>> >
>>>
>>
>>
>>
>> --
>> Dmitry Gusev
>>
>> AnjLab Team
>> http://anjlab.com
>>
>
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Reply via email to