Search in sources :

Example 6 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class XMLOutputMetaTest method testReadRep.

@SuppressWarnings("ConstantConditions")
@Test
public void testReadRep() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    Repository rep = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    String encoding = "UTF-8";
    String namespace = "";
    String mainElement = "rows";
    String repeatElement = "row";
    String fileName = "repFileName";
    StringObjectId oid = new StringObjectId("oid");
    String fileExtension = "repxml";
    boolean servletOutput = true;
    boolean newFile = true;
    long split = 100L;
    boolean addStepNbr = false;
    boolean addDate = false;
    boolean addTime = true;
    boolean specifyFormat = true;
    boolean omitNull = false;
    String dateTimeFormat = "yyyyMMdd";
    boolean addToResult = true;
    boolean zipped = true;
    String contentType = "Element";
    String fieldName = "aField";
    String fieldElement = "field";
    String fieldType = "String";
    long fieldLength = 20L;
    long fieldPrecision = 0L;
    when(rep.getStepAttributeString(oid, "encoding")).thenReturn(encoding);
    when(rep.getStepAttributeString(oid, "name_space")).thenReturn(namespace);
    when(rep.getStepAttributeString(oid, "xml_main_element")).thenReturn(mainElement);
    when(rep.getStepAttributeString(oid, "xml_repeat_element")).thenReturn(repeatElement);
    when(rep.getStepAttributeString(oid, "file_name")).thenReturn(fileName);
    when(rep.getStepAttributeString(oid, "file_extention")).thenReturn(fileExtension);
    when(rep.getStepAttributeBoolean(oid, "file_servlet_output")).thenReturn(servletOutput);
    when(rep.getStepAttributeBoolean(oid, "do_not_open_newfile_init")).thenReturn(newFile);
    when(rep.getStepAttributeInteger(oid, "file_split")).thenReturn(split);
    when(rep.getStepAttributeBoolean(oid, "file_add_stepnr")).thenReturn(addStepNbr);
    when(rep.getStepAttributeBoolean(oid, "file_add_date")).thenReturn(addDate);
    when(rep.getStepAttributeBoolean(oid, "file_add_time")).thenReturn(addTime);
    when(rep.getStepAttributeBoolean(oid, "SpecifyFormat")).thenReturn(specifyFormat);
    when(rep.getStepAttributeBoolean(oid, "omit_null_values")).thenReturn(omitNull);
    when(rep.getStepAttributeString(oid, "date_time_format")).thenReturn(dateTimeFormat);
    when(rep.getStepAttributeBoolean(oid, "add_to_result_filenames")).thenReturn(addToResult);
    when(rep.getStepAttributeBoolean(oid, "file_zipped")).thenReturn(zipped);
    when(rep.countNrStepAttributes(oid, "field_name")).thenReturn(1);
    when(rep.getStepAttributeString(oid, 0, "field_content_type")).thenReturn(contentType);
    when(rep.getStepAttributeString(oid, 0, "field_name")).thenReturn(fieldName);
    when(rep.getStepAttributeString(oid, 0, "field_element")).thenReturn(fieldElement);
    when(rep.getStepAttributeString(oid, 0, "field_type")).thenReturn(fieldType);
    when(rep.getStepAttributeString(oid, 0, "field_format")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_currency")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_decimal")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_group")).thenReturn(null);
    when(rep.getStepAttributeString(oid, 0, "field_nullif")).thenReturn(null);
    when(rep.getStepAttributeInteger(oid, 0, "field_length")).thenReturn(fieldLength);
    when(rep.getStepAttributeInteger(oid, 0, "field_precision")).thenReturn(fieldPrecision);
    xmlOutputMeta.readRep(rep, metastore, oid, Collections.singletonList(dbMeta));
    assertEquals(fileName, xmlOutputMeta.getFileName());
    assertTrue(xmlOutputMeta.isDoNotOpenNewFileInit());
    assertTrue(xmlOutputMeta.isServletOutput());
    assertEquals(fileExtension, xmlOutputMeta.getExtension());
    assertFalse(xmlOutputMeta.isStepNrInFilename());
    assertFalse(xmlOutputMeta.isDateInFilename());
    assertTrue(xmlOutputMeta.isTimeInFilename());
    assertTrue(xmlOutputMeta.isSpecifyFormat());
    assertEquals(dateTimeFormat, xmlOutputMeta.getDateTimeFormat());
    assertTrue(xmlOutputMeta.isAddToResultFiles());
    assertTrue(xmlOutputMeta.isZipped());
    assertEquals(encoding, xmlOutputMeta.getEncoding());
    assertTrue(StringUtil.isEmpty(xmlOutputMeta.getNameSpace()));
    assertEquals(mainElement, xmlOutputMeta.getMainElement());
    assertEquals(repeatElement, xmlOutputMeta.getRepeatElement());
    assertEquals(split, xmlOutputMeta.getSplitEvery());
    assertFalse(xmlOutputMeta.isOmitNullValues());
    XMLField[] outputFields = xmlOutputMeta.getOutputFields();
    assertEquals(1, outputFields.length);
    assertEquals(fieldName, outputFields[0].getFieldName());
    assertEquals(XMLField.ContentType.Element, outputFields[0].getContentType());
    assertEquals(fieldElement, outputFields[0].getElementName());
    assertEquals(fieldLength, outputFields[0].getLength());
    assertEquals(fieldPrecision, outputFields[0].getPrecision());
    Mockito.reset(rep, metastore);
    StringObjectId transid = new StringObjectId("transid");
    xmlOutputMeta.saveRep(rep, metastore, transid, oid);
    verify(rep).saveStepAttribute(transid, oid, "encoding", encoding);
    verify(rep).saveStepAttribute(transid, oid, "name_space", namespace);
    verify(rep).saveStepAttribute(transid, oid, "xml_main_element", mainElement);
    verify(rep).saveStepAttribute(transid, oid, "xml_repeat_element", repeatElement);
    verify(rep).saveStepAttribute(transid, oid, "file_name", fileName);
    verify(rep).saveStepAttribute(transid, oid, "file_extention", fileExtension);
    verify(rep).saveStepAttribute(transid, oid, "file_servlet_output", servletOutput);
    verify(rep).saveStepAttribute(transid, oid, "do_not_open_newfile_init", newFile);
    verify(rep).saveStepAttribute(transid, oid, "file_split", split);
    verify(rep).saveStepAttribute(transid, oid, "file_add_stepnr", addStepNbr);
    verify(rep).saveStepAttribute(transid, oid, "file_add_date", addDate);
    verify(rep).saveStepAttribute(transid, oid, "file_add_time", addTime);
    verify(rep).saveStepAttribute(transid, oid, "SpecifyFormat", specifyFormat);
    verify(rep).saveStepAttribute(transid, oid, "omit_null_values", omitNull);
    verify(rep).saveStepAttribute(transid, oid, "date_time_format", dateTimeFormat);
    verify(rep).saveStepAttribute(transid, oid, "add_to_result_filenames", addToResult);
    verify(rep).saveStepAttribute(transid, oid, "file_zipped", zipped);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_content_type", contentType);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_name", fieldName);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_element", fieldElement);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_type", fieldType);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_format", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_currency", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_decimal", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_group", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_nullif", null);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_length", fieldLength);
    verify(rep).saveStepAttribute(transid, oid, 0, "field_precision", fieldPrecision);
    Mockito.verifyNoMoreInteractions(rep, metastore);
}
Also used : Repository(org.pentaho.di.repository.Repository) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 7 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class RepositorySessionTimeoutHandlerTest method wrapMetastoreWithTimeoutHandler.

