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.

Similar Messages

  • 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.

  • 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: 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.
    ~

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Creating junit test cases using the reflection API

    In order to use the reflection API to get information about a *.java file's class name and methods, I need to compile the *.java file first, and then get info through the *.class file. Am I right?
    Eclipse, the Java IDE, can create junit test cases for java files the user selects right after the *.java files have been created, and even before the *.java files have been compiled by the user. I guess Eclipse internally compiles the java files before creating JUnit test cases for them. Does anyone know about it? Thanks.

    Let me explain my problem in more details.
    Given any java source tree, my program is supposed to create junit test cases for each class using java reflection. My approach is to scan through the source tree to keep the list of classes available, then compile all the java files in the given source tree, then do Class.forName() to load them to get their methods... Obviously I don't know what classes I will have at compilation time. I create a temp_classes directory as the output directory for the given source tree java files, and I add temp_classes to my classpath when I strart up my own program. However, that won't work..
    D:\eclipse\workspace\cmpe271_hw4\classes>java -classpath ..\classes;..\temp_classes Test
    javac -classpath .\temp_classes; -d .\temp_classes @temp_classes\javalist.txt
    java.lang.ClassNotFoundException: Factory
    java.lang.ClassNotFoundException: InvalidDateFormatException
    java.lang.ClassNotFoundException: MyUtility
    java.lang.ClassNotFoundException: Storage

  • 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.

  • Using TimesTen for JUnit tests

    I want to switch from using HSQL (in memory) to TimesTen in my Unit tests. Is there a simple setup for TimesTen when used for this purpose?
    For example, for HSQL, all I have to do is include the hsql.jar as a dependency in my project, then include the following line in my JUnit test:
    DataSource dataSource = new DriverManagerDataSource("org.hsqldb.jdbcDriver",
    "jdbc:hsqldb:target/test-classes/com/project/path/test/schema", user, pw);
    schema is a reference to the schema.script that includes the DDL for all the tables that I need to create in memory.
    Can anyone help me out? Thanks.

    From what little I know about it TimesTen is not an in-memory database, it is a caching architecture. Therefore I would expect the set-up to be different - the TimesTen stuff should be set up once ever[], like the schema of a regular database, rather than everytime you run your unit tests.
    I think you need to sit down with the TimesTen documentation and figure out how you are going to use the product. If you are just looking for a quick DB to use in unit tests I think you may well want to keep using HSQL.
    Cheers, APC

  • Getting error while writing JUnit test case for RestFul Services

    Hi All,
    I have written Restful services in Netbean 6.8.
    It's running well...no issues.
    {color:#0000ff}While writing JUnit test cases for them, I am getting following error:
    {color}{color:#993300}Testcase: testGetAuthenticated(com.ct.services.LoginServicesTest): Caused an ERROR
    Implementing class{color}
    java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:160)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:65)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    at com.ct.services.LoginServices.getAuthenticated(LoginServices.java:205)
    at com.ct.services.LoginServicesTest.testGetAuthenticated(LoginServicesTest.java:84)
    Test com.ct.services.LoginServicesTest FAILED
    F:\NetbeanProjectsWorkspace\DemoProject\nbproject\build-impl.xml:972: Some tests failed; see details above.
    BUILD FAILED (total time: 11 seconds)
    {color:#0000ff}Strange thing is that when I am commenting below lines and its related calls:
    {color}
    {color:#ff0000}EntityManagerFactory mEmf = Persistence.createEntityManagerFactory("AnyName");
    EntityManager mEm = mEmf.createEntityManager();
    {color}
    {color:#0000ff}from my code, JUnit test cases are working fine.
    {color}Anybody having any idea about this ?
    Thanks
    Avi
    Edited by: Avi007 on Aug 28, 2010 5:17 AM

    Hi All,
    [http://stackoverflow.com/questions/2778295/test-driven-development-problem]
    Please refer the above link for the solution
    Thanks
    Avi
    Edited by: Avi007 on Aug 30, 2010 12:33 AM

  • How to create process code for idoc bank_create01 in testing client

    hi,
    I am using Idoc BANK_CREATE01 and BANK_CHANGE01  to post idoc to R/3 in inbound side.
    there is no standard process code available for this idoc
    But there is a function module idoc_input_bank_create which posts data to r/3 from the idoc.
    So i created a zprocess code and attached this function module to it.
    But all this i have done in the development client , but it is not being reflected in the testing client
    And i am not able to create Process code in we42 in testing client since it is not modifiable.
    So , is transaction we42 client 42??
    Or is there any way that whatver i create in dev client should also reflect in testing client
    Please help
    Regards,
    Loveena

    Hi,
    While Creating the process code u have to save under transport ID under which id u have stored it,transfer that id into QA system then u can test ur IDOC.
    If u have created it under local object then u have to agin store into one tranport id and then transfer it.
    Regards,
    Phani
    Reward points if Helpful

  • Best practice for @EJB injection in junit test (out-of-container) ?

    Hi all,
    I'd like to run a JUnit test for a Stateless bean A which has another bean B injected via the @EJB annotation. Both beans are pure EJB 3 POJOs.
    The JUnit test should run out-of-container and is not meant to be an EJB client, either.
    What is the easiest/suggested way of getting this injection happening without explicitely having to instantiate the bean B in my test setup ?

    you can deal with EntityBeans without having the Container managed senario , you can obtain instance of EntityManager using the "EntityManagerFactory" and providing the "persistence.xml" file and provide the "provider" (toplink,hibernate ,...), then you can use entities as plain un managed classes

  • [svn:fx-trunk] 5386: * Fix for Flex Builder JUnit tests.

    Revision: 5386<br />Author:   [email protected]<br />Date:     2009-03-18 08:03:11 -0700 (Wed, 18 Mar 2009)<br /><br />Log Message:<br />-----------<br />* Fix for Flex Builder JUnit tests.<br /><br />tests Passed: checkintests, performance testsuite<br /><br />Needs QA: YES<br /><br />Needs DOC: NO<br /><br />API Change: NO<br /><br />Reviewer: Pete F.<br /><br />Code-level description of changes:<br /> <br />  compiler/CompilerAPI.java<br /><br />    Changed the deleted Map used in validateCompilationUnits() and<br />    some of it's helper methods from <String, Source> to <QName,<br />    Source>.  This allows us to track when a definition is deleted<br />    from one SWC in the library path and then added by another SWC in<br />    the library path.  All the definitions dependant on the definition<br />    need to be recompiled and we were missing this before.<br />    Specifically, the Flex Builder JUnit tests were switching from<br />    airglobal.swc to playerglobal.swc midstream.  As a result, we<br />    weren't recompiling classes that depended on<br />    flash.display.DisplayObjectContainer, because it looked like it<br />    hadn't been deleted.<br /><br />Modified Paths:<br />--------------<br />    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/CompilerAPI.java<br />    flex/sdk/trunk/modules/compiler/src/java/flex2/tools/oem/Library.java

  • Creating custom edit step (LV) for multiple numeric test

    Hello,
    i want to write a custom edit step (LabView) for a custom multiple numeric test (TestStand 3.0). It should be the replacement for the editmultinumericmeasurementstep. Have anybody done this before and example code or a solution?
    greetings schwede

    Hello,
    thankyou for your answer. But it doesn`t help. I know how to create a custom step type. But I want to create a custom multiple numeric limit test step type with a custom vi as the editmultinumericmeasurementstep. It is quiet difficulty, because i want to create my own measurements (see the attachment). The name of the test should not be measurement 0 or 1 but LED test color oder LED test intensity.
    greetings schwede
    Message Edited by Schwede on 12-06-2007 02:42 AM
    Attachments:
    Test.rtf ‏1414 KB

  • Question about writing Junit test for SQLj application

    Just inherite a SQLj application without unit test. After making few enchancement I plan to add unit test about it to make it more solid. What I plan to do is invoke SQLj translator dynamically to generate java source, then compile and invoke the result class dynamically at Junit test. Does anyone how to call SQLj translator as an API call ??

    I guess I might add that the error I am getting is
    java.lang.nullPointerException
    i've got this now:
         public E top() throws EmptyStackException {
              if (numItems == 0)
                   throw new EmptyStackException("Stack is empty");
              return S[numItems--];
         }With the same test, as it would throw an emptystackexception not a full..
    But the test still doesn't pass.

  • JUNIT test failure-Configuration file bc4j.xcfg not found in the classpath

    Hi All,
    As part of an ESS project,Im having a model project containing a VO(parameters VO).This VO is configured to have Read-only access through SQL query and have only one transient attribute each.For the model projects containing the VO for pre merge checker compliance I had to create JUNIT Test projects containing new AMs for testing the parametersVO. While running the JUNIT tests I got an exception like
    “oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.ConfigException, msg=JBO-33001: Configuration file /oracle/apps/hcm/goals/core/dataMigration/publicEssModel/test/applicationModule/common/bc4j.xcfg is not found in the classpath.”.—even though this file is contained in both the src/classes folder of the project.
    When i try to run the TestAM I'm getting an exception like 'configuration tester.xcfg not found in the calsspath.
    While debugging this error, we found that we are able to successfully run the JUNIT tests if we make some changes in the adf-config.xml file of the Application. The change required is to comment out the mdsC:adf-mds-config tag in the xml file.
    After doing this change Im also able to run my AM without any exception.
    Is this a known issue?.
    Since modifying the adf-config.xml is not a recommended practice is there any workaround that we can get rid of this exception.
    Regards,
    Ajin.

    Just checked but could only find this thread Unable to run ADFBC JUNIT Test Classes with JDEV11G 11.1.1.6
    As it's also dealing with junit and 11.1.1.6.0 you might want to read it.
    Timo

Maybe you are looking for