Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEIID-3045: removing the import properties as translator proeprties #280

Merged
merged 1 commit into from
Jul 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions runtime/src/main/java/org/teiid/deployers/TranslatorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,18 @@ private static void readTranslatorPropertyAsExtendedMetadataProperties(
Class clazz) {
Map<Method, TranslatorProperty> tps = TranslatorUtil.getTranslatorProperties(clazz);
for (Method m:tps.keySet()) {

Object defaultValue = getDefaultValue(instance, m, tps.get(m));
if (defaultValue != null) {
metadata.addProperty(getPropertyName(m), defaultValue.toString());
}

TranslatorProperty tp = tps.get(m);
boolean importProperty = tp.category()==TranslatorProperty.PropertyType.IMPORT;
if (defaultValue != null && !importProperty) {
metadata.addProperty(getPropertyName(m), defaultValue.toString());
}

ExtendedPropertyMetadata epm = new ExtendedPropertyMetadata();
epm.category = tp.category().name();
epm.name = tp.category()==TranslatorProperty.PropertyType.IMPORT?"importer."+getPropertyName(m):getPropertyName(m); //$NON-NLS-1$
epm.name = importProperty?"importer."+getPropertyName(m):getPropertyName(m); //$NON-NLS-1$
epm.description = tp.description();
epm.advanced = tp.advanced();
if (defaultValue != null) {
Expand Down
24 changes: 24 additions & 0 deletions runtime/src/test/java/org/teiid/deployers/TestTranslatorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
import java.util.ArrayList;

import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.Logger;
import org.teiid.logging.MessageLevel;
import org.teiid.metadata.Column;
import org.teiid.metadata.ExtensionMetadataProperty;
import org.teiid.metadata.MetadataFactory;
Expand Down Expand Up @@ -95,6 +100,25 @@ public void testImportProperties() throws Exception {
assertEquals("default-import-property", importProperties.get(0).defaultValue);
}

@Test
public void testInject() throws Exception {
VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
tm.setExecutionFactoryClass(MyTranslator.class);
tm.addProperty("MyProperty", "correctly-assigned");

MyTranslator my = (MyTranslator)TranslatorUtil.buildExecutionFactory(tm);
assertEquals("correctly-assigned", my.getMyProperty());

VDBTranslatorMetaData metadata = TranslatorUtil.buildTranslatorMetadata(my, "my-module");
metadata.addProperty("MyProperty", "correctly-assigned");

Logger logger = Mockito.mock(Logger.class);
Mockito.stub(logger.isEnabled(Mockito.anyString(), Mockito.anyInt())).toReturn(true);
Mockito.doThrow(new RuntimeException("fail")).when(logger).log(Mockito.eq(MessageLevel.WARNING), Mockito.eq(LogConstants.CTX_RUNTIME), Mockito.anyString());
LogManager.setLogListener(logger);
TranslatorUtil.buildExecutionFactory(metadata);
}

@Test
public void testExtensionMetadataProperties() throws Exception {
VDBTranslatorMetaData tm = new VDBTranslatorMetaData();
Expand Down