Search in sources :

Example 56 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.

the class RevisionResourceTest method setUp.

/**
 * @throws Exception
 */
@org.junit.Before
public void setUp() throws Exception {
    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    RevisionResource.setRepositoryVersionManager(mockRepositoryVersionManager);
    mockRepositoryFile = mock(RepositoryFile.class);
    when(mockRepositoryFile.getId()).thenReturn(MOCK_FILE_ID);
    IUnifiedRepository mockRepository = mock(IUnifiedRepository.class);
    when(mockRepository.getFile(FileUtils.idToPath(MOCK_FILE_PATH))).thenReturn(mockRepositoryFile);
    when(mockRepository.getVersionSummaries(MOCK_FILE_ID)).thenReturn(getMockVersionSummaries());
    revisionResource = new RevisionResource(mockRepository);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 57 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.

the class JobDelegateTest method testDataNodeToElementCopiesAttributesToJobEntryCopyAndJobEntry.

@Test
public void testDataNodeToElementCopiesAttributesToJobEntryCopyAndJobEntry() throws KettleException {
    IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
    JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
    DataNode mockDataNode = mock(DataNode.class);
    DataNode entriesNode = addSubnode(mockDataNode, JobDelegate.NODE_ENTRIES);
    DataNode copyNode = mock(DataNode.class);
    setNodes(entriesNode, JobDelegate.PROP_NR_JOB_ENTRY_COPIES, Arrays.asList(copyNode));
    DataNode nodeCustom = addSubnode(copyNode, JobDelegate.NODE_CUSTOM);
    DataNode notesNode = addSubnode(mockDataNode, JobDelegate.NODE_NOTES);
    DataNode hopsNode = addSubnode(mockDataNode, JobDelegate.NODE_HOPS);
    DataNode paramsNode = addSubnode(mockDataNode, JobDelegate.NODE_PARAMETERS);
    DataNode groupsNode = addSubnode(copyNode, AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
    DataNode groupNode = mock(DataNode.class);
    setNodes(groupsNode, null, Arrays.asList(groupNode));
    JobMeta mockJobMeta = mock(JobMeta.class);
    JobLogTable mockJobLogTable = mock(JobLogTable.class);
    List<JobEntryCopy> jobCopies = new ArrayList<JobEntryCopy>();
    DataProperty mockDataProperty = mock(DataProperty.class);
    List<DataProperty> dataProperties = Arrays.asList(mockDataProperty);
    setProperty(mockDataNode, JobDelegate.PROP_JOB_STATUS, 0L);
    setProperty(mockDataNode, JobDelegate.PROP_USE_BATCH_ID, false);
    setProperty(mockDataNode, JobDelegate.PROP_PASS_BATCH_ID, false);
    setProperty(mockDataNode, JobDelegate.PROP_USE_LOGFIELD, false);
    setProperty(copyNode, JobDelegate.PROP_JOBENTRY_TYPE, "WRITE_TO_LOG");
    when(copyNode.getId()).thenReturn("COPYNODE_ID");
    setProperty(copyNode, JobDelegate.PROP_NR, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_LOCATION_X, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_LOCATION_Y, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_DRAW, false);
    setProperty(copyNode, JobDelegate.PROP_PARALLEL, false);
    setProperty(nodeCustom, "logmessage_#_0", (String) null);
    setNodes(notesNode, JobDelegate.PROP_NR_NOTES, Arrays.<DataNode>asList());
    setNodes(hopsNode, JobDelegate.PROP_NR_HOPS, Arrays.<DataNode>asList());
    setProperty(paramsNode, JobDelegate.PROP_NR_PARAMETERS, 0L);
    when(mockJobMeta.getJobCopies()).thenReturn(jobCopies);
    when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
    when(groupNode.getName()).thenReturn("GROUP_NODE_NAME");
    when(groupNode.getProperties()).thenReturn(dataProperties);
    when(mockDataProperty.getName()).thenReturn("MOCK_PROPERTY");
    when(mockDataProperty.getString()).thenReturn("MOCK_VALUE");
    jobDelegate.dataNodeToElement(mockDataNode, mockJobMeta);
    assertEquals(jobCopies.get(0).getAttributesMap(), ((JobEntryBase) jobCopies.get(0).getEntry()).getAttributesMap());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobLogTable(org.pentaho.di.core.logging.JobLogTable) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) ArrayList(java.util.ArrayList) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 58 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.

the class JobDelegateTest method testElementToDataNodeSavesAttributes.

@Test
public void testElementToDataNodeSavesAttributes() throws KettleException {
    JobMeta mockJobMeta = mock(JobMeta.class);
    IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
    JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
    JobLogTable mockJobLogTable = mock(JobLogTable.class);
    JobEntryCopy mockJobEntryCopy = mock(JobEntryCopy.class);
    Map<String, Map<String, String>> attributes = new HashMap<String, Map<String, String>>();
    Map<String, String> group = new HashMap<String, String>();
    final String mockGroup = "MOCK_GROUP";
    final String mockProperty = "MOCK_PROPERTY";
    final String mockValue = "MOCK_VALUE";
    group.put(mockProperty, mockValue);
    attributes.put(mockGroup, group);
    JobEntryBaseAndInterface mockJobEntry = mock(JobEntryBaseAndInterface.class);
    when(mockJobEntry.getAttributesMap()).thenReturn(attributes);
    when(mockJobMeta.listParameters()).thenReturn(new String[] {});
    when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
    when(mockJobMeta.nrJobEntries()).thenReturn(1);
    when(mockJobMeta.getJobEntry(0)).thenReturn(mockJobEntryCopy);
    when(mockJobEntryCopy.getName()).thenReturn("MOCK_NAME");
    when(mockJobEntryCopy.getLocation()).thenReturn(new Point(0, 0));
    when(mockJobEntryCopy.getEntry()).thenReturn(mockJobEntry);
    DataNode dataNode = jobDelegate.elementToDataNode(mockJobMeta);
    DataNode groups = dataNode.getNode("entries").getNodes().iterator().next().getNode(AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
    DataNode mockGroupNode = groups.getNode(mockGroup);
    assertEquals(mockValue, mockGroupNode.getProperty(mockProperty).getString());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobLogTable(org.pentaho.di.core.logging.JobLogTable) HashMap(java.util.HashMap) Point(org.pentaho.di.core.gui.Point) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) HashMap(java.util.HashMap) Map(java.util.Map) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 59 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.

the class PurRepositoryUnitTest method testTransRepoAfterSaveExtensionPoint.

@Test
public void testTransRepoAfterSaveExtensionPoint() throws KettleException {
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(KettleExtensionPoint.TransImportAfterSaveToRepo.id);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "extensionpointId" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    PurRepository rep = mock(PurRepository.class);
    doCallRealMethod().when(rep).saveTransOrJob(any(ISharedObjectsTransformer.class), any(RepositoryElementInterface.class), anyString(), any(Calendar.class), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean());
    IUnifiedRepository pur = mock(IUnifiedRepository.class);
    doCallRealMethod().when(rep).setTest(same(pur));
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    doCallRealMethod().when(rep).init(same(mockMeta));
    rep.init(mockMeta);
    rep.setTest(pur);
    RepositoryFile file = mock(RepositoryFile.class);
    when(file.getId()).thenReturn("id");
    when(pur.createFile(any(Serializable.class), any(RepositoryFile.class), any(IRepositoryFileData.class), anyString())).thenReturn(file);
    TransMeta trans = mock(TransMeta.class);
    when(trans.getRepositoryElementType()).thenReturn(RepositoryObjectType.TRANSFORMATION);
    when(trans.getName()).thenReturn("trans");
    RepositoryDirectory dir = mock(RepositoryDirectory.class);
    when(dir.getObjectId()).thenReturn(new StringObjectId("id"));
    when(trans.getRepositoryDirectory()).thenReturn(dir);
    TransMeta transFromRepo = mock(TransMeta.class);
    when(rep.loadTransformation(any(ObjectId.class), isNull(String.class))).thenReturn(transFromRepo);
    ISharedObjectsTransformer transformer = mock(ISharedObjectsTransformer.class);
    rep.saveTransOrJob(transformer, trans, "", Calendar.getInstance(), false, false, false, false, false);
    verify(extensionPoint, times(1)).callExtensionPoint(any(LogChannelInterface.class), same(transFromRepo));
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Calendar(java.util.Calendar) TransMeta(org.pentaho.di.trans.TransMeta) Matchers.anyString(org.mockito.Matchers.anyString) StringObjectId(org.pentaho.di.repository.StringObjectId) RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 60 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.

the class PurRepositoryUnitTest method testRootIsNotVisible.

@Test
public void testRootIsNotVisible() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    // for Lazy Repo
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    // for Eager Repo
    RepositoryFileTree repositoryFileTree = mock(RepositoryFileTree.class);
    when(mockRepo.getTree("/", -1, null, true)).thenReturn(repositoryFileTree);
    when(repositoryFileTree.getFile()).thenReturn(mockRootFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    RepositoryDirectoryInterface rootDir = purRepository.getRootDir();
    assertFalse(rootDir.isVisible());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)88 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)61 Test (org.junit.Test)51 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)18 List (java.util.List)10 StringObjectId (org.pentaho.di.repository.StringObjectId)10 Serializable (java.io.Serializable)9 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)7 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)7 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)7 InputStream (java.io.InputStream)6 JobMeta (org.pentaho.di.job.JobMeta)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)6 HashMap (java.util.HashMap)5 ObjectId (org.pentaho.di.repository.ObjectId)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 Properties (java.util.Properties)4 Log (org.apache.commons.logging.Log)4