use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestMandatory method testOkOutsideTransactionWithCallback.
@Test(expected = RuntimeException.class)
public void testOkOutsideTransactionWithCallback() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
// Throws a RTE.
cs.doSomethingGood();
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestMandatory method testOkOutsideTransaction.
@Test(expected = RuntimeException.class)
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
// Fail !
((CheckService) osgiHelper.getServiceObject(ref)).doSomethingGood();
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestMandatory method testExpectedExceptionOutsideTransaction.
@Test(expected = RuntimeException.class)
public void testExpectedExceptionOutsideTransaction() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
// Throws a RTE
((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestMandatory method testOkInsideTransactionWithCallback.
@Test
public void testOkInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
Transaction t = tm.getTransaction();
cs.doSomethingGood();
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
t.commit();
Assert.assertNull(cs.getLastRolledBack());
Assert.assertNotNull(cs.getLastCommitted());
Assert.assertEquals(1, cs.getNumberOfCommit());
Assert.assertEquals(0, cs.getNumberOfRollback());
Assert.assertSame(t, cs.getLastCommitted());
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestNever method testExpectedExceptionOutsideTransaction.
@Test(expected = UnsupportedOperationException.class)
public void testExpectedExceptionOutsideTransaction() {
ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
ComponentInstance under = ipojoHelper.createComponentInstance("never-ok");
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
}
Aggregations