Search in sources :

Example 6 with IPentahoObjectReference

use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.

the class RuntimeObjectFactory method getAll.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <T> List<T> getAll(final Class<T> interfaceClass, final IPentahoSession session, final Map<String, String> properties) throws ObjectFactoryException {
    List<IPentahoObjectReference<T>> retValReferences = getObjectReferences(interfaceClass, session, properties);
    List<T> retVals = new ArrayList<T>();
    for (IPentahoObjectReference ref : retValReferences) {
        retVals.add((T) ref.getObject());
    }
    return retVals;
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) ArrayList(java.util.ArrayList)

Example 7 with IPentahoObjectReference

use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.

the class StandaloneSpringPentahoObjectFactoryTest method testReferences.

public void testReferences() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    IPentahoObjectReference reference = PentahoSystem.getObjectReference(MimeTypeListener.class, session);
    assertEquals("30", reference.getAttributes().get("priority"));
    assertEquals(((MimeTypeListener) reference.getObject()).name, "Higher Priority MimeTypeListener");
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 8 with IPentahoObjectReference

use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.

the class RuntimeObjectFactoryTest method testGetObjectReferences.

@Test
public void testGetObjectReferences() throws Exception {
    IPentahoSession session = new StandaloneSession("joe");
    RuntimeObjectFactory factory = new RuntimeObjectFactory();
    final SingletonPentahoObjectReference<String> something1 = new SingletonPentahoObjectReference<String>(String.class, "Something1", Collections.<String, Object>emptyMap(), 0);
    final SingletonPentahoObjectReference<String> something2 = new SingletonPentahoObjectReference<String>(String.class, "Something2", Collections.<String, Object>emptyMap(), 1);
    factory.registerReference(something1);
    factory.registerReference(something2);
    List<String> out = factory.getAll(String.class, PentahoSessionHolder.getSession());
    assertEquals(2, out.size());
    List<IPentahoObjectReference<String>> refs = factory.getObjectReferences(String.class, session);
    assertSame(something1, refs.get(1));
    assertSame(something2, refs.get(0));
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) Test(org.junit.Test)

Example 9 with IPentahoObjectReference

use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.

the class OSGIObjectFactoryTest method testObjectDefined.

@Test
public void testObjectDefined() throws Exception {
    ServiceReference<String> ref = Mockito.mock(ServiceReference.class);
    ServiceReference ref2 = Mockito.mock(ServiceReference.class);
    when(mockContext.getServiceReference(String.class)).thenReturn(ref);
    when(mockContext.getServiceReference(String.class.getName())).thenReturn(ref2);
    IPentahoObjectReference mockIPentahoObjectReference = Mockito.mock(IPentahoObjectReference.class);
    when(mockIPentahoObjectReference.getObject()).thenReturn(ref);
    List<ServiceReference<String>> mockServiceList = new ArrayList<ServiceReference<String>>();
    mockServiceList.add(ref2);
    when(mockContext.getServiceReferences(String.class, null)).thenReturn(mockServiceList);
    assertEquals(true, factory.objectDefined(String.class));
    assertEquals(false, factory.objectDefined(Integer.class));
    assertEquals(true, factory.objectDefined(String.class.getName()));
    assertEquals(false, factory.objectDefined(Integer.class.getName()));
    try {
        factory.objectDefined((String) null);
        fail("Should have thrown IllegalStateException");
    } catch (IllegalStateException e) {
    }
    try {
        factory.objectDefined((Class) null);
        fail("Should have thrown IllegalStateException");
    } catch (IllegalStateException e) {
    }
    verify(mockContext).getServiceReferences(String.class, null);
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 10 with IPentahoObjectReference

use of org.pentaho.platform.api.engine.IPentahoObjectReference in project pentaho-platform by pentaho.

the class OSGIObjectFactoryTest method testGetObjectReferencesWithQuery.

@Test
public void testGetObjectReferencesWithQuery() throws Exception {
    ServiceReference<String> ref = (ServiceReference<String>) Mockito.mock(ServiceReference.class);
    ServiceReference<String> ref2 = Mockito.mock(ServiceReference.class);
    when(mockContext.getServiceReferences(String.class, "(name=foo)")).thenReturn(Arrays.asList(ref, ref2));
    when(mockContext.getServiceReferences(Integer.class, null)).thenThrow(new InvalidSyntaxException("bad", "call"));
    when(mockContext.getService(ref)).thenReturn("SomeString");
    when(mockContext.getService(ref2)).thenReturn("SomeString2");
    // props
    when(ref.getPropertyKeys()).thenReturn(new String[] { "name" });
    when(ref.getProperty("name")).thenReturn("foo");
    when(ref2.getPropertyKeys()).thenReturn(new String[] { "name" });
    when(ref2.getProperty("name")).thenReturn("foo");
    List<IPentahoObjectReference<String>> objectReferences = factory.getObjectReferences(String.class, session, Collections.singletonMap("name", "foo"));
    assertNotNull(objectReferences);
    assertEquals(2, objectReferences.size());
    assertEquals("SomeString", objectReferences.get(0).getObject());
    assertEquals("SomeString2", objectReferences.get(1).getObject());
    objectReferences = factory.getObjectReferences(String.class, session, Collections.singletonMap("name", "bar"));
    assertTrue(objectReferences.isEmpty());
    verify(mockContext).getServiceReferences(String.class, "(name=foo)");
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)15 ArrayList (java.util.ArrayList)7 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)6 Test (org.junit.Test)4 ServiceReference (org.osgi.framework.ServiceReference)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 Map (java.util.Map)2 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 SingletonPentahoObjectReference (org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 Node (org.dom4j.Node)1 Bundle (org.osgi.framework.Bundle)1