/*
 * 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.optimize.result;

import com.google.common.collect.Lists;
import org.apache.shardingsphere.core.optimize.result.insert.InsertOptimizeResult;
import org.apache.shardingsphere.core.parse.sql.context.expression.SQLExpression;
import org.apache.shardingsphere.core.parse.sql.context.expression.SQLNumberExpression;
import org.apache.shardingsphere.core.parse.sql.context.expression.SQLParameterMarkerExpression;
import org.apache.shardingsphere.core.parse.sql.context.expression.SQLTextExpression;
import org.junit.Test;

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

public final class InsertOptimizeResultTest {
    
    private InsertOptimizeResult setInsertOptimizeResult = new InsertOptimizeResult(Lists.newArrayList("id", "value", "status"));
    
    private InsertOptimizeResult valuesInsertOptimizeResult = new InsertOptimizeResult(Lists.newArrayList("id", "value", "status"));
    
    @Test
    public void assertAddUnitWithSet() {
        SQLExpression[] expressions = {new SQLNumberExpression(1), new SQLParameterMarkerExpression(1), new SQLTextExpression("test")};
        Object[] parameters = {"parameter"};
        setInsertOptimizeResult.addUnit(expressions, parameters, 1);
        assertThat(setInsertOptimizeResult.getColumnNames().size(), is(3));
        assertThat(setInsertOptimizeResult.getUnits().get(0).getValues(), is(expressions));
        assertThat(setInsertOptimizeResult.getUnits().get(0).getParameters()[0], is((Object) "parameter"));
        assertThat(setInsertOptimizeResult.getUnits().get(0).getDataNodes().size(), is(0));
        assertThat(setInsertOptimizeResult.getUnits().get(0).getColumnValue("value"), is((Object) "parameter"));
        assertThat(setInsertOptimizeResult.getUnits().get(0).getColumnValue("status"), is((Object) "test"));
        setInsertOptimizeResult.getUnits().get(0).setColumnValue("id", 2);
        assertThat(setInsertOptimizeResult.getUnits().get(0).getColumnValue("id"), is((Object) 2));
        setInsertOptimizeResult.getUnits().get(0).setColumnValue("value", "parameter1");
        assertThat(setInsertOptimizeResult.getUnits().get(0).getColumnValue("value"), is((Object) "parameter1"));
    }
}

@@ -1525,20 +1525,17 @@
 eResult 
-setI
+i
 nsertOpt
@@ -1628,141 +1628,8 @@
    %0A
-    private InsertOptimizeResult valuesInsertOptimizeResult = new InsertOptimizeResult(Lists.newArrayList(%22id%22, %22value%22, %22status%22));%0A
     
@@ -1861,36 +1861,33 @@
 eter%22%7D;%0A        
-setI
+i
 nsertOptimizeRes
@@ -1938,36 +1938,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2011,36 +2011,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2100,36 +2100,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2205,36 +2205,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2294,36 +2294,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2404,36 +2404,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2499,36 +2499,33 @@
 est%22));%0A        
-setI
+i
 nsertOptimizeRes
@@ -2582,36 +2582,33 @@
      assertThat(
-setI
+i
 nsertOptimizeRes
@@ -2676,20 +2676,17 @@
         
-setI
+i
 nsertOpt
@@ -2777,12 +2777,9 @@
 hat(
-setI
+i
 nser

optimize InsertOptimizeResultTest