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;
}
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");
}
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));
}
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);
}
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)");
}
Aggregations