/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.infra.metadata.refresh;

import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.refresh.impl.DropIndexStatementMetaDataRefreshStrategy;
import org.apache.shardingsphere.sql.parser.binder.statement.ddl.DropIndexStatementContext;
import org.apache.shardingsphere.sql.parser.sql.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.sql.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
import org.junit.Test;

import java.sql.SQLException;
import java.util.Collections;
import java.util.Optional;

import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;

public final class DropIndexStatementMetaDataRefreshStrategyTest extends AbstractMetaDataRefreshStrategyTest {
    
    @Test
    public void refreshMetaData() throws SQLException {
        MetaDataRefreshStrategy<DropIndexStatementContext> metaDataRefreshStrategy = new DropIndexStatementMetaDataRefreshStrategy();
        DropIndexStatement dropIndexStatement = new DropIndexStatement();
        dropIndexStatement.getIndexes().add(new IndexSegment(1, 2, new IdentifierValue("index")));
        dropIndexStatement.setTable(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue("t_order"))));
        DropIndexStatementContext dropIndexStatementContext = new DropIndexStatementContext(dropIndexStatement);
        metaDataRefreshStrategy.refreshMetaData(getMetaData(), mock(DatabaseType.class), Collections.emptyMap(), dropIndexStatementContext, tableName -> Optional.empty());
        assertFalse(getMetaData().getSchema().getConfiguredSchemaMetaData().get("t_order").getIndexes().containsKey("index"));
    }
}

@@ -855,16 +855,125 @@
 fresh;%0A%0A
+import java.sql.SQLException;%0Aimport java.util.Collections;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0A
 import o
@@ -1031,16 +1031,16 @@
 seType;%0A
-
 import o
@@ -1135,16 +1135,97 @@
 rategy;%0A
+import org.apache.shardingsphere.sql.parser.binder.metadata.index.IndexMetaData;%0A
 import o
@@ -1758,96 +1758,8 @@
 t;%0A%0A
-import java.sql.SQLException;%0Aimport java.util.Collections;%0Aimport java.util.Optional;%0A%0A
 impo
@@ -2730,24 +2730,24 @@
 l.empty());%0A
-
         asse
@@ -2867,10 +2867,1709 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void assertRemoveIndexes() throws SQLException %7B%0A        Map%3CString, IndexMetaData%3E actualIndex = getMetaData().getSchema().getConfiguredSchemaMetaData().get(%22t_order%22).getIndexes();%0A        actualIndex.put(%22t_order_index%22, new IndexMetaData(%22t_order_index%22));%0A        actualIndex.put(%22order_id_index%22, new IndexMetaData(%22order_id_index%22));%0A        DropIndexStatement dropIndexStatement = new DropIndexStatement();%0A        dropIndexStatement.getIndexes().add(new IndexSegment(1, 2, new IdentifierValue(%22index%22)));%0A        dropIndexStatement.getIndexes().add(new IndexSegment(2, 3, new IdentifierValue(%22t_order_index%22)));%0A        dropIndexStatement.getIndexes().add(new IndexSegment(3, 4, new IdentifierValue(%22order_id_index%22)));%0A        dropIndexStatement.setTable(new SimpleTableSegment(new TableNameSegment(1, 3, new IdentifierValue(%22t_order%22))));%0A        DropIndexStatementContext dropIndexStatementContext = new DropIndexStatementContext(dropIndexStatement);%0A        MetaDataRefreshStrategy%3CDropIndexStatementContext%3E metaDataRefreshStrategy = new DropIndexStatementMetaDataRefreshStrategy();%0A        metaDataRefreshStrategy.refreshMetaData(getMetaData(), mock(DatabaseType.class), Collections.emptyMap(), dropIndexStatementContext, tableName -%3E Optional.empty());%0A        assertFalse(getMetaData().getSchema().getConfiguredSchemaMetaData().get(%22t_order%22).getIndexes().containsKey(%22index%22));%0A        assertFalse(getMetaData().getSchema().getConfiguredSchemaMetaData().get(%22t_order%22).getIndexes().containsKey(%22t_order_index%22));%0A        assertFalse(getMetaData().getSchema().getConfiguredSchemaMetaData().get(%22t_order%22).getIndexes().containsKey(%22order_id_index%22));%0A    %7D%0A
 %7D%0A

add test case DropIndexStatementMetaDataRefreshStrategy (#6728)