package com.cin.test;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.cin.dto.GenericResponse;
import com.cin.dto.IndustryDTO;
import com.cin.dto.OccupationDTO;
import com.cin.dto.StatisticsDTO;
import com.cin.exceptions.PersistenceException;
import com.cin.service.StatisticsService;
import com.cin.test.util.Database;
public class StatisticsServiceTest {
static Database db;
static StatisticsService service;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
db = new Database();
db.resetAllData();
service = new StatisticsService();
}
@Test
public void testCalculateWeeklyWage() throws PersistenceException {
StatisticsDTO aStatistics = new StatisticsDTO();
aStatistics.setState("illinois");
aStatistics.setOccCode(1);
aStatistics.setIndustryCode(9);
GenericResponse aResponse = service.calculateWeeklyWage(aStatistics);
assertTrue(aResponse.isResponseStatus());
assertTrue(aResponse.getStatistics().getAvgWeekWage() > 0);
}
@Test
public void testCalculateAverageIncomeForState() throws PersistenceException {
StatisticsDTO aStatistics = new StatisticsDTO();
aStatistics.setState("illinois");
GenericResponse aResponse = service.calculateAverageIncome(aStatistics);
assertTrue(aResponse.isResponseStatus());
assertTrue(aResponse.getStatistics().getAvgIncome() > 0);
}
@Test
public void testCalculateAverageIncomeForCode() throws PersistenceException {
StatisticsDTO aStatistics = new StatisticsDTO();
aStatistics.setIndustryCode(9);
aStatistics.setOccCode(1);
GenericResponse aResponse = service.calculateAverageIncome(aStatistics);
assertTrue(aResponse.isResponseStatus());
assertTrue(aResponse.getStatistics().getAvgIncome() > 0);
}
@Test
public void testCalculateAverageIncomeForRace() throws PersistenceException {
StatisticsDTO aStatistics = new StatisticsDTO();
aStatistics.setRace("White");
GenericResponse aResponse = service.calculateAverageIncome(aStatistics);
assertTrue(aResponse.isResponseStatus());
assertTrue(aResponse.getStatistics().getAvgIncome() > 0);
}
@Test
public void testCalculateAverageIncomeForEducation() throws PersistenceException {
StatisticsDTO aStatistics = new StatisticsDTO();
aStatistics.setEducationLevel("masters");
GenericResponse aResponse = service.calculateAverageIncome(aStatistics);
assertTrue(aResponse.isResponseStatus());
assertTrue(aResponse.getStatistics().getAvgIncome() > 0);
}
@Test
public void testGetLargestIndustriesInState() throws PersistenceException {
String state = "illinois";
List<IndustryDTO> ret = service.getLargestIndustriesInState(state);
assertTrue( ret.size() > 0 );
}
@Test
public void testGetLargestOccupationsInState() throws PersistenceException {
String state = "illinois";
List<OccupationDTO> ret = service.getLargestOccupationsInState(state);
assertTrue( ret.size() > 0 );
assertTrue( ret.size() <= 5);
}
@Test
public void testGetPrincipleStateForIndustry() {
int industry = 9;
List<String> ret = service.getPrincipleStateForIndustry(industry);
assertTrue( ret.size() > 0 );
assertTrue( ret.size() <= 5 );
}
@Test
public void testGetPrincipleStateForOccupation() {
int occupation = 1;
List<String> ret = service.getPrincipleStateForOccupation(occupation);
assertTrue( ret.size() > 0 );
assertTrue( ret.size() <= 5 );
}
}