JUnit test fixture where constructor of base object throws exception

I'm trying to construct a test case which requires an object whose constructor currently throws and exception (it tries to make a connection which isn't currently available).
Now normally the trick would be to construct a test fixture class which extends the base class and returns the stuff I want. The trouble is I can't cope with an exception in in super constructor. Is there any way out of this, short of refactoring the offending base class?

Just use the no-arg constructor of RootRenderingContext, and all should be defaulted appropriately.

Similar Messages

  • Creating a RenderingContext for a JUnit test Fixture

    I have created a Java class to supply the current date. Code follows. I have created a JUnit TestCase and TestFixture. I need to create and populate a RenderingContext for the TestFixture. Since RenderingContext is an interface, I suppose that I create an instance using a RootRenderingContext constructor. However, I am unsure of where the default RendererManager is found and even more unsure about using the RendererManager constructor to obtain a new instance. Guidance is requested.
    BTW I realize that the class itself does not really need testing, but when the DataObject returned gets more complicated, testing will be needed.
    Thanks,
    Bill
    import oracle.cabo.ui.RenderingContext;
    import oracle.cabo.ui.data.BoundValue;
    import oracle.cabo.ui.data.DataObject;
    import java.util.Date;
    * Provides a <code>CurrentDate<code> to a <code>BoundValue<interface.
    * This is needed because UIX UINode trees stay resident after being
    * intitialized. Components will ask for the date every time it has to render
    * the page.
    * @author UIX Developers Guide Chapter 4 Data Binding
    * @version 1.0
    public class CurrentDate {
    static public DataObject getValue(RenderingContext context, String namespace, String name) {
    return (DataObject) new Date();
    }

    Just use the no-arg constructor of RootRenderingContext, and all should be defaulted appropriately.

  • Unable to run ADFBC JUNIT Test Classes with JDEV11G 11.1.1.6

    Dear All,
    I upgraded my project to the latest release JDEV 11G 11.1.1.6
    Previously we are on JDEV 11G 11.1.1.5
    I have a JUNIT class that I am running which test my ADFBC components.
    public class MyTestClass {
      @Test
      public void testVOAccess()
        //assertions
    }Unfortunately, I am hitting an error like this from the messages.
    Mar 9, 2012 1:28:07 PM oracle.adf.share.ADFContext getCurrent
    WARNING: Automatically initializing a DefaultContext for getCurrent.
    Caller should ensure that a DefaultContext is proper for this use.
    Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.
    This message may be avoided by performing initADFContext before using getCurrent().
    For more information please enable logging for oracle.adf.share.ADFContext at FINEST level.
    Mar 9, 2012 1:28:08 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
    SEVERE: org.xml.sax.SAXParseException: Invalid encoding name "Cp1252".
    Mar 9, 2012 1:28:10 PM oracle.mds
    NOTIFICATION: PManager instance is created without multitenancy support as JVM flag "oracle.multitenant.enabled" is not set to enable multitenancy support.
    Mar 9, 2012 1:28:12 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
    SEVERE: org.xml.sax.SAXParseException: Invalid encoding name "Cp1252".
    Mar 9, 2012 1:28:12 PM oracle.adf.share.jndi.ReferenceStoreHelper getReferencesMapEx
    WARNING: Incomplete connection reference object for connection:MYDATASOURCEAt the JUNIT Test Runner, I see this.
    java.lang.ExceptionInInitializerError: null
         java.lang.reflect.Constructor.newInstance(Constructor.java:513)
         org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:171)
         org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:216)
    Caused by: oracle.jbo.DMLException: JBO-26061: Error while opening JDBC connection.
         oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:207)
         oracle.jbo.server.ConnectionPool.instantiateResource(ConnectionPool.java:166)To validate the issue, I tried to run my same project using the older release which is JDEV 11G 11.1.1.5
    and I see that I am not hitting any error. All my test classes runs fine.
    Has anybody replicated this?
    Thanks

    Didier Laurent wrote:
    I logged the following bug for this issue:
    bug 14030895 - REGR: JDEVELOPER 11.1.1.6.0 JUNIT JBO-26061 ERROR WHILE OPENING JDBC CONNECTION
    Regards,
    Didier.So its really a bug..
    I abandon this already since I cannot find any solution to look up for this.
    On the other hand, I am maintaining two jdeveloper version just to get around this problem.
    When testing ADFBC, I used the 11.1.1.5 while for non-junit test I used the 11.1.1.6
    Hopefully this gets fixed on the next release as I am having a hard time swithcing between two JDev version.
    Thanks
    Edited by: Neliel on May 3, 2012 11:42 PM

  • Re: junit test for entity beans ... ejb 3.0

    I'm confused. I'm trying to test my entity bean.
    I have:
    - an entity bean
    - a stateless session bean for accessing the entity bean (facade)
    - an interface for accessing the the stateless bean
    And I'm trying to write a JUnit test class to test this bean. However, I am uncertain as to how to test this (I'm new to EJB 3.0, JBoss and Eclipse).
    What would the JUnit test look like? I'm confused as to whether or not I should be injecting the interface/bean/what???
    I've tried several variations. I either get "NameNotFound" - not bound exceptions or Null pointer exceptions.
    What would the @EJB syntax look like or how would I do it through the context?
    For Example:
    @EJB private TestFacade myTest; //interface to stateless bean ?
    OR
    InitialContext ctx = new InitialContext();
    TestResultFacadeBean myTest = (TestResultFacadeBean) ctx.lookup("localTest");
    I'm confused at to which method I should be using and what object I should be accessing. If I could get either one to work, I'd be happy. :)
    How do I ensure my bean is deployed to the container? What do I need to do?
    If anyone has a simple example or explanation as to which method I should use and how to use it, I'd be very grateful.
    Thanks very much,
    LisaD

    OK, you need to have several layers of testing.
    Layer 0. Test the entity beans are deployable (more on this later). Basically, you need to know that all your annotations work. Things to watch out for are multiple @Id fields in one class or @EmbeddedID or @IdClass in conjuction with @ManyToOne, @ManyToMany, @OneToMany, @OneToOne and fun with @JoinTable, @JoinColumn and @JoinColumns. Once you know how these are supposed to work with the spec, it's not too bad to write it correctly each time. But there are some gotchas that will break things later on.
    Layer 1. Do the functions in the classes that don't depend on annotations work as expected. Typically, this is just going to be the getters and setters in your entity classes. Of course JUnit best practice says we don't bother testing functions that look like:
    public T getX() {
    return this.x;
    or
    public void setX(T x) {
    this.x = x;
    as there is nothing that can go wrong with them. So in that case, your level 1 tests will just be initial values specified from constructors and verifying that the non-get/set pairs work, and that the getters you have tagged @Transient work (because you've likely put some logic in them)
    Layer 2. Test the session bean methods that don't require injection to work.
    Layer 3. Test the session bean methods that require injection (Mock Objects). Simulate the injection for yourself, injecting Mock Objects for the entity manager. Then you can confirm that the correct methods are being called in the correct sequences, etc.
    [Note this may require some skill in designing the mock.  I'm working on developing my own entitymanager mock, and if it looks usefull I'll release it to the world.
    Layer 4. Test the session bean methods that require injection (Real entity manager) (See Layer 0)
    For this you will need an out of container persistence implementation.  Currently Hibernate and Glassfish provide beta versions.  You will need a different persistence.xml file that lists all the entities.  You will have to use reflection to inject the entity manager(s) that you create from an entity manager factory unless you provide a constructor that takes an EntityManager as a parameter.  You may need to use reflection to call any @PostConstruct method if you made it private.
    Layer 5. Navigate the relationships in the objects returned from Layer 4 using a database that has been loaded with test data.
    I am currently using Layers 0, 1, 2 & 4 to test my session beans and entity beans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Junit testing of WLI BMP 2.1

    Does anyone know where I can find an example of Junit test scripts for testing
    a Workflow Scenario. Not just the individual java classes (activity or task)
    but from end-to-end testing.

    You create two ObjectOutputStreams. I don't know if that can cause problems. I think it does write two stream headers to the socket, which could mess up the protocol. Any exceptions at the other end of the connection? Put logging there to see if it gets the object and sends a response.
    Just for paranoia I'd move the ObjectInputStream creation to before writing anything on the output stream.
    Hit control-\ (Unix) or control-break (Windows). Where is it stuck? Show us the stack trace for that thread.

  • Persist does not throw any exception in a JUnit test

    I am implementing a JUnit test using Toplink as JPA provider. I must be missing something because I try to persist two times the same entity and no exception is thrown. Neither PersistenceException nor any other type of exception. The code cannot be easier:
    @Test
    public void testAddExistingTeam() throws Exception {
    Team team = new Team("team2");
    try{     
    EntityManagerFactory emf =
    Persistence.createEntityManagerFactory("fofo");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    em.persist(team);
    em.persist(team);
    em.getTransaction().commit();
    em.close();
    catch(Exception e){
    e.printStackTrace();
    Notice the two em.persist(team).
    This code does not seem to either enter the catch block or produce any sort of exception. On the other hand, I have checked that after the first
    em.persist(team); the team is really managed.
    The relevant parts of the Team class definition follow:
    @Entity
    @Table (name ="TEAM")
    public class Team implements Serializable {
    @Id
    @Column (name="NAME")
    private String name;
    @ManyToOne
    @JoinColumn (name="CLUB_NAME", referencedColumnName="NAME")
    private Club club;
    private Category category;
    private String email;
    @ManyToMany(mappedBy="teams")
    private List<Competition> competitions;
    public Team (String name){
    this.name = name;
    this.club = null;
    this.competitions = new ArrayList<Competition>();
    ....getters/setters....and more constructors.
    I am really puzzled by this issue. Somebody could help??? I would be really grateful!!!
    Josepma

    This is expected behavior as persist is a no-op if called on a managed entity (other than to cascade over relationships marked with cascade.Persist), and the first persist call makes the passed in team entity managed.
    Try calling em.flush(); and em.clear(); between the persist calls to get an exception.
    The first flush will ensure the team is inserted in the database, while clear will detach it so that the second persist call will try to insert the team. JPA providers are not required to throw the entityExistsException on persist - it can be delayed until the transaction is flushed or committed, so you are likely to get a PersistenceException from the commit instead of EntityExistsException from persist.
    Best Regards,
    Chris

  • Copy constructor and temporary objects in C++

    I'd need some clarification on how constructor works when the argument is  a temporary object. I defined a dummy MyVect class with operator+ and copy constructor:
    class MyVect {
    public:
    MyVect() {
    cout << "Constructor" << endl;
    MyVect(const MyVect &vect){
    cout << "Copy Constructor" << endl;
    ~MyVect() {
    cout << "Destructor" << endl;
    MyVect operator+(const MyVect &v) const {
    cout << "operator+" << endl;
    MyVect result
    return result;
    Then I test it with this very simple code pattern:
    MyVect v1;
    MyVect v2;
    MyVect v3(v1 + v2);
    The output is:
    Constructor
    Constructor
    operator+
    Constructor
    Destructor
    Destructor
    Destructor
    The first two constructor calls are for v1 and v2, then operator+ for  v1+v2 is called, and  inside it there is a constructor call for result object. But then no copy constructor (nor constructor) for v3 is called. In my limited understanding of C++, I guessed that once the temporary object resulting from v1+v2 has been created, then it would be the argument of the copy constructor call. Instead it looks like the compiler transforms the temporary into v3, since v3 is correctly initialized as the sum of v1 and v2 (I tried with a more complicated version of MyVect to verify this). This behavior reminds me of the move semantics introduced with C++11, but I'm not using the -std=c++11 flag (and in fact if I try to define a move constructor the compilation fails).
    Can anyone please help me to understand what's happening under the hood? Thanks.
    Last edited by snack (2013-02-13 10:44:28)

    wikipedia wrote:The following cases may result in a call to a copy constructor:
    When an object is returned by value
    When an object is passed (to a function) by value as an argument
    When an object is thrown
    When an object is caught
    When an object is placed in a brace-enclosed initializer list
    These cases are collectively called copy-initialization and are equivalent to:[2] T x = a;
    It is however, not guaranteed that a copy constructor will be called in these cases, because the C++ Standard allows the compiler to optimize the copy away in certain cases, one example being the return value optimization (sometimes referred to as RVO).
    Last edited by Lord Bo (2013-02-13 13:58:47)

  • Junit test cases -error in creating Application Module

    I am on JDeveloper 9i with OA Extension installed build 1550. I am trying to run Business Components Test Fixtures and getting the following error in setUp method of the fixture class at the following line
    _am = Configuration.createRootApplicationModule("mycompany.oracle.apps.xxsan.invoiceholds.server.InvoiceHoldsAM", "Development");
    The exception below..
    java.lang.NoSuchMethodError: oracle.xml.parser.v2.SAXParser.setContentHandler(Lorg/xml/sax/ContentHandler;)V
    at oracle.jdeveloper.cm.DefaultConnectionStore.read(DefaultConnectionStore.java:182)
    Anybody who have used Junit successfully to test their business components. Would appreciate any feedback.
    Thank you.
    Arun

    Well I guess i figured it out myself. I use the findApplicationModule before calling the createApplicationModule. Apparently, bc4j does not like creating multiple application modules...it should just reuse the existing one instead of throwing this obscure invalid name exception.

  • Writing JUnit test app to test a method which uses AppResources

    Recently I was given a requirement to write a JUnit class( with main) to test a method in a Processor class which is running in weblogic. But this method in processor class makes use of AppResources like this: AppResources appResources = new AppResources("ApplicationResources"); String ruleFileName = appResources.getResourceString("rule.file.irlfile"); But when I try to run my JUnit test (stand alone app with main class) I am getting "java.util.MissingResourceException: Can't find bundle for base name ApplicationResources" exception. The appResources is null... Any ideas how to work around this problem?

    It doesn't sound like the Process class was designed for testability outside of its J2EE server container, probably. So writing a unit test for it, under its current design, may be an exercise in futility. You might want to look into "Cactus" tests (search for JUnit Cactus on the web), to test it in its container. Or, redesign the class for testability, separating its business logic better (that's a lot of work to do though) so that it can be instantiated and exercised independently of its environment.

  • Pinball test fixture

    I am real new to Labview and I thought this would be a simple project to help me with the learning process. 
    I want to build a test fixture for the Pinball machine pcbs.  I have a number of them in storage from different manufactures.  I think most of this is just going to be inputing a closed switch message to either the lamp matrix or the solinoid drivers and then monitoring the outputs to see if the lamp light or solinoid fired.  This is where I want to start.
    Could I get an idea and overview of the hardware and basic Labview software approach you would use to do this?
    I have a PCI-6035E and a PCI-6534.
    Is there some hardware that would make this easier to create or will I need to create a test jig to to buffer the signals before going into the PCI cards?
    I am just looking for some general ideas on how to approach this.
    Thanks
    Kevin

    Hello uriahsky,
    I would like to point you toward some helpful links in finding common LabVIEW architectures as well as how to utilize the DAQ resources you've mentioned below. I would recommend that you also browse through the available LabVIEW examples as a getting started point for a new application in which you may then use DAQmx functions (highlighted in the getting started link below) to then control your hardware. 
    http://www.ni.com/gettingstarted/labviewbasics/  (Introduction to NI LabVIEW)
    http://www.ni.com/gettingstarted/labviewbasics/exa​mples.htm  (Finding Examples for NI LabVIEW) 
    http://www.ni.com/white-paper/2926/en  (Using a State Machine (Event Driven) Architecture)
    http://www.ni.com/white-paper/3022/en  (Application Design Patterns: Master/Slave)
    http://www.ni.com/white-paper/3023/en (Application Design Patterns: Producer/Consumer)
    http://www.ni.com/white-paper/5434/en  (Getting Started with NI-DAQmx: Main Page)
    Wes W
    Application Engineering
    National Instruments
    www.ni.com/support

  • No base object information for AQ$_PROP_TABLE_1

    Hi all,
    My alert log is stating that there is no base object information for the AQ$_PROP_TABLE_1 table? This table is owned by sys which is preventing me from preparing the table.
    Q1) How did the database end up in the state?
    Q2) How do I fix it?
    I'm running 9.2.0.3.
    WARNING: no base object information defined in logminer dictionary!!!
    knlldmm: gdbnm=HLRDB.SITE1
    knlldmm: objn=6850
    knlldmm: objv=1
    knlldmm: scn=1004390
    SQL> select OBJECT_NAME from dba_objects where OBJECT_ID=6850;
    OBJECT_NAME
    AQ$_PROP_TABLE_1
    Enter user-name: sys as sysdba
    Enter password:
    Connected.
    SQL> begin
    2 DBMS_CAPTURE_ADM.PREPARE_TABLE_INSTANTIATION('AQ$_PROP_TABLE_1');
    3 end;
    4 /
    begin
    ERROR at line 1:
    ORA-12087: online redefinition not allowed on tables owned by "SYS"
    ORA-06512: at "SYS.DBMS_CAPTURE_ADM_INTERNAL", line 74
    ORA-06512: at "SYS.DBMS_CAPTURE_ADM", line 159
    ORA-06512: at line 2
    Many thanks,
    Warren

    Select the image you'd like to use as the placeholder, and assign it a "name" in the Inspector - also make sure that the name only contains standard letters, numbers or underscores and starts with a letter (no spaces or punctuation). Does it show up in the Actions menu after that?

  • Static Inheritance, Constructors --- Classes as objects

    First I asked myself why constructors are not inherited.
    Then I asked myself why Static Methods are not inherited.
    And it all seems to come down to, why Classes are not objects in Java as they are in Smalltalk?
    Is there any reason I'm missing?
    I would love at least inheritable static methods.

    That's OK, but that method would not be inherited, and would execute in the context of the superclass.
    Picture this (a simple "template method"):
    class SuperClass {
         public static void staticMethod() {          
              System.out.println("Static in SuperClass");
              other();          
         public static void other() {          
              System.out.println("other in SuperClass");
    class SubClass extends SuperClass{
         public static void other () {
              System.out.println("other in SubClass");
    Here, I just want to redefine other() in SubClass, but it calls the SuperClass version.
    Let's test:
    public class Test {
         public static void main(String[] args) throws DatabaseErrorException, TableUpdateException {
              SuperClass.staticMethod();
              SubClass.staticMethod();
    Output:
    Static in SuperClass
    other in SuperClass
    Static in SuperClass
    other in SuperClass
    First line calls static in SuperClass, which calls other (found in SuperClass and executed), the output from other is second line.
    Then, the third line shows calling staticMehod in SubClass, which doesn't redefine it, and executes the SuperClass version, that's ok, but when staticMethod calls other, it doesn't look for it in SubClass, but it directly executes the one in SuperClass (which is shown in line 4).

  • Base object costing

    i need an overview of base object costing and base object planning in product costing with an scenario where it is exactly used

    HI,
    I guess, you are referring to 'Base Planning Object' in simulation costing.
    Base planning object allows you to enter a quantity structure manually, so you can costs without accessing BOMs, routings etc., With this you can cost new products (without material master). It is like a master record (with your own name) for which can create a cost estimate. It is excel like sheet where you can enter you costs. You still refer to a Costing variant here which is not the normal cost variant, though.
    So, this functionality is used in simulation costing, especially for new products for which you don't have the master data defined in SAP.
    Check this [link|http://help.sap.com/saphelp_erp60_sp/helpdata/en/cf/6fe5bc414f11d182b10000e829fbfe/frameset.htm] for more details.
    Hope this helps.

  • Re: Creating a seperate project for Junit Tests.

    Hello,
    I was wondering if its possible to have all the test cases form different projects in a single project(which would only contain all Junit test cases) and then fire these tests from that single project.
    So the idea is to have multiple projects but all the Junit tests would be compiled in a single project. Is there any way i can accomplish this.
    Thanks

    qwerty.123 wrote:
    Yes that is correct. But in order to do this i need my test class to be in the same package as my class which is tested. That's why one should use the same package structure in your test source directory as you do in your regular source directory.
    For example:
    myproject/src/main/java/some/package/MyClass.java
    myproject/src/test/java/some/package/MyClassTest.java
    Where myproject/src/main/java and myproject/src/test/java/ are both source folders in your project's build path.
    Is there any way i can run a test for a class which is in a different project/package altogether and my test class lying in a seperate Project/package.Sure; you just won't have access to "package-private" classes and members.
    ~

  • Table for Customizing and BASIS objects

    Hi all,
    Is there any table/view which stores a list of all customizing and BASIS objects created in the SAP system (something like table TADIR for programs)?
    I should be able to query against that table and find if a particular customizing objects exists or not.
    Regards,
    Saurabh

    Hi Saurabh,
    here in table SMODILOG...if u fatch data with condition...
    where ( OBJ_TYPE = 'CUSO' or
               OBJ_TYPE = 'ACGR' ) and
              OBJ_NAME <> Y*string or
              OBJ_NAME <>  z*string.
    This will get you the objects that you want.
    <b>Reward helpful answers with points,</b>
    Regards,
    Tejas

Maybe you are looking for

  • I just bought a 2gb shuffle and i have more music than it can hold in my itunes acct. How can i sync only the certain playlists on the shuffle?

    I just bought a 2 gb shuffle and I have more music in my itunes than it can hold.  How can i sync only the certain playlists on the shuffle?

  • Final Rebate Settlement Issue

    Hi All, When i am trying to make final settlment of rebate system is giving me error "The sales volume for this agreement is not current'. I am unable to process final settlement and even sales volume in rebate agreement is showing 0. Please give me

  • Urgent Help, Scripting duplicate page

    This is my XML structure: <courses> <course> <name></name> <title></title> <sectionname></sectionname> </course> </courses In my Indesign template, I have 1 page with a main placeholder for the course. I have another placeholder on the side of the pa

  • Images not showing in firefox

    Hello! I'm using the following code: <s:Image width="40" height="40"                                           click="novoProjecto(event)"                                           id="novoProj"                                           buttonMode="t

  • Flash Player Hangs Firefox Severly

    Hello, I am using windows 7 Ultimate 64 bit 16 GB RAM Core i7 3.4 GHz SSD Hard disk Flash Player 11.4 Firefox 15 The problem that I am facing is when I try to play a flash game it hangs the whole firefox and not only that GAMES SPEED is higly effecte