Package com.cin.test

Source Code of com.cin.test.CensusInsuranceServiceTest

package com.cin.test;

import static org.junit.Assert.*;
import org.junit.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.cin.dto.*;
import com.cin.ejb.transactionejb.UserFactory;
import com.cin.exceptions.*;
import com.cin.jndi.lookup.EJBLookup;
import com.cin.service.CensusInsuranceService;
import com.cin.service.ScoreCache;
import com.cin.test.util.*;


public class CensusInsuranceServiceTest {
  static Database db;
  static UserFactory userFactory;
  static CensusInsuranceService service;
 
  @BeforeClass
  public static void initClass() throws Exception{
    db = new Database();
    db.resetAllData();
   
    userFactory = EJBLookup.getInstance().getUserFactory();
    service = new CensusInsuranceService();
  }
 
  @Before
  public void setup(){
    ScoreCache.getInstance().clearAll();
  }

  @Test
  public final void testCalculateQuoteForPolicy() throws Exception{
    int ssn = 10;
    int value = 1000;
    int deductibles = 50;
    InsurencePolicyDTO policy = new InsurencePolicyDTO(0, ssn, "my property", value, deductibles, 0, null, null);
    int quote = service.calculateQuoteForPolicy(policy);
   
    assertTrue(quote > 1);
  }

  @Test
  public final void testCalculateScoreForUser() throws Exception{
    int ssn = 10;
   
    UserDTO user = new UserDTO(ssn);
    service.calculateScoreForUser(user);
   
    assertTrue( user.getScore() > 0 );
    assertTrue( user.getScore() <= 100 );
  }
 
  @Test
  public final void testCalculateScoreForUserMissingEducation() throws Exception {
    int ssn = 13;
   
    UserDTO user = new UserDTO(ssn);
    service.calculateScoreForUser(user);
   
    assertTrue( user.getScore() > 0 );
    assertTrue( user.getScore() <= 100 );
  }
 
  @Test(expected=MissingInformationException.class)
  public final void testCalculateScoreForUserMissingInfo() throws Exception {
    int ssn = 18;
   
    UserDTO user = new UserDTO(ssn);
    service.calculateScoreForUser(user);
  }

  @Test
  public void testCalculateScoreForUsers() throws Exception {
    List<UserDTO> users = new ArrayList<UserDTO>();
    users.add(new UserDTO(10));
    users.add(new UserDTO(11));
   
    service.calculateScoreForUsers(users);
   
    for(UserDTO u : users){
      assertTrue( u.getScore() > 0 );
    }
  }

  @Test
  public void testCalculateUnemployementForState() {
    service.calculateUnemployementForState("Illinois");
  }


  @Test
  public void testChangeUserEmployment() throws Exception{
    EmploymentTable employTable = db.getTable(EmploymentTable.class);
    JobTable jobTable = db.getTable(JobTable.class);
   
    try{
      int ssn = 10;
      UserDTO user = service.retrieveUserRecord(ssn);
      user.getEmploymentStatus().setEmploymentStatus("new employment status");
      user.getEmploymentStatus().setUnemploymentReason("new unemployment reason");
      user.getJobDetails().setEmployerSize(13);
      user.getJobDetails().setUnionMember("new union member status");
     
      service.changeUserEmployment(user);
     
      EmploymentStatusDTO employRow = employTable.getRow(ssn);
      assertNotNull( employRow );
      assertEquals( "new employment status", employRow.getEmploymentStatus() );
      assertEquals( "new unemployment reason", employRow.getUnemploymentReason() );
     
      JobDTO jobRow = jobTable.getRow(ssn);
      assertNotNull( jobRow );
      assertEquals( 13, jobRow.getEmployerSize() );
      assertEquals( "new union member status", jobRow.getUnionMember() );
    }finally{
      employTable.reset();
      jobTable.reset();
    }
  }

  @Test
  public void testChangeUserResidence() {
    fail("Not yet implemented"); // TODO
  }

  @Test
  public void testFindIndustryStabilityValue() {
    int code = 9;
   
    IndustryDTO industry = service.findIndustryStabilityValue(code);
   
    assertNotNull(industry);
   
    assertNotNull(industry.getIndustry());
    assertTrue( ! industry.getIndustry().equals("") );
   
    assertEquals( code, industry.getIndustryCode() );
    assertTrue( industry.getStability() > 0 );
    assertTrue( industry.getStability() <= 100 );
  }

  @Test
  public void testFindOccupationStabilityValue() {
    int code = 1;
   
    OccupationDTO occupation = service.findOccupationStabilityValue(code);
   
    assertNotNull(occupation);
   
    assertNotNull(occupation.getOccupation());
    assertTrue( ! occupation.getOccupation().equals("") );
   
    assertEquals( code, occupation.getOccupationCode() );
    assertTrue( occupation.getStability() > 0 );
    assertTrue( occupation.getStability() <= 100 );
  }

