<commit_before>/**
 * Copyright 2013 Unicon (R) Licensed under the
 * Educational Community 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.osedu.org/licenses/ECL-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.apereo.lap.services;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@TransactionConfiguration(defaultRollback = true)
@ContextConfiguration({ "classpath:test-context.xml" })
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
public class StorageServiceTest {
    private static final Logger logger = LoggerFactory.getLogger(StorageService.class);

    @Autowired
    ConfigurationService configuration;

    @Autowired
    StorageService storage;

    @Before
    @BeforeTransaction
    public void before() {
        configuration.config().setProperty("test", true);
        assertTrue( configuration.is("test") );
    }

    @Test
    public void testService() {
        assertNotNull(storage);
        assertNotNull(storage.getConfiguration());
        assertNotNull(storage.getTempDataSource());
        assertNotNull(storage.getPersistentDataSource());
        assertNotNull(storage.getTempJdbcTemplate());
        assertNotNull(storage.getPersistentJdbcTemplate());


        // TODO add real tests
    }
}
<commit_msg>LAP-14 more storage unit tests to verify things are working<commit_after>/**
 * Copyright 2013 Unicon (R) Licensed under the
 * Educational Community 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.osedu.org/licenses/ECL-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.apereo.lap.services;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

/**
 * Integration services test for Storage
 */
@TransactionConfiguration(defaultRollback = true)
@ContextConfiguration({ "classpath:test-context.xml" })
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
public class StorageServiceTest {
    private static final Logger logger = LoggerFactory.getLogger(StorageService.class);

    @Autowired
    ConfigurationService configuration;

    @Autowired
    StorageService storage;

    @javax.annotation.Resource
    ResourceLoader resourceLoader;

    @Before
    @BeforeTransaction
    public void before() {
        configuration.config().setProperty("test", true);
        assertTrue( configuration.is("test") );
    }

    @Test
    public void testServiceLoad() {
        assertNotNull(storage);
        assertNotNull(storage.getConfiguration());
        assertNotNull(storage.getTempDataSource());
        assertNotNull(storage.getPersistentDataSource());
        assertNotNull(storage.getTempJdbcTemplate());
        assertNotNull(storage.getPersistentJdbcTemplate());
    }

    @Test
    public void testServiceSQL() {
        List<Map<String, Object>> results;
        assertNotNull(storage);

        // check for empty tables
        results = storage.getTempJdbcTemplate().queryForList("SELECT * FROM PERSONAL");
        assertNotNull(results);
        assertTrue( results.isEmpty() );

        Resource sample = resourceLoader.getResource("sample.sql");
        JdbcTestUtils.executeSqlScript(storage.getTempJdbcTemplate(), sample, true);
        logger.info("Loaded sample SQL script: "+sample.getFilename());

        results = storage.getTempJdbcTemplate().queryForList("SELECT * FROM PERSONAL");
        assertNotNull(results);
        assertTrue(!results.isEmpty());
        assertEquals(2, results.size());
    }

}

{'fraction_non_alphanumeric': 0.09510869565217392, 'fraction_numerical': 0.005253623188405797, 'mean_word_length': 4.381091617933723, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1216916', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1386, 'n_words': 374}