<commit_before>package com.ecyrd.jspwiki.auth.user;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import junit.framework.TestCase;

import com.ecyrd.jspwiki.TestJDBCDataSource;
import com.ecyrd.jspwiki.TestJNDIContext;
import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
import com.ecyrd.jspwiki.auth.WikiSecurityException;

/**
 * @author <NAME>
 */
public class JDBCUserDatabaseTest extends TestCase
{
    private Connection       m_conn = null;

    private JDBCUserDatabase m_db   = null;

    private Date             m_createStamp;

    /**
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();

        // Set up the mock JNDI initial context
        TestJNDIContext.initialize();
        Context initCtx = new InitialContext();
        initCtx.bind( "java:comp/env", new TestJNDIContext() );
        Context ctx = (Context) initCtx.lookup( "java:comp/env" );
        DataSource ds = new TestJDBCDataSource( new File( "build.properties" ) );
        ctx.bind( JDBCUserDatabase.DEFAULT_DB_JNDI_NAME, ds );

        // Get the JDBC connection and init tables
        Connection m_conn = ds.getConnection();
        Statement stmt = m_conn.createStatement();
        ResultSet rs;
        String sql;

        sql = "DELETE FROM " + JDBCUserDatabase.DEFAULT_DB_TABLE + ";";
        rs = stmt.executeQuery( sql );

        // Create a new test user 'janne'
        m_createStamp = new Timestamp( System.currentTimeMillis() );
        sql = "INSERT INTO users (" + JDBCUserDatabase.DEFAULT_DB_EMAIL + "," + JDBCUserDatabase.DEFAULT_DB_FULL_NAME
                + "," + JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," + JDBCUserDatabase.DEFAULT_DB_PASSWORD + ","
                + JDBCUserDatabase.DEFAULT_DB_WIKI_NAME + "," + JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES ("
                + "'<EMAIL>'," + "'<NAME>'," + "'janne',"
                + "'{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee'," + "'JanneJalkanen'," + "'"
                + new Timestamp( m_createStamp.getTime() ).toString() + "'" + ");";
        rs = stmt.executeQuery( sql );

        // Create a new test user 'user'
        sql = "INSERT INTO users (" + JDBCUserDatabase.DEFAULT_DB_EMAIL + "," + JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME
                + "," + JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," + JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES ("
                + "'<EMAIL>'," + "'user'," + "'{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'," + "'"
                + new Timestamp( m_createStamp.getTime() ).toString() + "'" + ");";
        rs = stmt.executeQuery( sql );

        // Initialize the user database
        m_db = new JDBCUserDatabase();
        m_db.initialize( null, new Properties() );
    }

    public void tearDown() throws Exception
    {
        if ( m_conn != null )
        {<commit_msg>Fixed SQL calls that should have used 'executeUpdate' instead of 'executeQuery' for test harness INSERT statements.<commit_after>package com.ecyrd.jspwiki.auth.user;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import junit.framework.TestCase;

import com.ecyrd.jspwiki.TestJDBCDataSource;
import com.ecyrd.jspwiki.TestJNDIContext;
import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
import com.ecyrd.jspwiki.auth.WikiSecurityException;

/**
 * @author <NAME>
 */
public class JDBCUserDatabaseTest extends TestCase
{
    private Connection       m_conn = null;

    private JDBCUserDatabase m_db   = null;

    private Date             m_createStamp;

    /**
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();

        // Set up the mock JNDI initial context
        TestJNDIContext.initialize();
        Context initCtx = new InitialContext();
        initCtx.bind( "java:comp/env", new TestJNDIContext() );
        Context ctx = (Context) initCtx.lookup( "java:comp/env" );
        DataSource ds = new TestJDBCDataSource( new File( "build.properties" ) );
        ctx.bind( JDBCUserDatabase.DEFAULT_DB_JNDI_NAME, ds );

        // Get the JDBC connection and init tables
        Connection m_conn = ds.getConnection();
        Statement stmt = m_conn.createStatement();
        String sql;

        sql = "DELETE FROM " + JDBCUserDatabase.DEFAULT_DB_TABLE + ";";
        stmt.executeUpdate( sql );

        // Create a new test user 'janne'
        m_createStamp = new Timestamp( System.currentTimeMillis() );
        sql = "INSERT INTO users (" + JDBCUserDatabase.DEFAULT_DB_EMAIL + "," + JDBCUserDatabase.DEFAULT_DB_FULL_NAME
                + "," + JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," + JDBCUserDatabase.DEFAULT_DB_PASSWORD + ","
                + JDBCUserDatabase.DEFAULT_DB_WIKI_NAME + "," + JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES ("
                + "'<EMAIL>'," + "'<NAME>'," + "'janne',"
                + "'{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee'," + "'JanneJalkanen'," + "'"
                + new Timestamp( m_createStamp.getTime() ).toString() + "'" + ");";
        stmt.executeUpdate( sql );

        // Create a new test user 'user'
        sql = "INSERT INTO users (" + JDBCUserDatabase.DEFAULT_DB_EMAIL + "," + JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME
                + "," + JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," + JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES ("
                + "'<EMAIL>'," + "'user'," + "'{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'," + "'"
                + new Timestamp( m_createStamp.getTime() ).toString() + "'" + ");";
        stmt.executeUpdate( sql );

        // Initialize the user database
        m_db = new JDBCUserDatabase();
        m_db.initialize( null, new Properties() );
    }

    public void tearDown() throws Exception
    {
        if ( m_conn != null )
        {
{'fraction_non_alphanumeric': 0.12432346386501114, 'fraction_numerical': 0.014645017510347023, 'mean_word_length': 2.890402476780186, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4553279', 'n_tokens_mistral': 2057, 'n_tokens_neox': 1934, 'n_words': 390}