use of org.pentaho.metaverse.api.ILogicalIdGenerator in project pentaho-metaverse by pentaho.
the class MetaverseNodeTest method testGetLogicalId.
@Test
public void testGetLogicalId() throws Exception {
MetaverseNode node = new MetaverseNode(v);
when(v.getProperty("name")).thenReturn("testName");
when(v.getProperty("zzz")).thenReturn("last");
when(v.getProperty("type")).thenReturn("testType");
MetaverseNode spyNode = spy(node);
when(spyNode.getPropertyKeys()).thenReturn(new HashSet<String>() {
{
add("name");
add("type");
add("zzz");
}
});
// should be using the default logical id generator initially
assertEquals("{\"name\":\"testName\",\"namespace\":\"\",\"type\":\"testType\"}", spyNode.getLogicalId());
ILogicalIdGenerator idGenerator = new MetaverseLogicalIdGenerator("type", "zzz", "name");
spyNode.setLogicalIdGenerator(idGenerator);
assertNotNull(spyNode.logicalIdGenerator);
// logical id should be sorted based on key
assertEquals("{\"name\":\"testName\",\"type\":\"testType\",\"zzz\":\"last\"}", spyNode.getLogicalId());
}
use of org.pentaho.metaverse.api.ILogicalIdGenerator in project pentaho-metaverse by pentaho.
the class MetaverseTransientNodeTest method testGetLogicalId_nullLogicalIdGeneration.
@Test
public void testGetLogicalId_nullLogicalIdGeneration() throws Exception {
MetaverseTransientNode myNode = new MetaverseTransientNode("myId");
ILogicalIdGenerator generator = mock(ILogicalIdGenerator.class);
when(generator.generateId(any(IHasProperties.class))).thenReturn(null);
myNode.setName("testName");
myNode.setType("testType");
myNode.setLogicalIdGenerator(generator);
assertEquals("myId", myNode.getLogicalId());
}
use of org.pentaho.metaverse.api.ILogicalIdGenerator in project pentaho-metaverse by pentaho.
the class BaseKettleMetaverseComponentTest method testCreateNodeFromDescriptor.
@Test
public void testCreateNodeFromDescriptor() throws Exception {
String namespaceId = "{namespace: 'my namespace', name: 'my name', type: 'my type'}";
ILogicalIdGenerator idGenerator = DictionaryConst.LOGICAL_ID_GENERATOR_DEFAULT;
IComponentDescriptor descriptor = mock(IComponentDescriptor.class);
INamespace ns = mock(INamespace.class);
when(descriptor.getParentNamespace()).thenReturn(mock(INamespace.class));
when(descriptor.getNamespace()).thenReturn(ns);
when(ns.getNamespaceId()).thenReturn(namespaceId);
component.metaverseObjectFactory = spy(new MetaverseObjectFactory());
IMetaverseNode node = component.createNodeFromDescriptor(descriptor, idGenerator);
assertNotNull(node);
assertTrue(node.getLogicalId().contains(namespaceId));
}
use of org.pentaho.metaverse.api.ILogicalIdGenerator in project pentaho-metaverse by pentaho.
the class MetaverseTransientNodeTest method testGetLogicalId.
@Test
public void testGetLogicalId() throws Exception {
MetaverseTransientNode myNode = new MetaverseTransientNode();
myNode.setName("testName");
myNode.setType("testType");
myNode.setProperty("zzz", "last");
myNode.setProperty(DictionaryConst.PROPERTY_NAMESPACE, "");
myNode.setStringID("myId");
// should be using the default logical id generator initially
assertEquals("{\"name\":\"testName\",\"namespace\":\"\",\"type\":\"testType\"}", myNode.getLogicalId());
ILogicalIdGenerator idGenerator = new MetaverseLogicalIdGenerator("type", "zzz", "name");
myNode.setLogicalIdGenerator(idGenerator);
assertNotNull(myNode.logicalIdGenerator);
// logical id should be sorted based on key
assertEquals("{\"name\":\"testName\",\"type\":\"testType\",\"zzz\":\"last\"}", myNode.getLogicalId());
}
Aggregations