  @Test
  public void testFindUsersByCode() {
    int industryCode = 9;
    int occupationCode = 1;
    List<UserDTO> users = service.findUsersByCode(industryCode, occupationCode);
    assertTrue( users.size() > 0 );
  }

  @Test
  public void testPurchasePolicy() {
    fail("Not yet implemented"); // TODO
  }

  @Test
  public final void testRetrieveUserBySearchCriteria() throws Exception {
    GenericRequest aRequest = new GenericRequest();
    SearchDTO aSearchObj = new SearchDTO();
    aSearchObj.setEstimatedIncome(100);
    aSearchObj.setScore(80);
    aSearchObj.setMaritalStatus("never married");
    aRequest.setSearchDTO(aSearchObj);
    GenericResponse aResponse = service.retrieveUserBySearchCriteria(aRequest);
    assertTrue(aResponse.getUserList().size() > 0);
  }
 
  @Test
  public final void testRetrieveUsersByEducation() throws Exception {
    GenericRequest aRequest = new GenericRequest();
    SearchDTO aSearchObj = new SearchDTO();
    aSearchObj.setEducation("ms");
    aRequest.setSearchDTO(aSearchObj);
    GenericResponse aResponse = service.retrieveUserBySearchCriteria(aRequest);
    assertTrue(aResponse.getUserList().size() > 0);
  }

 
  @Test
  public final void testRetrieveUserRecord() throws Exception{
    UserDTO userFound = service.retrieveUserRecord(new UserDTO(10));
   
    assertNotNull( userFound );
    assertEquals( 10, userFound.getSsn() );
    assertEquals( "GISH, CHAUNCEY", userFound.getName() );
  }
 

  @Test
  public void testRetrieveUserRecordbyZip() {
    fail("Not yet implemented"); // TODO
  }
 
  @Test
  public void testSendInvitation() throws Exception {
    InvitationTable table = db.getTable(InvitationTable.class);
    try{
      UserDTO agent = userFactory.findUserBySsn(11);
      UserDTO customer = userFactory.findUserBySsn(10);
      Date date = null;
     
      InvitationDTO invitation = new InvitationDTO(0, agent, customer, date);
      InsurencePolicyDTO policy = new InsurencePolicyDTO();
      policy.setDeductibles(100);
      policy.setPropertyName("My property");
      policy.setPropertyValue(10000);
      policy.setQuote(99);
      policy.setUserSSN(customer.getSsn());
     
      InvitationDTO sentInvitation = service.sendInvitation(invitation, policy);
     
      InvitationDTO dbInvitation = table.getNewest();
      assertNotNull( dbInvitation );
      assertEquals( customer.getSsn(), dbInvitation.getCustomer().getSsn() );
      assertEquals( dbInvitation.getId(), sentInvitation.getId() );
    } finally {
      table.clear();
    }
  }
 
  @Test
  public final void testSendInvitationNoPolicy() throws Exception {
    InvitationTable table = db.getTable(InvitationTable.class);
    try{
      UserDTO agent = userFactory.findUserBySsn(11);
      UserDTO customer = userFactory.findUserBySsn(10);
      Date date = null;
      InvitationDTO invitation = new InvitationDTO(0, agent, customer, date);
      InvitationDTO sentInvitation = service.sendInvitation(invitation, null);
     
      InvitationDTO dbInvitation = table.getNewest();
      assertNotNull( dbInvitation );
      assertEquals( customer.getSsn(), dbInvitation.getCustomer().getSsn() );
      assertEquals( dbInvitation.getId(), sentInvitation.getId() );
    } finally {
      table.clear();
    }
  }
 
  @Test
  public final void testUpdateUserInfo() throws Exception {
    try{
      UserDTO user = service.retrieveUserRecord(new UserDTO(10));
      // update user's detail
      user.setAge(101);
      // update user's education
      user.getEducation().setEducation("updated_edu");
           
      service.updateUserInfo(user);
     
      UserDTO newUser = service.retrieveUserRecord(new UserDTO(10));
      assertEquals(101, newUser.getAge());
      assertEquals("updated_edu", newUser.getEducation().getEducation());
    } finally {
      db.resetAllData();
    }
  }
 
  @Test
  public final void testUpdateUserInfoNoExtra() throws Exception {
    // update just userrecord
    UserDTO user = service.retrieveUserRecord(new UserDTO(10));
    assert( user.getEducation() != null );
    user.setEducation(null);
    assert( user.getInvestmentDetails() != null );
    user.setInvestmentDetails(null);
   
    service.updateUserInfo(user);
   
    UserDTO newUser = service.retrieveUserRecord(new UserDTO(10));
    assertNotNull(newUser.getEducation());
    assertNotNull(newUser.getInvestmentDetails());
  }
 
}
TOP

Related Classes of com.cin.test.CensusInsuranceServiceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.