Wicket tester mock server name

View: New views
4 Messages — Rating Filter:   Alert me  

Wicket tester mock server name

by Ted Vinke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

Seems a bit dumb I can't seem to get the following working. In my
application I have to so something special based on the domain the app
is running on. I ask for that domain in the following manner:

    String serverName =
getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName();
    // serverName is e.g. 'www.somedomain.com'

The problem: when testing in the Wicket tester serverName results in
'localhost'.

How can I set / mock
getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName()
to return a preset value, such as 'www.somedomain.com',  when accessing
my page in my unit test?

Any tips or hints to examples are greatly appreciated!!

Kind regards,
Ted

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Wicket tester mock server name

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

you can create your own subclass of mockhttpservletrequest and return
whatever you want. hooking it into wickettester should not be that
bad... if it is we can see if we can make it easier.

-igor

On Wed, Nov 4, 2009 at 8:27 AM, Ted Vinke <tvinke@...> wrote:

> Hi!
>
> Seems a bit dumb I can't seem to get the following working. In my
> application I have to so something special based on the domain the app is
> running on. I ask for that domain in the following manner:
>
>   String serverName =
> getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName();
>   // serverName is e.g. 'www.somedomain.com'
>
> The problem: when testing in the Wicket tester serverName results in
> 'localhost'.
>
> How can I set / mock
> getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName()
> to return a preset value, such as 'www.somedomain.com',  when accessing my
> page in my unit test?
>
> Any tips or hints to examples are greatly appreciated!!
>
> Kind regards,
> Ted
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Wicket tester mock server name

by Ted Vinke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have no experience mocking things with the Wicket tester. I've tried
things like

MockHttpServletRequest mock = tester.getServletRequest();
mock.setURL("http://www.domain.com");

in my test and a

@Override
    public UserSession newSession(Request request, Response response) {
        tester.setupRequestAndResponse();
        MockHttpServletRequest mockRequest = tester.getServletRequest();
        mockRequest.setURL("http://www.domain.com");
        return super.newSession(tester.getWicketRequest(),
tester.getWicketResponse());
    }

in a MockApplication which extends my real Application but I don't seem
to get the desired effect.

I'm happy to change the original routine
'getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName()'
to something else if that makes everything more testable. Can someone
give me a example of how to set up this MockHttpServletRequest ?

Regards, Ted

Igor Vaynberg wrote:

> you can create your own subclass of mockhttpservletrequest and return
> whatever you want. hooking it into wickettester should not be that
> bad... if it is we can see if we can make it easier.
>
> -igor
>
> On Wed, Nov 4, 2009 at 8:27 AM, Ted Vinke <tvinke@...> wrote:
>  
>> Hi!
>>
>> Seems a bit dumb I can't seem to get the following working. In my
>> application I have to so something special based on the domain the app is
>> running on. I ask for that domain in the following manner:
>>
>>   String serverName =
>> getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName();
>>   // serverName is e.g. 'www.somedomain.com'
>>
>> The problem: when testing in the Wicket tester serverName results in
>> 'localhost'.
>>
>> How can I set / mock
>> getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName()
>> to return a preset value, such as 'www.somedomain.com',  when accessing my
>> page in my unit test?
>>
>> Any tips or hints to examples are greatly appreciated!!
>>
>> Kind regards,
>> Ted
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>>    
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  



Re: Wicket tester mock server name

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

you need to override the creation of the request cycle, that is where
request and response are taken.

-igor

On Thu, Nov 5, 2009 at 1:17 AM, Ted Vinke <tvinke@...> wrote:

> I have no experience mocking things with the Wicket tester. I've tried
> things like
>
> MockHttpServletRequest mock = tester.getServletRequest();
> mock.setURL("http://www.domain.com");
>
> in my test and a
>
> @Override
>   public UserSession newSession(Request request, Response response) {
>       tester.setupRequestAndResponse();
>       MockHttpServletRequest mockRequest = tester.getServletRequest();
>       mockRequest.setURL("http://www.domain.com");
>       return super.newSession(tester.getWicketRequest(),
> tester.getWicketResponse());
>   }
>
> in a MockApplication which extends my real Application but I don't seem to
> get the desired effect.
>
> I'm happy to change the original routine
> 'getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName()'
> to something else if that makes everything more testable. Can someone give
> me a example of how to set up this MockHttpServletRequest ?
>
> Regards, Ted
>
> Igor Vaynberg wrote:
>>
>> you can create your own subclass of mockhttpservletrequest and return
>> whatever you want. hooking it into wickettester should not be that
>> bad... if it is we can see if we can make it easier.
>>
>> -igor
>>
>> On Wed, Nov 4, 2009 at 8:27 AM, Ted Vinke <tvinke@...> wrote:
>>
>>>
>>> Hi!
>>>
>>> Seems a bit dumb I can't seem to get the following working. In my
>>> application I have to so something special based on the domain the app is
>>> running on. I ask for that domain in the following manner:
>>>
>>>  String serverName =
>>>
>>> getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName();
>>>  // serverName is e.g. 'www.somedomain.com'
>>>
>>> The problem: when testing in the Wicket tester serverName results in
>>> 'localhost'.
>>>
>>> How can I set / mock
>>>
>>> getWebRequestCycle().getWebRequest().getHttpServletRequest().getServerName()
>>> to return a preset value, such as 'www.somedomain.com',  when accessing
>>> my
>>> page in my unit test?
>>>
>>> Any tips or hints to examples are greatly appreciated!!
>>>
>>> Kind regards,
>>> Ted
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@...
>>> For additional commands, e-mail: users-help@...
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...