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);
}
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());
}
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();
}
}
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);
}
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());
}
Aggregations