Search in sources :

Example 61 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestRequires method testExpectedExceptionInsideTransactionWithCallback.

@Test
public void testExpectedExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
    ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
    ComponentInstance under = ipojoHelper.createComponentInstance("requires-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();
    try {
        cs.doSomethingBad2();
        Assert.fail("UnsupportedOperationException expected");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof UnsupportedOperationException);
    }
    Transaction t2 = cs.getCurrentTransaction();
    Assert.assertSame(t2, t);
    Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
    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());
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.transaction.services.CheckService) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 62 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestRequires method testExpectedExceptionInsideTransaction.

@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
    ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
    ComponentInstance under = ipojoHelper.createComponentInstance("requires-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);
    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();
    try {
        cs.doSomethingBad2();
        Assert.fail("UnsupportedOperationException expected");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof UnsupportedOperationException);
    }
    Transaction t2 = cs.getCurrentTransaction();
    Assert.assertSame(t2, t);
    Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
    t.commit();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.transaction.services.CheckService) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 63 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestRequires 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("requires-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());
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.transaction.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 64 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestRequires method testOkOutsideTransactionWithCallback.

@Test
public void testOkOutsideTransactionWithCallback() {
    ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
    ComponentInstance under = ipojoHelper.createComponentInstance("requires-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);
    cs.doSomethingGood();
    Assert.assertNull(cs.getLastRolledBack());
    Assert.assertNotNull(cs.getLastCommitted());
    Assert.assertEquals(1, cs.getNumberOfCommit());
    Assert.assertEquals(0, cs.getNumberOfRollback());
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.transaction.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 65 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestRequiresNew method testExpectedExceptionInsideTransaction.

@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
    ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
    ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-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);
    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();
    try {
        cs.doSomethingBad2();
        Assert.fail("UnsupportedOperationException expected");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof UnsupportedOperationException);
    }
    Transaction t2 = cs.getCurrentTransaction();
    Assert.assertNotSame(t2, t);
    Assert.assertEquals(Status.STATUS_NO_TRANSACTION, t2.getStatus());
    Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
    t.commit();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.transaction.services.CheckService) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

ComponentInstance (org.apache.felix.ipojo.ComponentInstance)373 Test (org.junit.Test)360 ServiceReference (org.osgi.framework.ServiceReference)215 Properties (java.util.Properties)142 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 CheckService (org.apache.felix.ipojo.handler.transaction.services.CheckService)65 Factory (org.apache.felix.ipojo.Factory)53 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)50 ServiceContext (org.apache.felix.ipojo.ServiceContext)47 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)39 IOException (java.io.IOException)29 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)22 BundleContext (org.osgi.framework.BundleContext)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 Dictionary (java.util.Dictionary)12 Hashtable (java.util.Hashtable)12 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)10 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)9