MongoMetadataEngine extends CommonsMetadataEngine<MongoClient> { @Override protected void createIndex(IndexMetadata indexMetadata, Connection<MongoClient> connection) throws ExecutionException { DB db = connection.getNativeConnection().getDB( indexMetadata.getName().getTableName().getCatalogName().getName()); DBObject indexDBObject = IndexUtils.getIndexDBObject(indexMetadata); DBObject indexOptionsDBObject = IndexUtils.getCustomOptions(indexMetadata); try { db.getCollection(indexMetadata.getName().getTableName().getName()).createIndex(indexDBObject, indexOptionsDBObject); } catch (MongoException e) { logger.error("Error creating the index: " + e.getMessage()); throw new ExecutionException(e.getMessage(), e); } if (logger.isDebugEnabled()) { logger.debug("Index created: " + indexDBObject.toString() + " with options: " + indexOptionsDBObject); } } private  MongoMetadataEngine(MongoConnectionHandler connectionHandler); static MongoMetadataEngine getInstance(MongoConnectionHandler connectionHandler);  }
@Test public void createIndexTest() throws ExecutionException, UnsupportedException { IndexMetadataBuilder indexMetadataBuilder = new IndexMetadataBuilder(DB_NAME, TABLE_NAME, INDEX_NAME, IndexType.DEFAULT); indexMetadataBuilder.addColumn(COLUMN_NAME, new ColumnType(DataType.VARCHAR)); indexMetadataBuilder.addColumn(COLUMN_NAME2, new ColumnType(DataType.INT)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); DBCollection collection = mock(DBCollection.class); when(client.getDB(DB_NAME)).thenReturn(database); when(database.getCollection(TABLE_NAME)).thenReturn(collection); mongoMetadataEngine.createIndex(indexMetadata, connection); verify(client, times(1)).getDB(DB_NAME); verify(collection, times(1)).createIndex(new BasicDBObject(COLUMN_NAME, 1).append(COLUMN_NAME2, 1), new BasicDBObject("name", INDEX_NAME)); }