Atouray
asked on
Integration Testing in eclipse
Is there any good plugins in eclipse that does integration testing? To test method calls between specified classes.
ASKER
I have two classes, and one of them is calling a method from the other. I want to do an integration testing for this.
Class FirstClass{
public void openDocument(URL url) throws Exception {
// Originally, this method determined external application, with which the document
// should be opened. Which application should open which document type was
// configured in Vmap properties file. As a result, Vmap tried to solve the
// problem (of determining application for a file type), which should better be
// solved somewhere else. Indeed, on Windows, this problem is perfectly solved by
// Explorer. On KDE, this problem is solved by Konqueror default browser. In
// general, most WWW browsers have to solve this problem.
// As a result, the only thing we do here, is to open URL in WWW browser.
String osName = System.getProperty("os.name");
if (osName.substring(0,3).equals("Win")) {
String propertyString = new String("default_browser_command_windows");
if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) {
propertyString += "_9x";
} else {
propertyString += "_nt";
}
String browser_command=new String();
String command=new String();
// Here we introduce " around the parameter of explorer
// command. This is not because of possible spaces in this
// parameter - it is because of "=" character, which causes
// problems. My understanding of MSDOS is not so good, but at
// least I can say, that "=" is used in general for the purpose
// of variable assignment.
//String[] call = { browser_command, "\""+url.toString()+"\"" };
try {
// This is working fine on Windows 2000 and NT as well
// Below is a piece of code showing how to run executables directly
// without asking. However, we don't want to do that. Explorer will run
// executable, but ask before it actually runs it.
//
// Imagine you download a package of maps containing also nasty
// executable. Let's say there is a map "index.mm". This map contains a
// link to that nasty executable, but the name of the link appearing to the
// user does not indicate at all that clicking the link leads to execution
// of a programm. This executable is located on your local computer, so
// asking before executing remote executable does not solve the
// problem. You click the link and there you are running evil executable.
// build string for default browser:
// ask for property about browser: fc, 26.11.2003.
Object[] messageArguments = { url.toString() };
MessageFormat formatter = new MessageFormat(getProperty(propertyString));
browser_command = formatter.format(messageArguments);
if (url.getProtocol().equals("file")) {
command = "rundll32 url.dll,FileProtocolHandler "+Tools.urlGetFile(url);
} else if (url.toString().startsWith("mailto:")) {
command = "rundll32 url.dll,FileProtocolHandler "+url.toString();
} else {
command = browser_command;
}
Runtime.getRuntime().exec(command);
}
catch(IOException x) {
c.errorMessage("Could not invoke browser.\n\nVmap excecuted the following statement on a command line:\n\""+command+"\".\n\nYou may look at the user or default property called '"+propertyString+"'.");
System.err.println("Caught: " + x);
}
} else if (osName.startsWith("Mac OS")) {
String urlString = url.toString();
String browser_command=new String();
try {
// build string for default browser:
if (url.getProtocol().equals("file")) {
urlString=urlString.replace('\\','/').replaceAll(" ","%20");
}
Object[] messageArguments = { urlString, urlString };
// ask for property about browser: fc, 26.11.2003.
MessageFormat formatter = new MessageFormat(getProperty("default_browser_command_mac"));
browser_command = formatter.format(messageArguments);
Runtime.getRuntime().exec(browser_command);
} catch(IOException ex2) {
c.errorMessage("Could not invoke browser.\n\nVmap excecuted the following statement on a command line:\n\""+browser_command+"\".\n\nYou may look at the user or default property called 'default_browser_command_mac'.");
System.err.println("Caught: " + ex2);
}
} else {
// There is no '"' character around url.toString (compare to Windows code
// above). Putting '"' around does not work on Linux - instead, the '"'
// becomes part of URL, which is malformed, as a result.
// String urlString = url.toString();
// if (url.getProtocol().equals("file")) {
// urlString = urlString.replace('\\','/').replaceAll(" ","%20"); }
// // ^ This is more of a heuristic than a "logical" code
String browser_command=new String();
try {
// build string for default browser:
String correctedUrl = new String(url.toExternalForm());
// ask for property about browser: fc, 26.11.2003.
Object[] messageArguments = { correctedUrl, url.toString() };
MessageFormat formatter = new MessageFormat(getProperty("default_browser_command_other_os"));
browser_command = formatter.format(messageArguments);
Runtime.getRuntime().exec(browser_command); }
catch(IOException ex2) {
c.errorMessage("Could not invoke browser.\n\nVmap excecuted the following statement on a command line:\n\""+browser_command+"\".\n\nYou may look at the user or default property called 'default_browser_command_other_os'.");
System.err.println("Caught: " + ex2);
}
}
}
}
Class Tools{
public static String urlGetFile(URL url) {
String osNameStart = System.getProperty("os.name").substring(0,3);
String fileSeparator = System.getProperty("file.separator");
if (osNameStart.equals("Win") && url.getProtocol().equals("file")) {
String fileName = url.toString().replaceFirst("^file:","").replace('/','\\');
return (fileName.indexOf(':') >= 0) ?
fileName.replaceFirst("^\\\\*","") :
fileName; } // Network path
else {
return url.getFile(); }}
}
ASKER
I have to test the coupling between these classes.
if (url.getProtocol().equals( "file")) {
command = "rundll32 url.dll,FileProtocolHandle r "+Tools.urlGetFile(url);
} else if (url.toString().startsWith ("mailto:" )) {
The method Tools.urlGetFile(url) is in the Tools method. How do i go about with the integration testing. This is what I have done so far but i believe it is more of a unit test than an integration test. Can someone guide me through the integration testing?
@Test
public void T2() throws MalformedURLException {
try{
URL url=new URL("http://www.yahoo.com/edinburgh/lothian/warrender");
m_vmap.openDocument(url);
String urlInTools = m_cCountField.urlGetFile(u rl);
System.out.println("URLGet File: "+urlInTools);
// formatter.format(url);
//assertEquals("/edinburgh /lothian/w arrender", urlInTools );
}
catch(Exception e) {
System.out.println("Error Found: "+e);
assertTrue(true);
}
}
Thank you
if (url.getProtocol().equals(
command = "rundll32 url.dll,FileProtocolHandle
} else if (url.toString().startsWith
The method Tools.urlGetFile(url) is in the Tools method. How do i go about with the integration testing. This is what I have done so far but i believe it is more of a unit test than an integration test. Can someone guide me through the integration testing?
@Test
public void T2() throws MalformedURLException {
try{
URL url=new URL("http://www.yahoo.com/edinburgh/lothian/warrender");
m_vmap.openDocument(url);
String urlInTools = m_cCountField.urlGetFile(u
System.out.println("URLGet
// formatter.format(url);
//assertEquals("/edinburgh
}
catch(Exception e) {
System.out.println("Error Found: "+e);
assertTrue(true);
}
}
Thank you
Class FirstClass{
public void openDocument(URL url) throws Exception {
// Originally, this method determined external application, with which the document
// should be opened. Which application should open which document type was
// configured in Vmap properties file. As a result, Vmap tried to solve the
// problem (of determining application for a file type), which should better be
// solved somewhere else. Indeed, on Windows, this problem is perfectly solved by
// Explorer. On KDE, this problem is solved by Konqueror default browser. In
// general, most WWW browsers have to solve this problem.
// As a result, the only thing we do here, is to open URL in WWW browser.
String osName = System.getProperty("os.name");
if (osName.substring(0,3).equals("Win")) {
String propertyString = new String("default_browser_command_windows");
if (osName.indexOf("9") != -1 || osName.indexOf("Me") != -1) {
propertyString += "_9x";
} else {
propertyString += "_nt";
}
String browser_command=new String();
String command=new String();
// Here we introduce " around the parameter of explorer
// command. This is not because of possible spaces in this
// parameter - it is because of "=" character, which causes
// problems. My understanding of MSDOS is not so good, but at
// least I can say, that "=" is used in general for the purpose
// of variable assignment.
//String[] call = { browser_command, "\""+url.toString()+"\"" };
try {
// This is working fine on Windows 2000 and NT as well
// Below is a piece of code showing how to run executables directly
// without asking. However, we don't want to do that. Explorer will run
// executable, but ask before it actually runs it.
//
// Imagine you download a package of maps containing also nasty
// executable. Let's say there is a map "index.mm". This map contains a
// link to that nasty executable, but the name of the link appearing to the
// user does not indicate at all that clicking the link leads to execution
// of a programm. This executable is located on your local computer, so
// asking before executing remote executable does not solve the
// problem. You click the link and there you are running evil executable.
// build string for default browser:
// ask for property about browser: fc, 26.11.2003.
Object[] messageArguments = { url.toString() };
MessageFormat formatter = new MessageFormat(getProperty(propertyString));
browser_command = formatter.format(messageArguments);
if (url.getProtocol().equals("file")) {
command = "rundll32 url.dll,FileProtocolHandler "+Tools.urlGetFile(url);
} else if (url.toString().startsWith("mailto:")) {
command = "rundll32 url.dll,FileProtocolHandler "+url.toString();
} else {
command = browser_command;
}
Runtime.getRuntime().exec(command);
}
catch(IOException x) {
c.errorMessage("Could not invoke browser.\n\nVmap excecuted the following statement on a command line:\n\""+command+"\".\n\nYou may look at the user or default property called '"+propertyString+"'.");
System.err.println("Caught: " + x);
}
} else if (osName.startsWith("Mac OS")) {
String urlString = url.toString();
String browser_command=new String();
try {
// build string for default browser:
if (url.getProtocol().equals("file")) {
urlString=urlString.replace('\\','/').replaceAll(" ","%20");
}
Object[] messageArguments = { urlString, urlString };
// ask for property about browser: fc, 26.11.2003.
MessageFormat formatter = new MessageFormat(getProperty("default_browser_command_mac"));
browser_command = formatter.format(messageArguments);
Runtime.getRuntime().exec(browser_command);
} catch(IOException ex2) {
c.errorMessage("Could not invoke browser.\n\nVmap excecuted the following statement on a command line:\n\""+browser_command+"\".\n\nYou may look at the user or default property called 'default_browser_command_mac'.");
System.err.println("Caught: " + ex2);
}
} else {
// There is no '"' character around url.toString (compare to Windows code
// above). Putting '"' around does not work on Linux - instead, the '"'
// becomes part of URL, which is malformed, as a result.
// String urlString = url.toString();
// if (url.getProtocol().equals("file")) {
// urlString = urlString.replace('\\','/').replaceAll(" ","%20"); }
// // ^ This is more of a heuristic than a "logical" code
String browser_command=new String();
try {
// build string for default browser:
String correctedUrl = new String(url.toExternalForm());
// ask for property about browser: fc, 26.11.2003.
Object[] messageArguments = { correctedUrl, url.toString() };
MessageFormat formatter = new MessageFormat(getProperty("default_browser_command_other_os"));
browser_command = formatter.format(messageArguments);
Runtime.getRuntime().exec(browser_command); }
catch(IOException ex2) {
c.errorMessage("Could not invoke browser.\n\nVmap excecuted the following statement on a command line:\n\""+browser_command+"\".\n\nYou may look at the user or default property called 'default_browser_command_other_os'.");
System.err.println("Caught: " + ex2);
}
}
}
}
Class Tools{
public static String urlGetFile(URL url) {
String osNameStart = System.getProperty("os.name").substring(0,3);
String fileSeparator = System.getProperty("file.separator");
if (osNameStart.equals("Win") && url.getProtocol().equals("file")) {
String fileName = url.toString().replaceFirst("^file:","").replace('/','\\');
return (fileName.indexOf(':') >= 0) ?
fileName.replaceFirst("^\\\\*","") :
fileName; } // Network path
else {
return url.getFile(); }}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. I did something similar to what you have done, is this integration as well?
public void testCouplingPath() throws MalformedURLException{
//Testing for the operating System
String ExpectedSystemOS = "Win";
String osName = System.getProperty("os.name");
String actualSystemOS = osName.substring(0,3);
assertEquals("System OS type",ExpectedSystemOS, actualSystemOS);
//Testing for the url protocol
URL url = new URL("file://www.gambia.west.africa.gm");
String urlProtocol = url.getProtocol();
String expectedProtocol = "file";
assertEquals("URL Protocol",expectedProtocol,urlProtocol);
//testing for the Tools.urlGetFile(url)
String urlGetFileReturns = Tools.urlGetFile(url);
String expectedURLReturn = "\\\\www.gambia.west.africa.gm";
assertEquals("urlGetFile return answer",expectedURLReturn,urlGetFileReturns);
}
That looks like a good test but it's still really just a unit test for urlGetFile() and some parts of the openDocument() method.
I think to make it a full integration test you just need to add a call to:
FirstClass.openDocument(ur l);
probably at the end of the test.
Since openDocument() doesn't actually return anything, it's hard to test it's behavior - except that a call to it doesn't throw an exception.
Doug
I think to make it a full integration test you just need to add a call to:
FirstClass.openDocument(ur
probably at the end of the test.
Since openDocument() doesn't actually return anything, it's hard to test it's behavior - except that a call to it doesn't throw an exception.
Doug
There's nothing about JUnit that limits you to writing unit tests. You can easily write integration tests - where your test classes just calls to methods in other classes.
Doug