@Test
public void wrapMetastoreWithTimeoutHandler() throws Throwable {
    IMetaStore metaStore = mock(IMetaStore.class);
    doThrow(KettleRepositoryLostException.class).when(metaStore).createNamespace(any());
    SessionTimeoutHandler sessionTimeoutHandler = mock(SessionTimeoutHandler.class);
    IMetaStore wrappedMetaStore = RepositorySessionTimeoutHandler.wrapMetastoreWithTimeoutHandler(metaStore, sessionTimeoutHandler);
    wrappedMetaStore.createNamespace("TEST_NAMESPACE");
    verify(sessionTimeoutHandler).handle(any(), any(), any(), any());
}
Also used : RepositorySessionTimeoutHandler(org.pentaho.di.ui.repo.timeout.RepositorySessionTimeoutHandler) SessionTimeoutHandler(org.pentaho.di.ui.repo.timeout.SessionTimeoutHandler) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 8 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class RepositorySessionTimeoutHandler method invoke.

@SuppressWarnings("unchecked")
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        String methodName = method.getName();
        if (GET_SERVICE_METHOD_NAME.equals(methodName)) {
            return wrapRepositoryServiceWithTimeoutHandler((Class<? extends IRepositoryService>) args[SERVICE_CLASS_ARGUMENT]);
        }
        if (GET_META_STORE_METHOD_NAME.equals(methodName)) {
            return metaStoreInstance;
        }
        Object result = method.invoke(repository, args);
        if (CONNECT_METHOD_NAME.equals(methodName)) {
            IMetaStore metaStore = repository.getMetaStore();
            metaStoreInstance = wrapMetastoreWithTimeoutHandler(metaStore, sessionTimeoutHandler);
        }
        return result;
    } catch (InvocationTargetException ex) {
        if (connectedToRepository()) {
            return sessionTimeoutHandler.handle(repository, ex.getCause(), method, args);
        }
        throw ex.getCause();
    }
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testMetaStoreBasics.

