Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Get path as String for file in source package structure

Thread view: 
Petterson Mikael - 26 Apr 2007 15:03 GMT
Hi,

In  a junit test:

public void testSendMsgWithAttachment(){
    try {
        SendMessage send = new SendMessage();
        send.sendMsg(from, to, cc, bcc, subject, text, attachment);
        fail("Test failed since no IOException was thrown");
       } catch (Exception e) {
        fail("Test failed du to unexpected exception" + e.toString());
       }
}

The String 'attachment' is the path to attachment-file.

I have the file ( Attachment.txt) in my package structure (CVS):

net.sourceforge.app.message.test

How can I get a path as String that is possible to use in my tes ( so I
can retrieve the attachment).

cheers,

//mikael
Oliver Wong - 26 Apr 2007 15:52 GMT
> Hi,
>
[quoted text clipped - 18 lines]
> How can I get a path as String that is possible to use in my tes ( so I
> can retrieve the attachment).

   I think it depends a lot on the implementation of
SendMessage.sendMsg() and what it expects as the last parameter. E.g. does
it accept relative paths, or only absolute paths? Does it accept URLs?
etc.

   - Oliver
Daniel Pitts - 26 Apr 2007 18:41 GMT
On Apr 26, 7:03 am, Petterson Mikael
<mikael.petter...@era.ericsson.se> wrote:
> Hi,
>
[quoted text clipped - 23 lines]
>
> //mikael

First, your test looks wrong.
public void testSendMsgWithAttachment(){
  try {
     SendMessage send = new SendMessage();
     send.sendMsg(from, to, cc, bcc, subject, text, attachment);
     fail("Test failed since no IOException was thrown");
  } catch (IOException e) {
  } catch (Exception e) {
     fail("Test failed du to unexpected exception" + e.toString());
  }
}

To get the URL of the attachment try:
URL attachmentUrl = getClass().getClassLoader().getResource("net/
sourceforge/app/message/test/Attachment.txt");


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.