Problem with ORB.init and PowerMock

463 views
Skip to first unread message

John Lee

unread,
Jun 13, 2013, 7:12:26 AM6/13/13
to powe...@googlegroups.com
Hi,

Need some advice.

I need to use ORB for unit testing. Before adding in PowerMock, it was fine. (without Logger)
But once I include PowerMock to mock away my Logger, the ORB.init fails.
Here is the bit that failed.

@RunWith(PowerMockRunner.class)
@PrepareForTest({ Logger.class })
public class EventParserTMF814Test {
    ORB orb;

    @Before
    public void setUp() throws Exception {
        // setup static mocks
        PowerMockito.mockStatic(Logger.class);

        orb = ORB.init(new String[0], null);



I get the following Failure Trace:
java.lang.ExceptionInInitializerError
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:139)
    at javax.management.remote.rmi.RMIConnectionImpl_Stub.class$(RMIConnectionImpl_Stub.java:6)
    at javax.management.remote.rmi.RMIConnectionImpl_Stub.<clinit>(RMIConnectionImpl_Stub.java:41)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:139)
    at javax.management.remote.rmi.RMIConnector.<clinit>(RMIConnector.java:2096)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:37)
    at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:134)
    at java.lang.reflect.Field.acquireFieldAccessor(Field.java:945)
    at java.lang.reflect.Field.getFieldAccessor(Field.java:912)
    at java.lang.reflect.Field.get(Field.java:371)
    at com.ibm.CORBA.iiop.UtilDelegateImpl$2.run(UtilDelegateImpl.java:199)
    at java.security.AccessController.doPrivileged(AccessController.java:202)
    at com.ibm.CORBA.iiop.UtilDelegateImpl.<clinit>(UtilDelegateImpl.java:191)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at java.lang.J9VMInternals.newInstanceImpl(Native Method)
    at java.lang.Class.newInstance(Class.java:1345)
    at javax.rmi.CORBA.Util.createDelegateIfSpecified(Util.java:359)
    at javax.rmi.CORBA.Util.<clinit>(Util.java:70)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    at com.ibm.rmi.SubcontractRegistry.registerServerSubcontract(SubcontractRegistry.java:149)
    at com.ibm.rmi.SubcontractRegistry.registerDefaultSubcontracts(SubcontractRegistry.java:130)
    at com.ibm.rmi.corba.ORB.initializePrereqPlugins(ORB.java:569)
    at com.ibm.rmi.corba.ORB.orbParameters(ORB.java:1316)
    at com.ibm.rmi.corba.ORB.set_parameters(ORB.java:1242)
    at com.ibm.CORBA.iiop.ORB.set_parameters(ORB.java:1687)
    at org.omg.CORBA.ORB.init(ORB.java:364)
    at com.ibm.tivoli.netcool.integrations.corbaframework.tmf814.EventParserTMF814Test.setUp(EventParserTMF814Test.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:129)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:296)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl$PowerMockJUnit49MethodRunner.executeTestInSuper(PowerMockJUnit49RunnerDelegateImpl.java:116)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl$PowerMockJUnit49MethodRunner.executeTest(PowerMockJUnit49RunnerDelegateImpl.java:77)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:101)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.SecurityException: java.lang.NoSuchMethodException: javax.security.auth.SubjectDomainCombiner.<init>(javax.security.auth.Subject)
    at javax.security.auth.Subject.<clinit>(Subject.java:241)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
    ... 63 more



Johan Haleby

unread,
Jun 14, 2013, 8:18:20 AM6/14/13
to powe...@googlegroups.com
Could you show me what your code looks like? Is it a static logger field you want to mock?

Regards,
/Johan





--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at http://groups.google.com/group/powermock?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Lee

unread,
Jun 17, 2013, 6:17:05 AM6/17/13
to powe...@googlegroups.com

What I intend to do is to mock away the Logger, as I do not intend to see what is logged.
However I need to use ORB in order to generate the input data to test the implementation.
But before I can do that start creating the data I need to initialise the ORB.

However if I do not use PowerMock, and setup the Logger by printing to the console, I am able to initialize the ORB without any problem.

I'm just wondering is there something I am missing that needs to be configured such that PowerMockRunner is able to find where ORB is?

Thanks.

Johan Haleby

unread,
Jun 18, 2013, 1:40:32 AM6/18/13
to powe...@googlegroups.com
I don't think you want to mock the logger, perhaps you just want to get rid of it or replace the log method with something else? What logger implementation are you using?


Daniel Wittner

unread,
Jun 24, 2015, 7:06:17 AM6/24/15
to powe...@googlegroups.com
I have had the same problem and solved it by adding "@PowerMockIgnore("javax.security.auth.*")" to the test class.

Matt Lachman

unread,
Jun 24, 2015, 9:46:53 AM6/24/15
to powermock+...@googlegroups.com
For more options, visit https://groups.google.com/d/optout.

Akhil Vijayan

unread,
Jun 2, 2017, 3:57:24 AM6/2/17
to PowerMock
hi lee try doing this:create a private method like ORB orb=call();
where call() should have all those code you have put in your setup and return orb instance;
do it in ur injectmock itself.
hope it will be helpfull:)
Reply all
Reply to author
Forward
0 new messages