/*
 * Licensed to STRATIO (C) under one or more contributor license agreements.
 *  See the NOTICE file distributed with this work for additional information
 *  regarding copyright ownership. The STRATIO (C) 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 com.stratio.connector.elasticsearch.core.engine.utils;

import static org.junit.Assert.assertEquals;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.stratio.meta2.common.data.ClusterName;
import com.stratio.meta2.common.data.ColumnName;
import com.stratio.meta2.common.data.TableName;
import com.stratio.meta2.common.metadata.ColumnMetadata;
import com.stratio.meta2.common.metadata.ColumnType;
import com.stratio.meta2.common.metadata.TableMetadata;

import com.stratio.meta2.common.statements.structures.selectors.IntegerSelector;
import com.stratio.meta2.common.statements.structures.selectors.Selector;
import com.stratio.meta2.common.statements.structures.selectors.StringSelector;

/**
 * DeepContentBuilder Tester.
 *
 * @author <Authors name>
 * @version 1.0
 * @since <pre>sep 11, 2014</pre>
 */
public class ContentBuilderCreatorTest {

    public static final String INDEX_NAME = "index";
    public static final String TYPE_NAME = "type";
    public static final String CLUSTER_NAME = "CLUSTER_NAME";
    private static final String RESULT_CREATE_TABLE = "{\"settings\":{\"index\":{\"number_of_shards\":5," +
            "\"number_of_replicas\":2,\"other\":\"String value\"}},\"properties\":{\"column_3\":{\"type\":\"double\"},\"column_5\":{\"type\":\"integer\"},\"column_7\":{\"type\":\"string\"},\"column_2\":{\"type\":\"boolean\"},\"column_6\":{\"type\":\"string\"},\"column_4\":{\"type\":\"float\"},\"column_1\":{\"type\":\"long\"}}}"M
    ContentBuilderCreator deepContentBuilder;

    @Before
    public void before() throws Exception {

        deepContentBuilder = new ContentBuilderCreator();
    }

    @After
    public void after() throws Exception {
    }

    /**
     * Method: createTypeSource(TableMetadata typeMetadata)
     */
    @Test
    public void testCreateTable() throws Exception {

        Map indexex = Collections.EMPTY_MAP;
        Map<Selector, Selector> options = new LinkedHashMap<>();
        options.put(new StringSelector("number_of_shards"),new IntegerSelector(5));
        options.put(new StringSelector("number_of_replicas"),new IntegerSelector(2));
        options.put(new StringSelector("other"),new StringSelector("String value"));
        List<ColumnName> partitionKey = Collections.EMPTY_LIST;
        List<ColumnName> clusterKey = Collections.EMPTY_LIST;

        Map<ColumnName, ColumnMetadata> columns = new HashMap<>();
        columns.putAll(creteColumns("column_1", ColumnType.BIGINT));
        columns.putAll(creteColumns("column_2", ColumnType.BOOLEAN));
        columns.putAll(creteColumns("column_3", ColumnType.DOUBLE));
        columns.putAll(creteColumns("column_4", ColumnType.FLOAT));
        columns.putAll(creteColumns("column_5", ColumnType.INT));
        columns.putAll(creteColumns("column_6", ColumnType.TEXT));
        columns.putAll(creteColumns("column_7", ColumnType.VARCHAR));

        ClusterName cluteref = new ClusterName(CLUSTER_NAME);

        TableMetadata tableMetadata = new TableMetadata(new TableName(INDEX_NAME, TYPE_NAME), options, columns, indexex,
                cluteref, partitionKey, clusterKey);
        assertEquals("The JSON is correct", RESULT_CREATE_TABLE,
                (deepContentBuilder.createTypeSource(tableMetadata).string()));

    }

    private Map<ColumnName, ColumnMetadata> creteColumns(String columnName, ColumnType columnType) {
        Map<ColumnName, ColumnMetadata> columns = new HashMap<>();
        ColumnName column = new ColumnName(INDEX_NAME, TYPE_NAME, columnName);
        columns.put(column, new ColumnMetadata(column, null, columnType));

        return columns;
    }

}

@@ -2155,16 +2155,33 @@
 lue%5C%22%7D%7D,
+%22 +%0A            %22
 %5C%22proper
@@ -2434,17 +2434,17 @@
 ng%5C%22%7D%7D%7D%22
-M
+;
 %0A    Con

correct compilation failure