@Test
public void provideTableMetadataTest() throws ConnectorException {

    DBCollection collection = mock(DBCollection.class);
    when(client.getDB(DB_NAME)).thenReturn(database);
    when(database.getCollection(TABLE_NAME)).thenReturn(collection);
    PowerMockito.mockStatic(DiscoverMetadataUtils.class);
    when(DiscoverMetadataUtils.discoverFieldsWithType(collection,"1")).thenReturn(fielddWithType);
    when(DiscoverMetadataUtils.discoverIndexes(collection)).thenReturn(
            getIndexMetadata(COLUMN_NAME2, IndexType.CUSTOM));
    TableMetadata tableMetadataProvided = mongoMetadataEngine.provideTableMetadata(new TableName(DB_NAME,
                    TABLE_NAME), new ClusterName(CLUSTER_NAME), connection);
    // names
    Assert.assertEquals("The table name is not the expected", TABLE_NAME, tableMetadataProvided.getName().getName());
    Assert.assertEquals("The cluster name is not the expected", CLUSTER_NAME, tableMetadataProvided.getClusterRef()
                    .getName());
    Assert.assertEquals("The catalog name is not the expected", DB_NAME, tableMetadataProvided.getName()
                    .getCatalogName().getName());
    // pKey
    Assert.assertEquals("The primary key must have only one field", 1, tableMetadataProvided.getPrimaryKey().size());
    Assert.assertEquals("The primary key must be the first field", tableMetadataProvided.getColumns().entrySet().iterator().next().getKey().getName(), tableMetadataProvided.getPrimaryKey().get(0)
                    .getName());
    // columns
    Assert.assertEquals("The columns must have one column", 1, tableMetadataProvided.getColumns().size());
    Assert.assertTrue("The column found in existing bson is not the expected", tableMetadataProvided.getColumns()
                    .keySet().contains(new ColumnName(DB_NAME, TABLE_NAME, COLUMN_NAME)));
    Assert.assertTrue("The column found in existing index is not the expected",
    tableMetadataProvided.getColumns().keySet().contains(new ColumnName(DB_NAME, TABLE_NAME, COLUMN_NAME)));
    // index
    Assert.assertEquals("There must be a single index", 1, tableMetadataProvided.getIndexes().size());
    Assert.assertTrue("The index name is not the expected",
                    tableMetadataProvided.getIndexes().containsKey(new IndexName(DB_NAME, TABLE_NAME, INDEX_NAME)));
    IndexMetadata indexMetadata = tableMetadataProvided.getIndexes().get(
                    new IndexName(DB_NAME, TABLE_NAME, INDEX_NAME));
    Assert.assertEquals("The index type is not the expected", IndexType.CUSTOM, indexMetadata.getType());
    Assert.assertEquals("There must be a single column", 1, indexMetadata.getColumns().size());
    Assert.assertTrue("There index column is not the expected",
                    indexMetadata.getColumns().containsKey(new ColumnName(DB_NAME, TABLE_NAME, COLUMN_NAME2)));
}