You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ychawla <pr...@gmail.com> on 2014/10/24 23:44:03 UTC
Change property in unit test
Hello All,
I have a unit test and I want to change a camel property. I am only a
single version of the configuration file to test against so I would like to
change the property in code. For example, I thought I could do something
like this:
context.getProperties().put("myProperty", "false");
However, that didn't do it.
I see that I can resolve a property like this:
context.resolvePropertyPlaceholders("property");
However it doesn't look like I can change its value. Is there a way to
dynamically change a property in a Camel Context unit test?
Thanks,
Yogesh
--
View this message in context: http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Change property in unit test
Posted by Willem Jiang <wi...@gmail.com>.
In this case you may need to put the properties file (myprop.properties) into the test src resource directory to override it.
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:com/mycompany/myprop.properties"/>
</bean>
--
Willem Jiang
Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem
On October 29, 2014 at 12:24:50 AM, ychawla (premiergeneration@gmail.com) wrote:
> Hi,
> I gave this a try but since I am using the plain spring configuration
> rather than extending a class with Camel Spring Support there isn't a
> method to override.
>
> My class signature looks like this:
>
> @RunWith(CamelSpringJUnit4ClassRunner.class)
>
> @ContextConfiguration(locations={
> "classpath:META-INF/spring/camel-context.xml"})
>
> public class MyClass {
>
> Any ideas?
>
> Thanks,
> Yogesh
>
>
>
> On Tue, Oct 28, 2014 at 2:39 AM, Charles Moulliard-2 [via Camel] <
> ml-node+s465427n5758199h40@n5.nabble.com> wrote:
>
> > Hi,
> >
> > Have you overrided the method as described in the doc of apache camel (
> > http://camel.apache.org/properties.html) ?
> >
> > @Override
> > protected Properties useOverridePropertiesWithPropertiesComponent() {
> > Properties extra = new Properties();
> > extra.put("destination", "mock:extra");
> > extra.put("greeting", "Bye");
> > return extra;
> > }
> >
> > Regards,
> >
> > On Mon, Oct 27, 2014 at 3:40 PM, ychawla <[hidden email]
> > >
> > wrote:
> >
> > > Hi Claus,
> > > I am using plain spring testing and annotating my custom class like
> > this:
> > >
> > > @RunWith(SpringJUnit4ClassRunner.class)
> > > @ContextConfiguration
> > > public class MyCamelTest {
> > >
> > > I don't think I am able to use
> > useOverridePropertiesWithPropertiesComponent
> > > in this scenario. Is there a similar technique I can use with this
> > testing
> > > methodology?
> > >
> > > Thanks,
> > > Yogesh
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> > http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758098.html
> > > Sent from the Camel - Users mailing list archive at Nabble.com.
> > >
> >
> >
> >
> > --
> > Charles Moulliard
> > Apache Committer / Architect @RedHat
> > Twitter : @cmoulliard | Blog : http://cmoulliard.github.io
> >
> >
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> >
> > http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758199.html
> > To unsubscribe from Change property in unit test, click here
> >
> > .
> > NAML
> >
> >
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758236.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Change property in unit test
Posted by ychawla <pr...@gmail.com>.
Hi,
I gave this a try but since I am using the plain spring configuration
rather than extending a class with Camel Spring Support there isn't a
method to override.
My class signature looks like this:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={
"classpath:META-INF/spring/camel-context.xml"})
public class MyClass {
Any ideas?
Thanks,
Yogesh
On Tue, Oct 28, 2014 at 2:39 AM, Charles Moulliard-2 [via Camel] <
ml-node+s465427n5758199h40@n5.nabble.com> wrote:
> Hi,
>
> Have you overrided the method as described in the doc of apache camel (
> http://camel.apache.org/properties.html) ?
>
> @Override
> protected Properties useOverridePropertiesWithPropertiesComponent() {
> Properties extra = new Properties();
> extra.put("destination", "mock:extra");
> extra.put("greeting", "Bye");
> return extra;
> }
>
> Regards,
>
> On Mon, Oct 27, 2014 at 3:40 PM, ychawla <[hidden email]
> <http://user/SendEmail.jtp?type=node&node=5758199&i=0>>
> wrote:
>
> > Hi Claus,
> > I am using plain spring testing and annotating my custom class like
> this:
> >
> > @RunWith(SpringJUnit4ClassRunner.class)
> > @ContextConfiguration
> > public class MyCamelTest {
> >
> > I don't think I am able to use
> useOverridePropertiesWithPropertiesComponent
> > in this scenario. Is there a similar technique I can use with this
> testing
> > methodology?
> >
> > Thanks,
> > Yogesh
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758098.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
> --
> Charles Moulliard
> Apache Committer / Architect @RedHat
> Twitter : @cmoulliard | Blog : http://cmoulliard.github.io
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758199.html
> To unsubscribe from Change property in unit test, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5758017&code=cHJlbWllcmdlbmVyYXRpb25AZ21haWwuY29tfDU3NTgwMTd8MjQwNzY1OTI3>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758236.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Change property in unit test
Posted by Charles Moulliard <ch...@gmail.com>.
Hi,
Have you overrided the method as described in the doc of apache camel (
http://camel.apache.org/properties.html) ?
@Override
protected Properties useOverridePropertiesWithPropertiesComponent() {
Properties extra = new Properties();
extra.put("destination", "mock:extra");
extra.put("greeting", "Bye");
return extra;
}
Regards,
On Mon, Oct 27, 2014 at 3:40 PM, ychawla <pr...@gmail.com>
wrote:
> Hi Claus,
> I am using plain spring testing and annotating my custom class like this:
>
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration
> public class MyCamelTest {
>
> I don't think I am able to use useOverridePropertiesWithPropertiesComponent
> in this scenario. Is there a similar technique I can use with this testing
> methodology?
>
> Thanks,
> Yogesh
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758098.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog : http://cmoulliard.github.io
Re: Change property in unit test
Posted by ychawla <pr...@gmail.com>.
Hi Claus,
I am using plain spring testing and annotating my custom class like this:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class MyCamelTest {
I don't think I am able to use useOverridePropertiesWithPropertiesComponent
in this scenario. Is there a similar technique I can use with this testing
methodology?
Thanks,
Yogesh
--
View this message in context: http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017p5758098.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Change property in unit test
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
See useOverridePropertiesWithPropertiesComponent
http://camel.apache.org/camel-test.html
On Fri, Oct 24, 2014 at 11:44 PM, ychawla <pr...@gmail.com> wrote:
> Hello All,
> I have a unit test and I want to change a camel property. I am only a
> single version of the configuration file to test against so I would like to
> change the property in code. For example, I thought I could do something
> like this:
>
> context.getProperties().put("myProperty", "false");
>
> However, that didn't do it.
>
> I see that I can resolve a property like this:
>
> context.resolvePropertyPlaceholders("property");
>
> However it doesn't look like I can change its value. Is there a way to
> dynamically change a property in a Camel Context unit test?
>
> Thanks,
> Yogesh
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Change-property-in-unit-test-tp5758017.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/