/*
 * 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.core.parse.rule.registry.statement;

import org.apache.shardingsphere.core.parse.rule.jaxb.entity.extractor.ExtractorRuleDefinitionEntity;
import org.apache.shardingsphere.core.parse.rule.jaxb.loader.extractor.ExtractorRuleDefinitionEntityLoader;
import org.apache.shardingsphere.core.parse.rule.jaxb.loader.statement.SQLStatementRuleDefinitionEntityLoader;
import org.apache.shardingsphere.core.parse.rule.registry.extractor.ExtractorRuleDefinition;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public final class SQLStatementRuleDefinitionTest {
    
    @Test
    public void assertGetSQLStatementRule() {
        ExtractorRuleDefinitionEntity extractorRuleDefinitionEntity =
                new ExtractorRuleDefinitionEntityLoader().load("META-INF/parsing-rule-definition/extractor-rule-definition.xml");
        SQLStatementRuleDefinition sqlStatementRuleDefinition = new SQLStatementRuleDefinition(
                new SQLStatementRuleDefinitionEntityLoader().load("META-INF/parsing-rule-definition/sql-statement-rule-definition.xml"), new ExtractorRuleDefinition(extractorRuleDefinitionEntity));
        SQLStatementRule sqlStatementRule = sqlStatementRuleDefinition.getSQLStatementRule("SelectContext");
        assertThat(sqlStatementRule.getContextName(), is("select"));
        assertThat(sqlStatementRule.getSqlStatementClass().getName(), is("org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement"));
        assertThat(sqlStatementRule.getExtractors().size(), is(3));
        assertTrue(sqlStatementRule.getOptimizer().isPresent());
    }
}

/*
 * 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.core.parse.rule.registry.statement;

import org.apache.shardingsphere.core.parse.rule.jaxb.entity.extractor.ExtractorRuleDefinitionEntity;
import org.apache.shardingsphere.core.parse.rule.jaxb.loader.extractor.ExtractorRuleDefinitionEntityLoader;
import org.apache.shardingsphere.core.parse.rule.jaxb.loader.statement.SQLStatementRuleDefinitionEntityLoader;
import org.apache.shardingsphere.core.parse.rule.registry.extractor.ExtractorRuleDefinition;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public final class SQLStatementRuleDefinitionTest {
    
    private static SQLStatementRuleDefinition sqlStatementRuleDefinition;
    
    @BeforeClass
    public static void setUp() {
        ExtractorRuleDefinitionEntity extractorRuleDefinitionEntity =
                new ExtractorRuleDefinitionEntityLoader().load("META-INF/parsing-rule-definition/extractor-rule-definition.xml");
        sqlStatementRuleDefinition = new SQLStatementRuleDefinition(
                new SQLStatementRuleDefinitionEntityLoader().load("META-INF/parsing-rule-definition/sql-statement-rule-definition.xml"), new ExtractorRuleDefinition(extractorRuleDefinitionEntity));
    }
    
    @Test
    public void assertSelectStatementRule() {
        SQLStatementRule sqlStatementRule = sqlStatementRuleDefinition.getSQLStatementRule("SelectContext");
        assertThat(sqlStatementRule.getContextName(), is("select"));
        assertThat(sqlStatementRule.getSqlStatementClass().getName(), is("org.apache.shardingsphere.core.parse.sql.statement.dml.SelectStatement"));
        assertThat(sqlStatementRule.getExtractors().size(), is(3));
        assertTrue(sqlStatementRule.getOptimizer().isPresent());
    }
    
    @Test
    public void assertDeleteStatementRule() {
        SQLStatementRule sqlStatementRule = sqlStatementRuleDefinition.getSQLStatementRule("DeleteContext");
        assertThat(sqlStatementRule.getExtractors().size(), is(0));
    }
}

add assertDeleteStatementRule()