<commit_before>package studentcapture.datalayer.database;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.context.WebApplicationContext;

import studentcapture.config.StudentCaptureApplicationTests;
// import studentcapture.datalayer.database.Submission.SubmissionWrapper;
import studentcapture.datalayer.database.User.CourseAssignmentHierarchy;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

/**
 * Created by tfy12hsm.
 */
public class UserTest  extends StudentCaptureApplicationTests {

    @Autowired
    private WebApplicationContext webApplicationContext;

    @Autowired
    User user;

    @Autowired
    private JdbcTemplate jdbcMock;

    @Before
    public void setUp() {
        //Over writes the actual database with fake.
        H2DataSource src = new H2DataSource();
        jdbcMock.setDataSource(src.dataSource());

    }


    @Test
    public void testAddUser() {

       boolean res =  user.addUser("userPelle","Pelle","Jönsson","1944","<PASSWORD>");

        String sql = "SELECT * FROM users WHERE username = 'userPelle'";

        //Getting values from table user
        HashMap<String,String> info = (HashMap<String,String>)
                jdbcMock.queryForObject(sql, new UserWrapper());

        assertEquals("userPelle",info.get("username"));
        assertEquals("Pelle",info.get("fName"));
        assertEquals("Jönsson",info.get("lName"));
        assertEquals("1944",info.get("SNN"));
    }


    @Test
    public void getCourseAssignmentHierarchyUserInformationTest() {
    	String getUserStatement = "SELECT * FROM Users WHERE "
        		+ "UserId=?";
    	String getTeacherHierarchyStatement = "SELECT * FROM Participant AS par"
				+ " LEFT JOIN Course AS cou ON par.courseId="
	    		+ "cou.courseId LEFT JOIN Assignment AS ass ON cou.courseId="
	    		+ "ass.courseId LEFT JOIN Submission AS sub ON "
	    		+ "ass.assignmentId=sub.assignmentId WHERE par.userId=? AND "
	    		+ "par.function='Teacher'";
    	String getStudentHierarchyStatement = "SELECT * FROM "
	    		+ "Participant AS par LEFT JOIN Course AS cou ON par.courseId="<commit_msg>Removed unnecessary setup<commit_after>package studentcapture.datalayer.database;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.context.WebApplicationContext;

import studentcapture.config.StudentCaptureApplicationTests;
// import studentcapture.datalayer.database.Submission.SubmissionWrapper;
import studentcapture.datalayer.database.User.CourseAssignmentHierarchy;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

/**
 * Created by tfy12hsm.
 */
public class UserTest  extends StudentCaptureApplicationTests {

    @Autowired
    private WebApplicationContext webApplicationContext;

    @Autowired
    User user;

    @Autowired
    private JdbcTemplate jdbcMock;

    @Test
    public void testAddUser() {

       boolean res =  user.addUser("userPelle","Pelle","Jönsson","<PASSWORD>","<PASSWORD>");

        String sql = "SELECT * FROM users WHERE username = 'userPelle'";

        //Getting values from table user
        HashMap<String,String> info = (HashMap<String,String>)
                jdbcMock.queryForObject(sql, new UserWrapper());

        assertEquals("userPelle",info.get("username"));
        assertEquals("Pelle",info.get("fName"));
        assertEquals("Jönsson",info.get("lName"));
        assertEquals("1944",info.get("SNN"));
    }


    @Test
    public void getCourseAssignmentHierarchyUserInformationTest() {
    	String getUserStatement = "SELECT * FROM Users WHERE "
        		+ "UserId=?";
    	String getTeacherHierarchyStatement = "SELECT * FROM Participant AS par"
				+ " LEFT JOIN Course AS cou ON par.courseId="
	    		+ "cou.courseId LEFT JOIN Assignment AS ass ON cou.courseId="
	    		+ "ass.courseId LEFT JOIN Submission AS sub ON "
	    		+ "ass.assignmentId=sub.assignmentId WHERE par.userId=? AND "
	    		+ "par.function='Teacher'";
    	String getStudentHierarchyStatement = "SELECT * FROM "
	    		+ "Participant AS par LEFT JOIN Course AS cou ON par.courseId="
{'fraction_non_alphanumeric': 0.10602067707277518, 'fraction_numerical': 0.0036488951956213257, 'mean_word_length': 3.934, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '1790836', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1413, 'n_words': 323}