Use junit with aspectj

Hi,
I have to use aspectj with junit so that I can test a method of a class where another object is being initialized by mocking that object. But I am having problems finding out how to compile the aspect keywords..Any ideas?

I have explored junit, jmock and AspectJ so far. But I am stuck at the point where I have to stub out an object being initialized in the method under test. Do you have any suggestions on how to stub out such objects without making any changes in the source code under test?
The scenario is basically when you instantiate an object inside of a method to perform some action. This problem is only occurring because I am not using a factory to get my objects. If I were using a factory, I could inject a mock factory. But I am looking for other solutions that don�t impact the source code.

Similar Messages

  • Problem using Toplink with JUnit

    Hi,
    I have a problem using Toplink with JUnit. Method under test is very simple: it use a static EntityManager object to open a transaction and persists data to db. When I invoke the method from a test method, it gives me the exception:
    java.lang.AssertionError
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:248)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:232)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:216)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initialize(JavaSECMPInitializer.java:239)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.initializeFromMain(JavaSECMPInitializer.java:278)
         at oracle.toplink.essentials.internal.ejb.cmp3.JavaSECMPInitializer.getJavaSECMPInitializer(JavaSECMPInitializer.java:81)
         at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:119)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
         at it.valerio.electromanager.model.EntityFacade.<clinit>(EntityFacade.java:12)
         at it.valerio.electromanager.business.ClienteBiz.insertIntoDatabase(ClienteBiz.java:36)
         at it.valerio.electromanager.test.model.ClienteTest.insertDBTest(ClienteTest.java:30)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
         at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
         at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
         at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
         at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
         at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Where is the problem???
    Regards,
    Valerio

    EntityFacade class is very simple and it uses a static EntityManager object. Here the code:
    public class EntityFacade {
         private static EntityManager em = Persistence.createEntityManagerFactory("ElectroManager").createEntityManager();
         private static Logger logger=Logger.getLogger(EntityFacade.class);
         public static void insertCliente(Cliente c)
              logger.debug("Inserisco cliente nel db: " + c);
              em.getTransaction().begin();
              c.setId(getNextIdForTable("Cliente"));
              em.persist(c);
              em.getTransaction().commit();
    If I call the method from inside a main it works well, so I think the problem is not the classpath neither the URL in the persistence.xml. However the URL is:
    <property name="toplink.jdbc.url" value="jdbc:derby:c:/programmi/ElectroManager/db/electroManager"/>
    I use the latest build version of TopLink.
    Thanks.

  • I already have an iPhone with Verizon, my upgrade isn't until next June 2014. Can I buy the iPhone 5s from Apple and still use it with verizon?

    I dropped my phone in some water and I don't have apple care. It's been about a week and I'd rather put the money into fixing my iPhone 4 to an iPhone 5s. But I'm not sure if I can just buy the phone from Apple and still use it with verizon. Can someone help?

    Yes, Apple will sell you an iPhone you can use with Verizon.

  • Need to remove header When using GUI_DOWNLOAD with file type "DBF"

    Hi ALL,
    I am using GUI_DOWNLOAD function module to downlaod data to csv file . I have taken FILE TYPE as "DBF" . After download , I have found data is downloaded along with a default header . Now how can I avoid Header while downloading.
    Please help me to solve this problem.
    thanks and regards,
    Dilip
    Edited by: dilip kumar on Jun 9, 2009 11:51 AM

    Hello Dilip,
    I tried using GUI_DOWNLOAD with FILE TYPE as "DBF", and i see the problem as mentioned. My question to you is:
    1. Why do you need 'DBF' format?
    2. Is it required to save the file as '.CSV'? Can you not try to save in '.XLS' file?
    Plz revert back.
    BR,
    Suhas

  • How to test the JSP pages and sevlets using JUnit. ?

    How to test the JSP pages using JUnit. How to configure what are all the steps to execute the JUnit test cases.

    Hi xiepei,
    since you are using modbus, a simple error checking is implicit in the protocol and is the comparison between returned checksum and the calculated one on the received message: checksum errors, if any, are an effect of communications errors (you should have at least 2 bits changed and on particular patterns to have the checksum be calculated correctly!). You won't be able to calculate BER on them, but you can calculate PER (Packet Error Rate).
    Another flag for communication errors, on the other direction, is to intercept error messages from the device: if it fully implements modbus protocol, it should return some warning in case of error (I seem to remember that in some cases it returns the reveived message with some error bits added: please check in modbus documentation).
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How to test servlet using Junit test????

    Hello everybody
    Does anybody know how to test an servlet class using Junit without using Cactus test . Is it possible to test a servlet using Junit without cactus test.Plz tell me the process how to test a servlet using Junit test .
    Regards
    srikant

    1) Do yoiu mean how to "run" your servlet code with sample parameter? This call manual testing with a sample run of you code. You need a web server(eg Tomcat), create a webapp with your servlet then deploy it there in order to run it.
    2) httpunit and junit are framework to write test case code that can be automated and repeatable. Plz read their doc.
    3) Your sample code me a very wrong way to retrieve and convert servlet parameters.
    Get a java toturial and servlet tutorial book and read it over the weekend. You need to get at least the basic.

  • How To Use HttpUnit With FORM-based Authentication?

    I'm just getting started with HttpUnit, and I'm having a problem:
    How does one use HttpUnit with FORM-based authentication?
    I have a Web app where I specify a number of protected URLs. When a user tries to invoke one of them in a browser, Tomcat 4.1.30 brings up a login page that I specified and asks for a username and password. The values given by the user is checked against the tomcat-users.xml file. If the user is valid, Tomcat
    forwards the response from the original request. If invalid, an error page is displayed. The user is considered valid until either the session times out or the browser is closed.
    Does HttpUnit have to log into the app every time I run a test? How does it manage subsequent pages after login?

    I don't think that's true. HttpUnit is 100% Java and based on JUnit. HttpUnit has nothing to do with Apache, AFAIK. HttpUnit is for unit testing servlets and JSPs. Apache is a Web server. It doesn't have a servlet/JSP engine, unless you bolt Tomcat on top of it.
    Perhaps we're talking about two different packages. - %

  • Is it possible to use servlets with portlets?

    I am building a Java portlet that will update a user's OID repository data. We are using it to provide a more user-friendly interface than the default Oracle "My Account" link on Portal.
    That portlet is made up by a JSP that submits the information to a Servlet that, in turn, forwards it to another servlet (using RequestDispatcher) that does the actual OID update and then it should redirect the page flow back to the original JSP to show the user a confirmation message.
    Things run fine up to where the OID entry is being updated correctly, but I am unable to redirect the flow back to the original JSP.
    JSP ----> Servlet ----> Servlet
    ^------------------------------|
    I did a little test and found out that after submitting the form to the 1st servlet, I cannot get a PortletRenderRequest object in that servlet.
    I have read the available documentation about building portlets but I cannot get a clear picture as to how I am supposed to build a portlet that uses servlets, or if it is possible at all.
    Is there a way to do this? Or if there isn't, can anyone provide an alternative?
    Thank you in advance.
    Best regards,
    Aldo Herrera

    If you mean the application AIM for Mac, it will depend on your download speed.
    If you mean "Can I use iChat with an AIM a screen name and does it cost anything ?" then the answer is Yes you can and no it does not cost and there is no download to do.
    If you mean "Can I use the AIM service with an @mac screen name and can this be done for free ? " then the answer is again yes.
    A trail account cost nothing and will work in ichat after the 60 days is up
    A Paid for but Lapsed account will also work in iChat and for this purpose can now be considered free.
    As I said and hinted at before your first question does not make it clear what you are actually asking.
    The Application AIM for Mac is stuck at version 4.7 and does not do Video or Audio Only chats.
    It has things that are useful in tweaking Buddy Lists in iChat but it is not specifically needed to contact AIM Buddies.
    9:00 PM Tuesday; June 24, 2008

  • How to run test cases in a jar file using junit?

    Hi,
    I want to run test cases in a jar file using junit and the jar file is not in the class path. I wrote the following code, but it does not work.
    import java.net.URL;
    import java.net.URLClassLoader;
    import junit.framework.TestResult;
    import junit.textui.TestRunner;
    public class MyTestRunner {
         public static void main(String[] args) throws Exception{
              URL url = new URL("file:///d:/case.jar");
              URLClassLoader loader = new URLClassLoader(new URL[]{url});
              loader.loadClass("TestCase1");
              TestRunner runner = new TestRunner();
              TestResult result = runner.start(new String[]{"TestCase1"});
              System.out.println(result.toString());
    }Any ideas?
    Thanks a lot.

    Wouldn't it just be easier to put it on the classpath? You're trying to, anyway, with a URLClassLoader, albeit in an entirely unnecessarily complicated way

  • NIST conformance tests using JUnit

    I haven't seen anyone from Oracle on the [email protected] mailing list, so I'm posting this here just to let you guys know.
    I've been working on recasting the NIST DOM test suite for Java to use JUnit and posted an initial release last night.
    The tests can easily be run against the beta XDK's parser (or any other JAXP compliant parser), but there were a substantial number test errors and failures. Some of these may be due to test problems, but I'd guess most of them are legitimate. However, I do not have time or the motivation to investigate them.
    It does seem that you take the position that the XML declaration is treated as a processing instruction (like MSXML does) which will cause 3 tests to fail, but you can adjust the tests to accept this using
    -Dnet.sourceforge.xmlconf.domunit.acceptXMLDeclPI=true
    I've made the source for my JUnit-hosted deriviatives of the NIST test suite available at http://xmlconf.sourceforge.net. You can either download the combined source and binary
    zip file from http://sourceforge.net/project/showfiles.php?group_id=8114&release_id=31676
    or you can access the source through the CVS (http://sourceforge.net/cvs/?group_id=8114)
    The tests run using JUnit 3.5 and can test JAXP 1.0 or JAXP 1.1 compliant DOM parsers.
    Xerces-J 1.3.1 does not report any test failures, crimson.jar and the other parser tested
    had a moderate amount of test failures, but no investigation has been performed to
    determine if those failures were problems with the tests or actual non-conformances
    with the spec.
    A JBuilder 4 .jpx project and an Ant 1.2 build.xml file are provided.
    ------- readme.txt from domunit 0.0.1 ---------
    domunit 0.0.1
    domunit currently contains equivalents of the NIST DOM 1 test written for
    the JUnit test framework (http://www.junit.org) and JAXP 1.1 or 1.0 compatible parsers.
    The tests were written to allow easy migration to JavaScript using JSUnit
    (http://www.jsunit.net) and CPPUnit (http://www.xprogramming.org/software)
    To run the full set of tests, place domunit.jar, junit.jar and one of the following
    combinations of jars in the same directory or on the class path.
    xerces.jar
    xml4j.jar
    jaxp.jar and parser.jar (from Sun's JAXP 1.0 Reference Implementation)
    jaxp.jar and crimson.jar (from Sun's JAXP 1.1 Reference Implementation)
    and run:
    java -jar domunit.jar
    To test Oracle's XML Processor, place jaxp.jar from the JAXP 1.0 (not 1.1) Reference Implementation
    and xmlparserv2.jar in the domunit.jar directory and run:
    java -Djavax.xml.parsers.DocumentBuilderFactory=oracle.xml.jaxp.JXDocumentBuilderFactory
    -jar domunit.jar
    The following options can adjust the tests:
    -Dnet.sourceforge.xmlconf.domunit.isExpandEntityReferences=true
    -Dnet.sourceforge.xmlconf.domunit.isCoalescing=true
    -Dnet.sourceforge.xmlconf.domunit.acceptXMLDeclPI=true
    To build the project, use either the JBuilder 4 .jpx file or
    the Ant 1.2 build.xml file.
    Curt Arnold http://xmlconf.sourceforge.net
    [email protected]
    18 April 2001
    domunit - DOM testing on the xUnit frameworks
    Copyright (C) 2001, Curt Arnold
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    null

    I haven't seen anyone from Oracle on the [email protected] mailing list, so I'm posting this here just to let you guys know.
    I've been working on recasting the NIST DOM test suite for Java to use JUnit and posted an initial release last night.
    The tests can easily be run against the beta XDK's parser (or any other JAXP compliant parser), but there were a substantial number test errors and failures. Some of these may be due to test problems, but I'd guess most of them are legitimate. However, I do not have time or the motivation to investigate them.
    It does seem that you take the position that the XML declaration is treated as a processing instruction (like MSXML does) which will cause 3 tests to fail, but you can adjust the tests to accept this using
    -Dnet.sourceforge.xmlconf.domunit.acceptXMLDeclPI=true
    I've made the source for my JUnit-hosted deriviatives of the NIST test suite available at http://xmlconf.sourceforge.net. You can either download the combined source and binary
    zip file from http://sourceforge.net/project/showfiles.php?group_id=8114&release_id=31676
    or you can access the source through the CVS (http://sourceforge.net/cvs/?group_id=8114)
    The tests run using JUnit 3.5 and can test JAXP 1.0 or JAXP 1.1 compliant DOM parsers.
    Xerces-J 1.3.1 does not report any test failures, crimson.jar and the other parser tested
    had a moderate amount of test failures, but no investigation has been performed to
    determine if those failures were problems with the tests or actual non-conformances
    with the spec.
    A JBuilder 4 .jpx project and an Ant 1.2 build.xml file are provided.
    ------- readme.txt from domunit 0.0.1 ---------
    domunit 0.0.1
    domunit currently contains equivalents of the NIST DOM 1 test written for
    the JUnit test framework (http://www.junit.org) and JAXP 1.1 or 1.0 compatible parsers.
    The tests were written to allow easy migration to JavaScript using JSUnit
    (http://www.jsunit.net) and CPPUnit (http://www.xprogramming.org/software)
    To run the full set of tests, place domunit.jar, junit.jar and one of the following
    combinations of jars in the same directory or on the class path.
    xerces.jar
    xml4j.jar
    jaxp.jar and parser.jar (from Sun's JAXP 1.0 Reference Implementation)
    jaxp.jar and crimson.jar (from Sun's JAXP 1.1 Reference Implementation)
    and run:
    java -jar domunit.jar
    To test Oracle's XML Processor, place jaxp.jar from the JAXP 1.0 (not 1.1) Reference Implementation
    and xmlparserv2.jar in the domunit.jar directory and run:
    java -Djavax.xml.parsers.DocumentBuilderFactory=oracle.xml.jaxp.JXDocumentBuilderFactory
    -jar domunit.jar
    The following options can adjust the tests:
    -Dnet.sourceforge.xmlconf.domunit.isExpandEntityReferences=true
    -Dnet.sourceforge.xmlconf.domunit.isCoalescing=true
    -Dnet.sourceforge.xmlconf.domunit.acceptXMLDeclPI=true
    To build the project, use either the JBuilder 4 .jpx file or
    the Ant 1.2 build.xml file.
    Curt Arnold http://xmlconf.sourceforge.net
    [email protected]
    18 April 2001
    domunit - DOM testing on the xUnit frameworks
    Copyright (C) 2001, Curt Arnold
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    null

  • Imported RAW images badly corrupted, looks like red paint splashed all over the sky.  Photoshop and Iphoto have no problem with the images from my D800E.  Aperture worked fine for me in June with the same camera.  The Nikon software shows no problem.

    I am having a problem importing my images into Aperture 3 from my Nikon D800E.  The images appear as if red paint was splashed across the sky.  The Nikon software used to transfer from the camera does not show this problem and Photoshop 6 is fine with the images exported as jpg from the Nikon software.  Aperature does not even like the jpg images usable by Photoshop.  I am suspecting that Aperture is not correctly using the camera raw file.  Also, the histograms are radically different between the corrupted images and the Photoshop (good) versions.  Aperture worked just fine for me in June with the same camera.  All drivers and software are current as of this posting.  Anyone else out there seen this before??

    Are you sure you do not have Highlight Hot & Cold Areas turned on? (View->Highlight Hot & Cold Areas)?
    The bug in Digital Camera raw only affected Raw images. In your first post you wrote:
    Aperature does not even like the jpg images usable by Photoshop
    If the JPG's have the same problem then it isn't this bug.
    regards

  • Javascript error on - Help - Learn how to use Numbers with this online...

    I am trying to find out more about Numbers. I am using iTunes 9.1.1 on a Vista PC. I get a Javascript error in Internet Explorer 8 when I try to access:
    Help - Learn how to use Numbers with this online resource.
    http://help.apple.com/numbers/1.0
    The link redirects to the following page:
    http://help.apple.com/iwork/safari/interface/#tan727163ed
    The above page is blank except for boxes for Keynote Help, Pages Help, Numbers help, and a blank input field that seems to do nothing. Here is the Javascript error message from Internet Explorer 8:
    Webpage error details
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
    Timestamp: Tue, 1 Jun 2010 20:55:54 UTC
    Message: This command is not supported.
    Line: 1
    Char: 41589
    Code: 0
    URI: http://help.apple.com/iwork/safari/interface/javascript.js

    Link also does not work for me in WIN 7 with IE8. However, it does work in Chrome in WIN 7. It also works in Safari on my G4. Suggest you try Chrome or it may work in another browser like FireFox or Safari in Vista.

  • Unexpected exceptions in JUnit with JDev 10.1.3 b3412

    Hi, I've checked for update and installed the JUnit plugin. While in 10.1.2, JUnit works well, in 10.1.3 I always receive unexpected exceptions, in the assert sentence.
    I've tried with the code in the Online Demonstration, "Using JUnit for Unit Testing"
    http://www.oracle.com/technology/products/jdev/collateral/papers/10g/reviewer/viewlets/JUnit_tests_viewlet_swf.html
    and when I run the 'AllTests.java' file, I have:
    java.lang.NullPointerException
         at money.mypackage.test.moneyTest.testAdd(moneyTest.java:27)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    The testcase says:
    public void testAdd() {
    money expected=new money(26,"CHF");
    money result=fixture1.f12CHF.add(fixture1.f14CHF);
    assertTrue(expected.equals(result)); <----- Line 27
    ¿What do you think?

    in general you could develop bpel 10.1.2.02 compliant processes, but it would create a bunch of possible hazards you could run into - deployment structure, new services, workflow and so on .. add'ly you cannot deploy from jdev 10.1.3.1 to bpel 10.1.2.0.2 server -- all in all not really recommendable, and not really supported too :D
    /clemens
    SOA Product Management

  • Creating TO using L_TO_CREATE_DN with SLED or Expiry Date????

    Hi Team,
    I am writing a Ztcode program for the TO creation using function module L_TO_CREATE_DN function module. But my requirement needs VFDAT (Expiry Date ) to be saved for the Trading Order which we create using tcode LT03, Were SLED, Shelf Expiry Date is required during creation with screen.
    Can anybody help how to create TO using FM with expiry date...
    Thanks in adavance, Help is as soon as possible would be grateful.
    Regards,
    Gaurav Patwari
    919967053678
    Edited by: GauravPa on Jun 13, 2011 1:47 PM

    please check the wm status in the inbound delivery, by this error message looks like plant+sloc is not wm managed ?also if possible Please share the screenshot of the putaway tab of delivery

  • Is it possible to use aim with a mac for free?

    Is it possible to use aim with a mac for free?

    If you mean the application AIM for Mac, it will depend on your download speed.
    If you mean "Can I use iChat with an AIM a screen name and does it cost anything ?" then the answer is Yes you can and no it does not cost and there is no download to do.
    If you mean "Can I use the AIM service with an @mac screen name and can this be done for free ? " then the answer is again yes.
    A trail account cost nothing and will work in ichat after the 60 days is up
    A Paid for but Lapsed account will also work in iChat and for this purpose can now be considered free.
    As I said and hinted at before your first question does not make it clear what you are actually asking.
    The Application AIM for Mac is stuck at version 4.7 and does not do Video or Audio Only chats.
    It has things that are useful in tweaking Buddy Lists in iChat but it is not specifically needed to contact AIM Buddies.
    9:00 PM Tuesday; June 24, 2008

Maybe you are looking for