<commit_before>package gov.nih.nci.cabig.caaers.dao.index;

import gov.nih.nci.cabig.caaers.CaaersDbTestCase;
import gov.nih.nci.cabig.caaers.domain.UserGroupType;
import gov.nih.nci.cabig.caaers.domain.index.IndexEntry;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author: <NAME>
 */
public class OrganizationIndexDaoIntegrationTest extends CaaersDbTestCase {

    OrganizationIndexDao dao;
    JdbcTemplate template;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        dao = (OrganizationIndexDao) getDeployedApplicationContext().getBean("organizationIndexDao");
        template = (JdbcTemplate) getDeployedApplicationContext().getBean("jdbcTemplate");
    }

  

    public void testUpdateIndex(){
            	
        IndexEntry i0 = new IndexEntry(-1);
        i0.addRole(UserGroupType.business_administrator);
        i0.addRole(UserGroupType.ae_reporter);
        

        IndexEntry i1 = new IndexEntry(-2);
        i1.addRole(UserGroupType.ae_study_data_reviewer);
        List<IndexEntry> iList = new ArrayList<IndexEntry>();
        iList.add(i0);
        iList.add(i1);
        

        
        dao.updateIndex("test", iList);

        
        assertTrue(i0.isAllSiteOrAllStudy());
        assertTrue( iList.size() == 2 );
        assertTrue(i0.getRoles().size() == 2);
        assertTrue ( i0.getRoles().contains(UserGroupType.ae_reporter));
        assertNotNull ( findRole(UserGroupType.ae_reporter, i0));

        
        final Set<Integer> orgList = new HashSet<Integer>(); // Just to make sure not adding duplicate values. 
        template.query("select organization_id from organization_index where login_id = 'test' and r_102 = '1' and r_117 = '1'", new RowMapper(){
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                int i = rs.getInt(1);
                orgList.add(i);
                return null; 
            }
        });
        
        assertTrue(orgList.size() == 2);
    }


    public UserGroupType findRole(UserGroupType ug, IndexEntry entries){
        for(UserGroupType e : entries.getRoles()) if(e == ug) return e;
        return null;
    }
        
}
<commit_msg>CAAERS-6111 Create/Insert data in index when there is a change detected fixing tests<commit_after>package gov.nih.nci.cabig.caaers.dao.index;

import gov.nih.nci.cabig.caaers.CaaersDbTestCase;
import gov.nih.nci.cabig.caaers.domain.UserGroupType;
import gov.nih.nci.cabig.caaers.domain.index.IndexEntry;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author: <NAME>
 */
public class OrganizationIndexDaoIntegrationTest extends CaaersDbTestCase {

    OrganizationIndexDao dao;
    JdbcTemplate template;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        dao = (OrganizationIndexDao) getDeployedApplicationContext().getBean("organizationIndexDao");
        template = (JdbcTemplate) getDeployedApplicationContext().getBean("jdbcTemplate");
    }

  

    public void testUpdateIndex(){
            	
        IndexEntry i0 = new IndexEntry(-1);
        i0.addRole(UserGroupType.business_administrator);
        i0.addRole(UserGroupType.ae_reporter);
        

        IndexEntry i1 = new IndexEntry(-2);
        i1.addRole(UserGroupType.ae_study_data_reviewer);
        List<IndexEntry> iList = new ArrayList<IndexEntry>();
        iList.add(i0);
        iList.add(i1);
        

        
        dao.updateIndex("test", iList);

        

        assertTrue( iList.size() == 2 );
        assertTrue(i0.getRoles().size() == 2);
        assertTrue ( i0.getRoles().contains(UserGroupType.ae_reporter));
        assertNotNull ( findRole(UserGroupType.ae_reporter, i0));

        
        final Set<Integer> orgList = new HashSet<Integer>(); // Just to make sure not adding duplicate values. 
        template.query("select organization_id from organization_index where login_id = 'test' and r_102 = '1' or r_119 = '1'", new RowMapper(){
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                int i = rs.getInt(1);
                orgList.add(i);
                return null; 
            }
        });
        
        assertTrue(orgList.size() == 2);
    }


    public UserGroupType findRole(UserGroupType ug, IndexEntry entries){
        for(UserGroupType e : entries.getRoles()) if(e == ug) return e;
        return null;
    }
        
}

{'fraction_non_alphanumeric': 0.11009174311926606, 'fraction_numerical': 0.010805300713557594, 'mean_word_length': 2.8149300155520995, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1799566', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1496, 'n_words': 295}