Search in sources :

Example 1 with ILogicalIdGenerator

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());
}
Also used : ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) MetaverseLogicalIdGenerator(org.pentaho.metaverse.api.MetaverseLogicalIdGenerator) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with ILogicalIdGenerator

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());
}
Also used : ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) IHasProperties(org.pentaho.metaverse.api.IHasProperties) Test(org.junit.Test)

Example 3 with ILogicalIdGenerator

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));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) INamespace(org.pentaho.metaverse.api.INamespace) MetaverseObjectFactory(org.pentaho.metaverse.api.MetaverseObjectFactory) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with ILogicalIdGenerator

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());
}
Also used : ILogicalIdGenerator(org.pentaho.metaverse.api.ILogicalIdGenerator) MetaverseLogicalIdGenerator(org.pentaho.metaverse.api.MetaverseLogicalIdGenerator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 ILogicalIdGenerator (org.pentaho.metaverse.api.ILogicalIdGenerator)4 Matchers.anyString (org.mockito.Matchers.anyString)2 MetaverseLogicalIdGenerator (org.pentaho.metaverse.api.MetaverseLogicalIdGenerator)2 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)1 IHasProperties (org.pentaho.metaverse.api.IHasProperties)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 INamespace (org.pentaho.metaverse.api.INamespace)1 MetaverseObjectFactory (org.pentaho.metaverse.api.MetaverseObjectFactory)1