tag:blogger.com,1999:blog-1280619439915049383.post6206332767011294265..comments2024-03-17T02:14:58.129-05:00Comments on James Lorenzen's Blog: Proper way to access file resources in junit testsjlorenzenhttp://www.blogger.com/profile/13635369821860631868noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-1280619439915049383.post-57737513003523982802016-06-10T02:41:08.163-05:002016-06-10T02:41:08.163-05:00I love youI love youAnonymoushttps://www.blogger.com/profile/02905900406751788393noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-73290690833354226772014-10-15T10:31:00.092-05:002014-10-15T10:31:00.092-05:00can someone give me an example how can I write a J...can someone give me an example how can I write a Junit class for WSDL classes or webservice classesAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-3172323317120677552013-09-09T18:55:27.259-05:002013-09-09T18:55:27.259-05:00Thank you!Thank you!Juan Carlosnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-46288992196620883232013-07-09T10:27:06.547-05:002013-07-09T10:27:06.547-05:00Thanks! It really helped me a lot!Thanks! It really helped me a lot!Libor Jelinekhttps://www.blogger.com/profile/10599446195328804351noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-431663758369422972012-07-19T13:24:46.371-05:002012-07-19T13:24:46.371-05:00Got this to work in groovy when I couldn't get...Got this to work in groovy when I couldn't get anything else to work:<br />this.getClass().getResourceAsStream("/test.xml").textjlorenzenhttps://www.blogger.com/profile/13635369821860631868noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-57821593073270740572012-01-21T13:00:23.146-06:002012-01-21T13:00:23.146-06:00T.Hanks, to favorites.T.Hanks, to favorites.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-9688853190445994002012-01-04T07:54:07.151-06:002012-01-04T07:54:07.151-06:00Thank you very much!Thank you very much!Dmitry Sobolevhttps://www.blogger.com/profile/02029474592305050003noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-88502934636601308762011-07-18T15:12:33.369-05:002011-07-18T15:12:33.369-05:00Thank youThank youAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-33565239940526938222011-07-04T03:09:57.154-05:002011-07-04T03:09:57.154-05:00Nice work - thanks a lotNice work - thanks a lotAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-80126530822326955132011-05-24T14:42:08.595-05:002011-05-24T14:42:08.595-05:00Very usefuke, thanks!Very usefuke, thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-66019337508114339192010-05-14T08:55:59.756-05:002010-05-14T08:55:59.756-05:00Spring has some handy utils so you don't have ...Spring has some handy utils so you don't have that spaces problem:<br /><br />ResourceUtils.getFile(this.getClass().getResource("/filename.txt"))Paul Middelkoopnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-65076604095613593912009-09-11T09:51:38.779-05:002009-09-11T09:51:38.779-05:00Thank you, this is perfect. I saw a similar artic...Thank you, this is perfect. I saw a similar article talking about using getResourceAsStream but I needed a path instead.<br /><br />One note:<br /><br />I had a lot of trouble getting this to work before I realized that the URL replaces spaces with %20; the File created from such a path (if it's local on your machine) will not work like that! So I ended up doing the following rather circuitous route:<br /><br /><br />URL url = this.getClass().getResource(CBT_COA1);<br />String pathWithoutPercents = url.getFile().replace("%20", " ");<br /><br />File f = new File(pathWithoutPercents);Unknownhttps://www.blogger.com/profile/02633237664058475673noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-2371689273140548722008-10-30T14:46:00.000-05:002008-10-30T14:46:00.000-05:00Hello James, when I googled this as the first entr...Hello James, when I googled this as the first entry on the first try to find a solution I thought: Wow! this can't be this easy! Alas, it does not work. I am very surprised because as you say a so-called: resources directory gets special treatment in Maven. And, sure-enough the so-called: test file is copied to test-classes. I have even tried to use new File("../../../../"+filename) since the test file is exactly four directory levels above the test class packaging. I have done something similar with a Maven resources directory for my war file resources using getResourceAsStream() which does work. Any ideas of how to debug this? Please advise, David.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-50302344868284281422007-11-13T12:50:00.000-06:002007-11-13T12:50:00.000-06:00FYI,To accomplish this in a Groovy Test that exten...FYI,<BR/>To accomplish this in a Groovy Test that extends GroovyTestCase I had to replace the reference to 'this' to the current class.<BR/>Instead of:<BR/>URL url = this.getClass().getResource("/test.wsdl");<BR/><BR/>in groovy would be<BR/>def url = new DriverTest().getClass().getResource("/test.wsdl")<BR/><BR/>Where DriverTest is the actually test class.jlorenzenhttps://www.blogger.com/profile/13635369821860631868noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-63774532623253179592007-09-14T14:12:00.000-05:002007-09-14T14:12:00.000-05:00James,I really appreciate you posting this. I hav...James,<BR/><BR/>I really appreciate you posting this. I have been scouring the net looking for the way to reference a resource through the maven build. It was working in Eclipse, but it did not work through the maven build. <BR/><BR/>Thanks for helping me solve this one.Carlus Henryhttps://www.blogger.com/profile/10118327352251205251noreply@blogger.comtag:blogger.com,1999:blog-1280619439915049383.post-75675938036363913252007-07-11T15:53:00.000-05:002007-07-11T15:53:00.000-05:00Hammer, meet the head of the nail.Hammer, meet the head of the nail.Jeffhttps://www.blogger.com/profile/17053090306859709462noreply@blogger.com