Search in sources :

Example 56 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTest method testInsertTransformationPartitionSchema.

@Test
public void testInsertTransformationPartitionSchema() throws KettleException {
    ArgumentCaptor<String> argumentTableName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<RowMetaAndData> argumentTableData = ArgumentCaptor.forClass(RowMetaAndData.class);
    doNothing().when(repo.connectionDelegate).insertTableRow(argumentTableName.capture(), argumentTableData.capture());
    doReturn(new LongObjectId(456)).when(repo.connectionDelegate).getNextTransformationPartitionSchemaID();
    ObjectId result = repo.insertTransformationPartitionSchema(new LongObjectId(147), new LongObjectId(258));
    RowMetaAndData insertRecord = argumentTableData.getValue();
    assertEquals(KettleDatabaseRepository.TABLE_R_TRANS_PARTITION_SCHEMA, argumentTableName.getValue());
    assertEquals(3, insertRecord.size());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(0).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_PARTITION_SCHEMA_ID_TRANS_PARTITION_SCHEMA, insertRecord.getValueMeta(0).getName());
    assertEquals(Long.valueOf(456), insertRecord.getInteger(0));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(1).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_PARTITION_SCHEMA_ID_TRANSFORMATION, insertRecord.getValueMeta(1).getName());
    assertEquals(Long.valueOf(147), insertRecord.getInteger(1));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(2).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_PARTITION_SCHEMA_ID_PARTITION_SCHEMA, insertRecord.getValueMeta(2).getName());
    assertEquals(Long.valueOf(258), insertRecord.getInteger(2));
    assertEquals(new LongObjectId(456), result);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) LongObjectId(org.pentaho.di.repository.LongObjectId) Test(org.junit.Test)

Example 57 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTest method testInsertTransformationCluster.

@Test
public void testInsertTransformationCluster() throws KettleException {
    ArgumentCaptor<String> argumentTableName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<RowMetaAndData> argumentTableData = ArgumentCaptor.forClass(RowMetaAndData.class);
    doNothing().when(repo.connectionDelegate).insertTableRow(argumentTableName.capture(), argumentTableData.capture());
    doReturn(new LongObjectId(123)).when(repo.connectionDelegate).getNextTransformationClusterID();
    ObjectId result = repo.insertTransformationCluster(new LongObjectId(456), new LongObjectId(789));
    RowMetaAndData insertRecord = argumentTableData.getValue();
    assertEquals(KettleDatabaseRepository.TABLE_R_TRANS_CLUSTER, argumentTableName.getValue());
    assertEquals(3, insertRecord.size());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(0).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_CLUSTER_ID_TRANS_CLUSTER, insertRecord.getValueMeta(0).getName());
    assertEquals(Long.valueOf(123), insertRecord.getInteger(0));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(1).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_CLUSTER_ID_TRANSFORMATION, insertRecord.getValueMeta(1).getName());
    assertEquals(Long.valueOf(456), insertRecord.getInteger(1));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(2).getType());
    assertEquals(KettleDatabaseRepository.FIELD_TRANS_CLUSTER_ID_CLUSTER, insertRecord.getValueMeta(2).getName());
    assertEquals(Long.valueOf(789), insertRecord.getInteger(2));
    assertEquals(new LongObjectId(123), result);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) LongObjectId(org.pentaho.di.repository.LongObjectId) Test(org.junit.Test)

Example 58 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepository_DatabaseNames_Test method getDatabaseId_ExactMatch.

@Test
public void getDatabaseId_ExactMatch() throws Exception {
    final String name = UUID.randomUUID().toString();
    final ObjectId expectedId = new StringObjectId("expected");
    doReturn(expectedId).when(databaseDelegate).getDatabaseID(name);
    ObjectId id = repository.getDatabaseID(name);
    assertEquals(expectedId, id);
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 59 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class RunJobServletTest method doGetWrongCredentialsRepoTest.

@Test
public void doGetWrongCredentialsRepoTest() throws Exception {
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    TransformationMap transformationMap = mock(TransformationMap.class);
    SlaveServerConfig slaveServerConfig = mock(SlaveServerConfig.class);
    Repository repository = mock(Repository.class);
    RepositoryDirectoryInterface repDirInterface = mock(RepositoryDirectoryInterface.class);
    ObjectId objId = mock(ObjectId.class);
    Whitebox.setInternalState(runJobServlet, "transformationMap", transformationMap);
    KettleLogStore.init();
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getParameter("job")).thenReturn("dummyJob");
    when(mockHttpServletRequest.getParameter("level")).thenReturn("SomethingInvalid");
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(transformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
    when(slaveServerConfig.getRepository()).thenReturn(repository);
    when(repository.isConnected()).thenReturn(true);
    when(repository.loadRepositoryDirectoryTree()).thenReturn(repDirInterface);
    when(repDirInterface.findDirectory(anyString())).thenReturn(repDirInterface);
    when(repository.getJobId("dummyJob", repDirInterface)).thenReturn(objId);
    when(repository.loadJob(objId, null)).thenThrow(new KettleException("The server sent HTTP status code 401"));
    runJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) StringWriter(java.io.StringWriter) ObjectId(org.pentaho.di.repository.ObjectId) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 60 with ObjectId

use of org.pentaho.di.repository.ObjectId in project pentaho-kettle by pentaho.

the class RunJobServletTest method doGetNonExistingJobTest.

@Test
public void doGetNonExistingJobTest() throws Exception {
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    TransformationMap transformationMap = mock(TransformationMap.class);
    SlaveServerConfig slaveServerConfig = mock(SlaveServerConfig.class);
    Repository repository = mock(Repository.class);
    RepositoryDirectoryInterface repDirInterface = mock(RepositoryDirectoryInterface.class);
    ObjectId objId = mock(ObjectId.class);
    Whitebox.setInternalState(runJobServlet, "transformationMap", transformationMap);
    KettleLogStore.init();
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getParameter("job")).thenReturn("dummyJob");
    when(mockHttpServletRequest.getParameter("level")).thenReturn("SomethingInvalid");
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(transformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
    when(slaveServerConfig.getRepository()).thenReturn(repository);
    when(repository.isConnected()).thenReturn(true);
    when(repository.loadRepositoryDirectoryTree()).thenReturn(repDirInterface);
    when(repDirInterface.findDirectory(anyString())).thenReturn(repDirInterface);
    when(repository.getJobId("dummyJob", repDirInterface)).thenReturn(objId);
    when(repository.loadJob(objId, null)).thenThrow(new KettleException("Unable to load job"));
    runJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
    verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_NOT_FOUND);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) StringWriter(java.io.StringWriter) ObjectId(org.pentaho.di.repository.ObjectId) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ObjectId (org.pentaho.di.repository.ObjectId)233 KettleException (org.pentaho.di.core.exception.KettleException)94 LongObjectId (org.pentaho.di.repository.LongObjectId)76 StringObjectId (org.pentaho.di.repository.StringObjectId)76 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)49 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)38 Test (org.junit.Test)37 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)37 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)34 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)33 ArrayList (java.util.ArrayList)30 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)29 MessageBox (org.eclipse.swt.widgets.MessageBox)26 Repository (org.pentaho.di.repository.Repository)18 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 SlaveServer (org.pentaho.di.cluster.SlaveServer)15 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)14 PartitionSchema (org.pentaho.di.partition.PartitionSchema)14 Matchers.anyString (org.mockito.Matchers.anyString)13 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)13