@Test
public void testMetaStoreBasics() throws MetaStoreException {
    IMetaStore metaStore = repository.getMetaStore();
    assertNotNull(metaStore);
    MetaStoreTestBase base = new MetaStoreTestBase();
    base.testFunctionality(metaStore);
}
Also used : MetaStoreTestBase(org.pentaho.di.repository.pur.metastore.MetaStoreTestBase) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 10 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testMetaStoreNamespaces.

@Test
public void testMetaStoreNamespaces() throws MetaStoreException {
    IMetaStore metaStore = repository.getMetaStore();
    assertNotNull(metaStore);
    // We start with a clean slate, only the pentaho namespace
    // 
    assertEquals(1, metaStore.getNamespaces().size());
    String ns = PentahoDefaults.NAMESPACE;
    assertEquals(true, metaStore.namespaceExists(ns));
    metaStore.deleteNamespace(ns);
    assertEquals(false, metaStore.namespaceExists(ns));
    assertEquals(0, metaStore.getNamespaces().size());
    metaStore.createNamespace(ns);
    assertEquals(true, metaStore.namespaceExists(ns));
    List<String> namespaces = metaStore.getNamespaces();
    assertEquals(1, namespaces.size());
    assertEquals(ns, namespaces.get(0));
    try {
        metaStore.createNamespace(ns);
        fail("Exception expected when a namespace already exists and where we try to create it again");
    } catch (MetaStoreNamespaceExistsException e) {
    // OK, we expected this.
    }
    metaStore.deleteNamespace(ns);
    assertEquals(false, metaStore.namespaceExists(ns));
    assertEquals(0, metaStore.getNamespaces().size());
}
Also used : MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Aggregations

IMetaStore (org.pentaho.metastore.api.IMetaStore)75 Test (org.junit.Test)55 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)20 SQL (org.pentaho.di.core.sql.SQL)17 Repository (org.pentaho.di.repository.Repository)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)11 TransMeta (org.pentaho.di.trans.TransMeta)11 Matchers.anyString (org.mockito.Matchers.anyString)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 StepMeta (org.pentaho.di.trans.step.StepMeta)10 KettleException (org.pentaho.di.core.exception.KettleException)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)8 ArrayList (java.util.ArrayList)7 Variables (org.pentaho.di.core.variables.Variables)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)7 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5