RE: Patch to parameterize port numbers in JUnit tests
Hi Rhett, Thanks for the pointer. Actually I wanted to reuse a static Java member, so I relied on the FieldRetrievingFactoryBean class: Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : Rhett Sutphin [mailto:rh...@detailedbalance.net] Envoye : mercredi 14 janvier 2009 22:31 A : discuss@restlet.tigris.org Objet : Re: Patch to parameterize port numbers in JUnit tests > For Spring it should be possible to inject the static value into the > bean property. I don't remember the exact syntax, but we can > figure this out. You can configure a PropertyPlaceholderConfigurer into the application context: http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html It resolves placeholders from either system properties or a configured property file / inline list. Rhett On Jan 14, 2009, at 1:59 PM, Jerome Louvel wrote: > Hi Raif, > > That sounds like a useful thing to do. I was trying to apply the > patch but got issues with the paths of the patched files. > > Could you try to use SVN instead to generate it, starting at the > root of the SVN trunk instead? > > For Spring it should be possible to inject the static value into the > bean property. I don't remember the exact syntax, but we can > figure this out. Any Spring wizard listening? > > Best regards, > Jerome Louvel > -- > Restlet ~ Founder and Lead developer ~ http://www.restlet.org > Noelios Technologies ~ Co-founder ~ http://www.noelios.com > > > -Message d'origine- > De : Raif S. Naffah [mailto:tig...@naffah-raif.name] > Envoye : samedi 10 janvier 2009 07:48 > A : discuss@restlet.tigris.org > Objet : Patch to parameterize port numbers in JUnit tests > > hello there, > > the JUnit tests (in org.restlet.test) have hard-wired port numbers > which may > not suit every developer's environment. this patch introduces a new > property in the main build.xml, and injects at as a system environment > variable. > > when more than one port is required, the property value is used as a > base; > i.e. second port number is valueOf(property) + 1, etc. > > the only test i was not able to parametrize was the Spring test (and > its > .xml file). > > > cheers; > rsn > > -- > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1024775 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1024919 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1028854
RE: Patch to parameterize port numbers in JUnit tests
Hi Raif, Thanks! Your patch has been applied in SVN trunk. I just need to fix the Spring config file now. Best regards, Jérôme Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : Raif S. Naffah [mailto:s...@naffah-raif.name] Envoyé : jeudi 15 janvier 2009 09:14 À : discuss@restlet.tigris.org Cc : Jerome Louvel Objet : Re: Patch to parameterize port numbers in JUnit tests hello Jerome, i've attached a new version done with kdesvn instead of Eclipse (previous version). On Thu January 15 2009 06:59:06 Jerome Louvel wrote: > Hi Raif, > > That sounds like a useful thing to do. I was trying to apply the patch > but got issues with the paths of the patched files. > > Could you try to use SVN instead to generate it, starting at the root of > the SVN trunk instead? > > For Spring it should be possible to inject the static value into the bean > property. I don't remember the exact syntax, but we can figure this out. > Any Spring wizard listening? > > Best regards, > Jerome Louvel > -- > Restlet ~ Founder and Lead developer ~ http://www.restlet.org > Noelios Technologies ~ Co-founder ~ http://www.noelios.com > > > -Message d'origine- > De : Raif S. Naffah [mailto:tig...@naffah-raif.name] > Envoye : samedi 10 janvier 2009 07:48 > A : discuss@restlet.tigris.org > Objet : Patch to parameterize port numbers in JUnit tests > > hello there, > > the JUnit tests (in org.restlet.test) have hard-wired port numbers which > may not suit every developer's environment. this patch introduces a new > property in the main build.xml, and injects at as a system environment > variable. > > when more than one port is required, the property value is used as a > base; i.e. second port number is valueOf(property) + 1, etc. > > the only test i was not able to parametrize was the Spring test (and its > .xml file). > > > cheers; > rsn > > -- > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=10 >24775 cheers; rsn -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1028770
Re: Patch to parameterize port numbers in JUnit tests
hello Jerome, i've attached a new version done with kdesvn instead of Eclipse (previous version). On Thu January 15 2009 06:59:06 Jerome Louvel wrote: > Hi Raif, > > That sounds like a useful thing to do. I was trying to apply the patch > but got issues with the paths of the patched files. > > Could you try to use SVN instead to generate it, starting at the root of > the SVN trunk instead? > > For Spring it should be possible to inject the static value into the bean > property. I don't remember the exact syntax, but we can figure this out. > Any Spring wizard listening? > > Best regards, > Jerome Louvel > -- > Restlet ~ Founder and Lead developer ~ http://www.restlet.org > Noelios Technologies ~ Co-founder ~ http://www.noelios.com > > > -Message d'origine- > De : Raif S. Naffah [mailto:tig...@naffah-raif.name] > Envoye : samedi 10 janvier 2009 07:48 > A : discuss@restlet.tigris.org > Objet : Patch to parameterize port numbers in JUnit tests > > hello there, > > the JUnit tests (in org.restlet.test) have hard-wired port numbers which > may not suit every developer's environment. this patch introduces a new > property in the main build.xml, and injects at as a system environment > variable. > > when more than one port is required, the property value is used as a > base; i.e. second port number is valueOf(property) + 1, etc. > > the only test i was not able to parametrize was the Spring test (and its > .xml file). > > > cheers; > rsn > > -- > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=10 >24775 cheers; rsn Index: build/build.properties === --- build/build.properties (revision 4122) +++ build/build.properties (working copy) @@ -58,7 +58,8 @@ # Indicates if the NSIS tool should be run over the # distribution files -nsis: true +#nsis: true +nsis: false nsis-makensis-path: /usr/bin # Verbose flag currently used during Java compilation @@ -73,3 +74,6 @@ # Indicates if the final packaging phase should be done. package: true + +# Port number to use for JUnit tests +port-number: 3 Index: modules/org.restlet.test/src/org/restlet/test/ComponentXmlTestCase.java === --- modules/org.restlet.test/src/org/restlet/test/ComponentXmlTestCase.java (revision 4122) +++ modules/org.restlet.test/src/org/restlet/test/ComponentXmlTestCase.java (working copy) @@ -42,9 +42,9 @@ */ public class ComponentXmlTestCase extends TestCase { -private final int port = 8182; +private final int port = RestletTestSuite.PORT; -private final int port2 = 8183; +private final int port2 = port + 1; public void testComponentXMLConfig() throws Exception { final StringBuilder builder = new StringBuilder(); Index: modules/org.restlet.test/src/org/restlet/test/RangeTestCase.java === --- modules/org.restlet.test/src/org/restlet/test/RangeTestCase.java (revision 4122) +++ modules/org.restlet.test/src/org/restlet/test/RangeTestCase.java (working copy) @@ -178,7 +178,7 @@ @Override protected void setUp() throws Exception { component = new Component(); -component.getServers().add(Protocol.HTTP, 8182); +component.getServers().add(Protocol.HTTP, RestletTestSuite.PORT); component.getClients().add(Protocol.FILE); component.getDefaultHost().attach(new TestRangeApplication()); component.start(); @@ -199,13 +199,14 @@ Client client = new Client(Protocol.HTTP); // Test partial Get. Request request = new Request(Method.GET, -"http://localhost:8182/testGet";); +"http://localhost:"; + RestletTestSuite.PORT + "/testGet"); Response response = client.handle(request); assertEquals(Status.SUCCESS_OK, response.getStatus()); assertEquals("1234567890", response.getEntity().getText()); assertEquals(10, response.getEntity().getSize()); -request = new Request(Method.GET, "http://localhost:8182/testGet";); +request = new Request(Method.GET, "http://localhost:"; ++ RestletTestSuite.PORT +"/testGet"); request.setRanges(Arrays.asList(new Range(0, 10))); response = client.handle(request); assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus()); @@ -268,7 +269,7 @@ // PUT on a file that does not exist Request request = new Request(Method.PUT, -"http://localhost:8182/testPut/essai.txt";); +"http://localhost:"
Re: Patch to parameterize port numbers in JUnit tests
> For Spring it should be possible to inject the static value into the > bean property. I don't remember the exact syntax, but we can > figure this out. You can configure a PropertyPlaceholderConfigurer into the application context: http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html It resolves placeholders from either system properties or a configured property file / inline list. Rhett On Jan 14, 2009, at 1:59 PM, Jerome Louvel wrote: > Hi Raif, > > That sounds like a useful thing to do. I was trying to apply the > patch but got issues with the paths of the patched files. > > Could you try to use SVN instead to generate it, starting at the > root of the SVN trunk instead? > > For Spring it should be possible to inject the static value into the > bean property. I don't remember the exact syntax, but we can > figure this out. Any Spring wizard listening? > > Best regards, > Jerome Louvel > -- > Restlet ~ Founder and Lead developer ~ http://www.restlet.org > Noelios Technologies ~ Co-founder ~ http://www.noelios.com > > > -Message d'origine- > De : Raif S. Naffah [mailto:tig...@naffah-raif.name] > Envoye : samedi 10 janvier 2009 07:48 > A : discuss@restlet.tigris.org > Objet : Patch to parameterize port numbers in JUnit tests > > hello there, > > the JUnit tests (in org.restlet.test) have hard-wired port numbers > which may > not suit every developer's environment. this patch introduces a new > property in the main build.xml, and injects at as a system environment > variable. > > when more than one port is required, the property value is used as a > base; > i.e. second port number is valueOf(property) + 1, etc. > > the only test i was not able to parametrize was the Spring test (and > its > .xml file). > > > cheers; > rsn > > -- > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1024775 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1024919
RE: Patch to parameterize port numbers in JUnit tests
Hi Raif, That sounds like a useful thing to do. I was trying to apply the patch but got issues with the paths of the patched files. Could you try to use SVN instead to generate it, starting at the root of the SVN trunk instead? For Spring it should be possible to inject the static value into the bean property. I don't remember the exact syntax, but we can figure this out. Any Spring wizard listening? Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : Raif S. Naffah [mailto:tig...@naffah-raif.name] Envoye : samedi 10 janvier 2009 07:48 A : discuss@restlet.tigris.org Objet : Patch to parameterize port numbers in JUnit tests hello there, the JUnit tests (in org.restlet.test) have hard-wired port numbers which may not suit every developer's environment. this patch introduces a new property in the main build.xml, and injects at as a system environment variable. when more than one port is required, the property value is used as a base; i.e. second port number is valueOf(property) + 1, etc. the only test i was not able to parametrize was the Spring test (and its .xml file). cheers; rsn -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1024775
Patch to parameterize port numbers in JUnit tests
hello there, the JUnit tests (in org.restlet.test) have hard-wired port numbers which may not suit every developer's environment. this patch introduces a new property in the main build.xml, and injects at as a system environment variable. when more than one port is required, the property value is used as a base; i.e. second port number is valueOf(property) + 1, etc. the only test i was not able to parametrize was the Spring test (and its .xml file). cheers; rsn ### Eclipse Workspace Patch 1.0 #P org.restlet.test Index: src/org/restlet/test/TemplateFilterTestCase.java === --- src/org/restlet/test/TemplateFilterTestCase.java(revision 4104) +++ src/org/restlet/test/TemplateFilterTestCase.java(working copy) @@ -198,7 +198,7 @@ // Create a new component final Component component = new Component(); -component.getServers().add(Protocol.HTTP, 8182); +component.getServers().add(Protocol.HTTP, RestletTestSuite.PORT); component.getClients().add(Protocol.FILE); // Create an application filtered with Freemarker @@ -220,28 +220,28 @@ freemarkerApplication.getTunnelService().setExtensionsTunnel(true); velocityApplication.getTunnelService().setExtensionsTunnel(true); final Client client = new Client(Protocol.HTTP); -Response response = client.get("http://localhost:8182/freemarker/"; -+ testFileFm1.getName()); +Response response = client.get("http://localhost:"; ++ RestletTestSuite.PORT +"/freemarker/" + testFileFm1.getName()); if (response.isEntityAvailable()) { assertEquals(response.getEntity().getText(), -"Method=GET/Authority=localhost:8182"); +"Method=GET/Authority=localhost:" + RestletTestSuite.PORT); } -response = client.get("http://localhost:8182/freemarker/"; -+ testFileFm2.getName()); +response = client.get("http://localhost:"; + RestletTestSuite.PORT ++ "/freemarker/" + testFileFm2.getName()); assertTrue(response.getStatus().isSuccess()); if (response.isEntityAvailable()) { assertEquals(response.getEntity().getText(), "Method=${m}/Authority=${ra}"); } -response = client.get("http://localhost:8182/velocity/"; -+ testFileVl1.getName()); +response = client.get("http://localhost:"; + RestletTestSuite.PORT ++ "/velocity/" + testFileVl1.getName()); if (response.isEntityAvailable()) { assertEquals(response.getEntity().getText(), "Method=GET/Path=/velocity/testVl1"); } -response = client.get("http://localhost:8182/velocity/"; -+ testFileVl2.getName()); +response = client.get("http://localhost:"; + RestletTestSuite.PORT ++ "/velocity/" + testFileVl2.getName()); assertTrue(response.getStatus().isSuccess()); if (response.isEntityAvailable()) { assertEquals(response.getEntity().getText(), Index: src/org/restlet/test/HeaderTestCase.java === --- src/org/restlet/test/HeaderTestCase.java(revision 4104) +++ src/org/restlet/test/HeaderTestCase.java(working copy) @@ -65,8 +65,6 @@ private static final String HTTP_HEADERS = "org.restlet.http.headers"; -private static final int PORT = 8182; - /** * Name of a test header field */ @@ -101,20 +99,21 @@ private Response getWithParams(Parameter... parameters) { final Client client = new Client(Protocol.HTTP); final Request request = new Request(Method.GET, "http://localhost:"; -+ PORT); ++ RestletTestSuite.PORT); final Form headers = getHttpHeaders(request); for (final Parameter p : parameters) { headers.add(p); } -return client.handle(request); +Response result = client.handle(request); +return result; } @Override public void setUp() throws Exception { if (this.component == null) { this.component = new Component(); -this.component.getServers().add(Protocol.HTTP, PORT); +this.component.getServers().add(Protocol.HTTP, RestletTestSuite.PORT); this.component.getDefaultHost().attachDefault( new TestHeaderRestlet()); } Index: src/org/restlet/test/SpringTestCase.xml === --- src/org/restlet/test/SpringTestCase.xml (revision 4104) +++ src/org/restlet/test/SpringTestCase.xml