/*
 * Copyright (c) 2012 Alvin R. de Leon. All Rights Reserved.
 *
 * Licensed 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.piraso.ui.sql;

import org.hibernate.jdbc.util.BasicFormatterImpl;
import org.hibernate.jdbc.util.Formatter;
import org.piraso.api.AbstractJacksonTest;
import org.piraso.api.GeneralPreferenceEnum;
import org.piraso.api.Preferences;
import org.piraso.api.sql.SQLPreferenceEnum;
import org.piraso.ui.api.NewContextMonitorModel;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;

/**
 * Used for profile creation
 */
public class ProfileTest extends AbstractJacksonTest {

    @Test
    public void testJackson() throws Exception {
        NewContextMonitorModel expected = new NewContextMonitorModel();

        expected.setLoggingUrl("http://127.0.0.1/piraso/logging");
        expected.setDesc("Profile for checking SQL Queries and retrieved Data.");

        Preferences preferences = new Preferences();

        preferences.addProperty(GeneralPreferenceEnum.SCOPE_ENABLED.getPropertyName(), true);
        //preferences.addProperty(GeneralPreferenceEnum.STACK_TRACE_ENABLED.getPropertyName(), true);
        preferences.addProperty(SQLPreferenceEnum.CONNECTION_ENABLED.getPropertyName(), true);
        //preferences.addProperty(SQLPreferenceEnum.CONNECTION_METHOD_CALL_ENABLED.getPropertyName(), true);
        preferences.addProperty(SQLPreferenceEnum.PREPARED_STATEMENT_ENABLED.getPropertyName(), true);
        preferences.addProperty(SQLPreferenceEnum.VIEW_SQL_ENABLED.getPropertyName(), true);
        //preferences.addProperty(SQLPreferenceEnum.PREPARED_STATEMENT_METHOD_CALL_ENABLED.getPropertyName(), true);
        preferences.addProperty(SQLPreferenceEnum.RESULTSET_ENABLED.getPropertyName(), true);

        expected.setPreferences(preferences);

        String str = mapper.writeValueAsString(expected);
        NewContextMonitorModel actual = mapper.readValue(str, NewContextMonitorModel.class);

        assertEquals(expected, actual);

        System.out.println("JSON: " + str);
        System.out.println("REPLACE: " + str.replaceAll("\"", "&quot;"));
    }

    @Test
    public void testSQLFormat() throws Exception {
        BasicFormatterImpl formatter = new BasicFormatterImpl();
        System.out.println(formatter.format("select * from dog"));
    }
}

@@ -652,101 +652,8 @@
 l;%0A%0A
-import org.hibernate.jdbc.util.BasicFormatterImpl;%0Aimport org.hibernate.jdbc.util.Formatter;%0A
 impo
@@ -2608,73 +2608,8 @@
 n %7B%0A
-        BasicFormatterImpl formatter = new BasicFormatterImpl();%0A
     
@@ -2635,17 +2635,24 @@
 tln(
-f
+new SQLF
 ormatter
 .for
@@ -2647,16 +2647,18 @@
 ormatter
+()
 .format(

fix failing test