Hi,
Yes, I was thinking about that as well.
But since I only need it when I run unit tests I decided to mock the
URI.getHost, URI.getPort and URI.getScheme instead using PowerMock and
Mockito.
import static
org.powermock.api.support.membermodification.MemberMatcher.method;
import static
org.powermock.api.support.membermodification.MemberModifier.stub;
..
import org.powermock.modules.junit4.rule.PowerMockRule;
..
@PrepareForTest({ URI.class, RestletComponent.class })
public class MonitoringRoutesTest extends CamelSpringTestSupport {
..
@Rule
public PowerMockRule rule = new PowerMockRule();
..
@Override
public void doPreSetup() throws Exception {
super.doPreSetup();
stub(method(URI.class, "getScheme")).toReturn("http");
stub(method(URI.class, "getHost")).toReturn("localhost");
stub(method(URI.class, "getPort")).toReturn(8081);
}
..
@Test
public void testListEgs() throws Exception {
String response = (String) template.requestBodyAndHeader(
"ahc:http://localhost:8081/admin/executiongroup", null,
Exchange.HTTP_METHOD, HttpMethods.GET, String.class);
..
Works like a charm.
2012/7/14 Claus Ibsen <[email protected]>
> Hi
>
> Maybe if its/was possible to setup the host and port on the
> RestletComponent, then the endpoint can fallback and use those options
> if non specified in the uri. Then for production they can be / to
> indicate servlet, and for unit test, you can set it up to a localhost
> 8080 or whatever.
>
>
>
> On Fri, Jul 13, 2012 at 2:50 PM, Magnus Palmér
> <[email protected]> wrote:
> > After following the "Using the Restlet servlet within a webapp"
> > documentation at http://camel.apache.org/restlet.html I refactored my
> > Restlet endpoints by removing protocol, host and port.
> > So from "restlet:http://host:port/path/{id}" to "restlet:/path/{id}".
> > This works great when running in a servlet container.
> >
> > However my JUnit tests no longer works since, the reason for this is that
> > when using the applicationContext the protocol and host is set to null
> and
> > port is defaulted to 80 in
> > the
> org.apache.camel.component.restlet.RestletComponent.createEndpoint(String
> > uri, String remaining, Map parameters).
> >
> > The only resolution that I know will work is to manipulate the URI by
> using
> > "http://host:port" in test and "" otherwise.
> > Any ideas is highly appreciated otherwise I will have to satisfy with
> > manipulating the URIs.
> > (I am using both the real applicationContext and a test
> applicationContext
> > in my JUnit tests that extends CamelSpringTestSupport, and they have
> among
> > other things a Spring context:property-override definition where I can
> put
> > configuration).
> >
> > Looking at the JUnit tests in Camel source all routes are configured
> using
> > "restlet:http://host" + portnum + "/path" for the camel-restlet
> component.
> >
> >
> > Kind regards, Magnus
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [email protected]
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>