/*

   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.CommentTest

       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.derbyTesting.functionTests.tests.lang;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.TestConfiguration;

/**
 * Test for comments.
 */
public final class CommentTest extends BaseJDBCTestCase {
    private Statement stmt;

    /**
     * Public constructor required for running test as standalone JUnit.
     */
    public CommentTest(String name)
    {
        super(name);
    }

    /**
     * Create a suite of tests.
    */
    public static Test suite()
    {
        return TestConfiguration.embeddedSuite(CommentTest.class);
    }

    /**
     * Some simple tests of bracketed comments.
     */
    public void testBracketedComments() throws Exception
    {
        JDBC.assertFullResultSet(
            stmt.executeQuery("/* a comment */ VALUES 1"), 
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES 1 /* a comment */"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* a comment */ 1"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* a comment \n with newline */ 1"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* SELECT * from FOO */ 1"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* a comment /* nested comment */ */ 1"), 
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery(
                "VALUES /*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1"),
            new String [][] {{"1"}});

        // mix with eol-comments
        JDBC.assertFullResultSet(
            stmt.executeQuery(
                "VALUES 1 --/*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery(
                "VALUES 1 --/*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1--/*"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* a comment --\n with newline */ 1"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* a comment -- */ 1"),
            new String [][] {{"1"}});

        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES /* a comment \n-- */ 1"),
            new String [][] {{"1"}});

        // mix with string quotes
        JDBC.assertFullResultSet(
            stmt.executeQuery("VALUES '/* a comment \n-- */'"),
            new String [][] {{"/* a comment \n-- */"}});

        // unterminated comments generate lexical errors
        assertCallError("42X03", getConnection(), "VALUES 1 /*");
        assertCallError("42X03", getConnection(), "VALUES 1 /* comment");
        assertCallError("42X03", getConnection(), "VALUES 1 /* comment /*");
        assertCallError("42X03", getConnection(), "VALUES 1 /* comment /* nested */");

        // just comments generates syntax error
        assertCompileError("42X01", "/* this is a comment */");
        assertCompileError("42X01", "-- this is a comment \n");
    }
    
    /**
     * Set the fixture up.
     */
    protected void setUp() throws SQLException
    {    
        getConnection().setAutoCommit(false);
        stmt = createStatement();
    }
    
    /**
     * Tear-down the fixture.
     */
    protected void tearDown() throws Exception
    {
        stmt.close();
        super.tearDown();
    }
}

@@ -1539,36 +1539,8 @@
 se %7B
-%0A    private Statement stmt;
 %0A%0A  
@@ -1973,32 +1973,85 @@
 Exception%0A    %7B%0A
+        Statement stmt = createStatement();%0A        %0A
         JDBC.ass
@@ -4149,35 +4149,38 @@
 %0A        assertC
-all
+ompile
 Error(%2242X03%22, g
@@ -4174,36 +4174,19 @@
 or(%2242X0
-3
+2
 %22,
- getConnection(),
  %22VALUES
@@ -4201,35 +4201,38 @@
 %0A        assertC
-all
+ompile
 Error(%2242X03%22, g
@@ -4226,36 +4226,19 @@
 or(%2242X0
-3
+2
 %22,
- getConnection(),
  %22VALUES
@@ -4261,35 +4261,38 @@
 %0A        assertC
-all
+ompile
 Error(%2242X03%22, g
@@ -4286,36 +4286,19 @@
 or(%2242X0
-3
+2
 %22,
- getConnection(),
  %22VALUES
@@ -4336,11 +4336,14 @@
 ertC
-all
+ompile
 Erro
@@ -4353,28 +4353,11 @@
 42X0
-3
+2
 %22,
- getConnection(),
  %22VA
@@ -4597,105 +4597,17 @@
   * 
-Set the fixture up.%0A     */%0A    protected void setUp() throws SQLException%0A    %7B    %0A        getC
+Default c
 onne
@@ -4615,152 +4615,95 @@
 tion
-().setAutoC
+s to auto-c
 ommit
-(
+ 
 false
-);%0A        stmt = createStatement();%0A    %7D%0A    %0A    /**%0A     * Tear-down the fixture.%0A     */%0A    protected void tearDown(
+.%0A     */%0A    protected void initializeConnection(Connection conn
 ) th
@@ -4699,32 +4699,35 @@
 on conn) throws 
+SQL
 Exception%0A    %7B%0A
@@ -4729,54 +4729,45 @@
    %7B
-%0A
     
-    stmt.close();%0A        super.tearDown(
+%0A        conn.setAutoCommit(false
 );%0A 

Clean up CommentTest to not use a field to hold a Statement object (no need). Also to use assertCompileError() instead of assertCallError() since that's actually what it being tested (a compile failure). This meant checking for the correct SQL state, not an incorrect one, this was previously hidden by a bug in assertCallError().