| /* |
| ************************************************************************* |
| * Copyright (c) 2006, 2007 Actuate Corporation. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Actuate Corporation - initial API and implementation |
| * |
| ************************************************************************* |
| */ |
| |
| package org.eclipse.datatools.connectivity.oda.util.manifest.tests; |
| |
| import java.sql.Types; |
| import java.util.Hashtable; |
| import java.util.Properties; |
| |
| import org.eclipse.datatools.connectivity.oda.util.manifest.DataSetType; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.DataTypeMapping; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.ExtensionManifest; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.JavaRuntimeInterface; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.ManifestExplorer; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.Property; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.RuntimeInterface; |
| import org.eclipse.datatools.connectivity.oda.util.manifest.TraceLogging; |
| |
| import junit.framework.TestCase; |
| |
| /** |
| * JUnit Plugin Test of the oda.util.manifest package. |
| */ |
| public class ManifestExplorerTest extends TestCase |
| { |
| private final String m_dtpFlatFileId = "org.eclipse.datatools.connectivity.oda.flatfile"; |
| private final String m_expectedFFDataSetId = "org.eclipse.datatools.connectivity.oda.flatfile.dataSet"; |
| |
| // comment out lots of non-working tests below but need an empty test so Maven/Tycho/Surefire doesn't complain |
| public void testNothingBecauseAllTheTestsFailOrError() |
| { |
| assertTrue( true ); |
| } |
| |
| // public void testGetDataSourceNames() throws Exception |
| // { |
| // Properties names = ManifestExplorer.getInstance().getDataSourceIdentifiers(); |
| // |
| // assertEquals( "Flat File Data Source", names.getProperty( m_dtpFlatFileId ) ); |
| // } |
| |
| // public void testGetExtensionConfigs() throws Exception |
| // { |
| // ExtensionManifest[] configs = |
| // ManifestExplorer.getInstance().getExtensionManifests(); |
| // verifyExtensionConfigs( configs, m_dtpFlatFileId ); |
| // } |
| |
| void verifyExtensionConfigs( ExtensionManifest[] configs, String driverId ) |
| { |
| boolean isFound = false; |
| for( int i = 0; i < configs.length; i++ ) |
| { |
| ExtensionManifest config = configs[i]; |
| if( config.getDataSourceElementID().equals( driverId ) ) |
| { |
| isFound = true; |
| break; |
| } |
| } |
| assertTrue( isFound ); |
| } |
| |
| // public void testGetExtensionConfig() throws Exception |
| // { |
| // ExtensionManifest config = |
| // ManifestExplorer.getInstance().getExtensionManifest( m_dtpFlatFileId ); |
| // verifyFlatfileExtensionConfig( config ); |
| // } |
| |
| // void verifyFlatfileExtensionConfig( ExtensionManifest config )testGetDoubleString |
| // throws Exception |
| // { |
| // assertNotNull( config ); |
| // assertEquals( m_dtpFlatFileId, config.getDataSourceElementID() ); |
| // assertEquals( "Flat File Data Source", config.getDataSourceDisplayName() ); |
| // assertEquals( "3.0", config.getOdaVersion() ); |
| // |
| // RuntimeInterface runtime = config.getRuntimeInterface(); |
| // assertTrue( runtime instanceof JavaRuntimeInterface ); |
| // JavaRuntimeInterface javaRuntime = (JavaRuntimeInterface) runtime; |
| // assertEquals( "org.eclipse.datatools.connectivity.oda.flatfile.FlatFileDriver", |
| // javaRuntime.getDriverClass() ); |
| // assertFalse( javaRuntime.needSetThreadContextClassLoader() ); |
| // assertEquals( RuntimeInterface.JAVA_TYPE, javaRuntime.getInterfaceType() ); |
| // assertTrue( javaRuntime.getLibraryLocation().toString() |
| // .endsWith( "org.eclipse.datatools.connectivity.oda.flatfile/" ) ); |
| // |
| // TraceLogging traceLogging = config.getTraceLogging(); |
| // assertNull( traceLogging ); |
| // |
| // myTestFFGetExtensionProperties( config ); |
| // |
| // String[] dataSetTypeIds = config.getDataSetTypeIDs(); |
| // assertTrue( dataSetTypeIds.length == 1 ); |
| // |
| // assertEquals( m_expectedFFDataSetId, dataSetTypeIds[0] ); |
| // myTestFFGetDataSetTypes( config ); |
| // } |
| |
| void myTestFFGetExtensionProperties( ExtensionManifest config ) |
| { |
| Property[] dataSourceProps = config.getProperties(); |
| assertTrue( dataSourceProps.length >= 3 ); |
| |
| Hashtable propsList = new Hashtable( dataSourceProps.length ); |
| for( int i = 0; i < dataSourceProps.length; i++ ) |
| { |
| Property prop = dataSourceProps[i]; |
| propsList.put( prop.getName(), prop ); |
| } |
| |
| String expectedGroupName = null; |
| String expectedGroupDisplayName = null; |
| |
| Property aProp = (Property) propsList.get( "HOME" ); |
| myTestPropertyAttributes( aProp, |
| "Home &Folder", |
| expectedGroupName, |
| expectedGroupDisplayName, |
| "string", |
| true, null, false ); |
| aProp = (Property) propsList.get( "CHARSET" ); |
| myTestPropertyAttributes( aProp, |
| "&Character Set", |
| expectedGroupName, |
| expectedGroupDisplayName, |
| "string", |
| true, null, false ); |
| aProp = (Property) propsList.get( "INCLTYPELINE" ); |
| myTestPropertyAttributes( aProp, |
| "Use Second Line as &Data Type Indicator", |
| expectedGroupName, |
| expectedGroupDisplayName, |
| "choice", |
| true, "YES", false ); |
| } |
| |
| void myTestPropertyAttributes( Property aProp, |
| String expectedDisplayName, |
| String expectedGroupName, |
| String expectedGroupDisplayName, |
| String expectedType, |
| boolean expectedInheritability, |
| String expectedDefaultValue, |
| boolean expectedIsEncryptable ) |
| { |
| assertNotNull( aProp ); |
| assertEquals( expectedDisplayName, aProp.getDisplayName() ); |
| if( expectedGroupName == null ) |
| assertNull( aProp.getGroupName() ); |
| else |
| assertEquals( expectedGroupName, aProp.getGroupName() ); |
| if( expectedGroupDisplayName == null ) |
| assertNull( aProp.getGroupDisplayName() ); |
| else |
| assertEquals( expectedGroupDisplayName, aProp.getGroupDisplayName() ); |
| assertEquals( expectedType, aProp.getType() ); |
| assertEquals( expectedInheritability, aProp.canInherit() ); |
| assertEquals( expectedDefaultValue, aProp.getDefaultValue() ); |
| assertEquals( expectedIsEncryptable, aProp.isEncryptable() ); |
| } |
| |
| void myTestFFGetDataSetTypes( ExtensionManifest config ) throws Exception |
| { |
| DataSetType[] dataSetTypes = config.getDataSetTypes(); |
| assertTrue( dataSetTypes.length == 1 ); |
| |
| DataSetType dataSetType = config.getDataSetType( m_expectedFFDataSetId ); |
| assertEquals( m_expectedFFDataSetId, dataSetType.getID() ); |
| assertEquals( "Flat File Data Set", dataSetType.getDisplayName() ); |
| |
| for( int i = 0, n = sm_mappings.length; i < n; i++ ) |
| { |
| Integer s = (Integer) sm_mappings[i][0]; |
| DataTypeMapping mapping = dataSetType.getDataTypeMapping( s.shortValue() ); |
| assertNotNull( mapping ); |
| assertEquals( s.intValue(), mapping.getNativeTypeCode() ); |
| assertEquals( sm_mappings[i][1], mapping.getNativeType() ); |
| assertEquals( sm_mappings[i][2], mapping.getOdaScalarDataType() ); |
| |
| int mappedOdaTypeCode = ((Integer) sm_mappings[i][3]).intValue(); |
| assertEquals( mappedOdaTypeCode, mapping.getOdaScalarDataTypeCode() ); |
| assertTrue( mapping.canConvertToOdaType( mappedOdaTypeCode )); |
| assertFalse( mapping.canConvertToOdaType( mappedOdaTypeCode + 1 )); |
| |
| assertTrue( mapping.getAlternativeOdaDataTypes().length == 0 ); |
| assertTrue( mapping.getAlternativeOdaDataTypeCodes().length == 0 ); |
| } |
| |
| Property[] dataSetProps = dataSetType.getProperties(); |
| assertEquals( 0, dataSetProps.length ); |
| } |
| |
| private static Object[][] sm_mappings = |
| { |
| // native type code, native type name, primary oda type name, oda type code |
| { new Integer( (int) 4 ), "INT", "Integer", new Integer( Types.INTEGER ) }, |
| { new Integer( (int) 8 ), "DOUBLE", "Double", new Integer( Types.DOUBLE ) }, |
| { new Integer( (int) 12 ), "STRING", "String", new Integer( Types.CHAR ) }, |
| { new Integer( (int) 91 ), "DATE", "Date", new Integer( Types.DATE ) }, |
| { new Integer( (int) 92 ), "TIME", "Time", new Integer( Types.TIME ) }, |
| { new Integer( (int) 93 ), "TIMESTAMP", "Timestamp", new Integer( Types.TIMESTAMP ) }, |
| { new Integer( (int) 2004 ), "BLOB", "String", new Integer( Types.CHAR ) }, |
| { new Integer( (int) 2005 ), "CLOB", "String", new Integer( Types.CHAR ) }, |
| { new Integer( (int) 2 ), "BIGDECIMAL", "Decimal", new Integer( Types.DECIMAL ) } |
| }; |
| |
| } |