### Question:
DatabaseConnectionAnalyzer extends BaseKettleMetaverseComponent implements IDatabaseConnectionAnalyzer<T> { @Override public IMetaverseNode analyze( IComponentDescriptor descriptor, DatabaseMeta dbMeta ) throws MetaverseAnalyzerException { if ( dbMeta == null ) { throw new MetaverseAnalyzerException( Messages.getString( "ERROR.DatabaseMeta.IsNull" ) ); } if ( metaverseObjectFactory == null ) { throw new MetaverseAnalyzerException( Messages.getString( "ERROR.MetaverseObjectFactory.IsNull" ) ); } if ( metaverseBuilder == null ) { throw new MetaverseAnalyzerException( Messages.getString( "ERROR.MetaverseBuilder.IsNull" ) ); } IMetaverseNode node = createNodeFromDescriptor( descriptor ); node.setType( DictionaryConst.NODE_TYPE_DATASOURCE ); int accessType = dbMeta.getAccessType(); node.setProperty( "accessType", accessType ); String accessTypeDesc = dbMeta.environmentSubstitute( dbMeta.getAccessTypeDesc() ); node.setProperty( "accessTypeDesc", accessTypeDesc ); String databaseName = dbMeta.environmentSubstitute( dbMeta.getDatabaseName() ); node.setProperty( "databaseName", databaseName ); String connectionName = dbMeta.environmentSubstitute( dbMeta.getName() ); node.setProperty( "name", connectionName ); DatabaseInterface dbInterface = dbMeta.getDatabaseInterface(); node.setProperty( "databaseType", dbInterface != null ? Const.NVL( dbInterface.getPluginName(), "Unknown" ) : "Unknown" ); String port = dbMeta.environmentSubstitute( dbMeta.getDatabasePortNumberString() ); node.setProperty( DictionaryConst.PROPERTY_PORT, port ); String host = dbMeta.environmentSubstitute( dbMeta.getHostname() ); node.setProperty( DictionaryConst.PROPERTY_HOST_NAME, host ); String user = dbMeta.environmentSubstitute( dbMeta.getUsername() ); node.setProperty( DictionaryConst.PROPERTY_USER_NAME, user ); boolean shared = dbMeta.isShared(); node.setProperty( "shared", shared ); if ( accessTypeDesc != null && accessTypeDesc.equals( "JNDI" ) ) { node.setLogicalIdGenerator( DictionaryConst.LOGICAL_ID_GENERATOR_DB_JNDI ); } else { node.setLogicalIdGenerator( getLogicalIdGenerator() ); } return node; }  @Override IMetaverseNode analyze( IComponentDescriptor descriptor, DatabaseMeta dbMeta ); @Override IComponentDescriptor buildComponentDescriptor( IComponentDescriptor parentDescriptor,
                                                        DatabaseMeta connection );  }### Answer:
@Test(expected = MetaverseAnalyzerException.class) public void testSetMetaverseBuilderNull() throws MetaverseAnalyzerException { dbConnectionAnalyzer.setMetaverseBuilder( null ); dbConnectionAnalyzer.analyze( mockDescriptor, databaseMeta ); }
@Test(expected = MetaverseAnalyzerException.class) public void testSetMetaverseBuilderNullMetaverseObjectFactory() throws MetaverseAnalyzerException { dbConnectionAnalyzer.metaverseObjectFactory = null; dbConnectionAnalyzer.analyze( mockDescriptor, databaseMeta ); }
@Test public void testAnalyze() { when( builder.addNode( any( IMetaverseNode.class ) ) ).thenAnswer( new Answer<Object>() { @Override public Object answer( InvocationOnMock invocation ) throws Throwable { Object[] args = invocation.getArguments(); IMetaverseNode node = (IMetaverseNode)args[0]; node.setProperty( DictionaryConst.PROPERTY_LOGICAL_ID, node.getLogicalId() ); return builder; } } ); try { IMetaverseNode node = dbConnectionAnalyzer.analyze( mockDescriptor, databaseMeta ); builder.addNode( node ); assertNotNull( node ); assertEquals( 14, node.getPropertyKeys().size() ); } catch ( MetaverseAnalyzerException e ) { fail( "analyze() should not throw an exception!" ); } }
@Test(expected = MetaverseAnalyzerException.class) public void testNullAnalyze() throws MetaverseAnalyzerException { dbConnectionAnalyzer.analyze( null, null ); }