Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.72 KB | None | 0 0
  1. /**
  2.  * $$Header$$
  3.  *
  4.  * ${project_name} - ${package_name}
  5.  *
  6.  * Copyright (C) ${year} Norvax, Inc.
  7.  * All Rights Reserved
  8.  *
  9.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Norvax, Inc.; the contents
  10.  * of this file may not be disclosed to third parties, copied or duplicated
  11.  * in any form, in whole or in part, without the prior written permission of
  12.  * Norvax, Inc. The copyright notice above does not evidence any actual or
  13.  * intended publication of such source code.
  14.  *
  15.  * Permission is hereby granted solely to the licensee for use of this source
  16.  * code in its unaltered state. This source code may not be modified by
  17.  * licensee except under direction of Norvax, Inc. Neither may this source
  18.  * code be given under any circumstances to non-licensees in any form,
  19.  * including source or binary. Modification of this source constitutes breach
  20.  * of contract, which voids any potential pending support responsibilities by
  21.  * Norvax, Inc. Divulging the exact or paraphrased contents of this source
  22.  * code to unlicensed parties either directly or indirectly constitutes
  23.  * violation of federal and international copyright and trade secret laws, and
  24.  * will be duly prosecuted to the fullest extent permitted under law.
  25.  *
  26.  * This software is provided by Norvax, Inc. ``as is'' and any express or
  27.  * implied warranties, including, but not limited to, the implied warranties
  28.  * of merchantability and fitness for a particular purpose are disclaimed. In
  29.  * no event shall the regents or contributors be liable for any direct,
  30.  * indirect, incidental, special, exemplary, or consequential damages
  31.  * (including, but not limited to, procurement of substitute goods or
  32.  * services; loss of use, data, or profits; or business interruption) however
  33.  * caused and on any theory of liability, whether in contract, strict
  34.  * liability, or tort (including negligence or otherwise) arising in any way
  35.  * out of the use of this software, even if advised of the possibility of such
  36.  * damage.
  37.  *
  38.  **/
  39.  
  40. package tests_PHX.FFM;
  41.  
  42. import infrastructure.BaseSharedFunctions;
  43. import infrastructure.BaseTest;
  44. import infrastructure.ExcelServer;
  45. import infrastructure.GlobalReporter;
  46.  
  47. import java.util.ArrayList;
  48. import java.util.HashMap;
  49. import java.util.List;
  50. import java.util.Map;
  51. import java.util.Random;
  52.  
  53. import org.json.JSONException;
  54. import org.json.JSONObject;
  55. import org.openqa.selenium.By;
  56.  
  57. import shared_Carriers.CarrierCustomer;
  58. import shared_Carriers.CarrierCustomerDataKey;
  59. import shared_Carriers.PopulateApplicants;
  60. import shared_PHX.PHXShared_AutomationTest;
  61. import shared_PHX.PHXShared_TextAndURLRepository;
  62.  
  63. /**
  64.  * This test will generate a random zip code + applicant ages, navigate to FFM, collect a subsidy from there. Then open MP calculator and calculate the subsidy there. Then it will compare both subsidies.
  65.  *
  66.  * @author IS
  67.  */
  68.  
  69. public class PHX_FFM_CompareMPAndFFMSubsidy
  70.     extends PHXShared_AutomationTest
  71. {
  72.  
  73.     private Integer _applicants;
  74.  
  75.     private final By _estTaxCreditPath = By.xpath("//div[contains(., 'Est. tax credit:')]/b[@class='dollars']");
  76.  
  77.     private String effectiveDate = /* PHXShared_DateUtils.calculateNextEffectiveDate(); */"01/01/2015";
  78.  
  79.     /**
  80.      * Mandatory main test execution override method.
  81.      */
  82.     @Override
  83.     public final void execute() {
  84.         startTestCase();
  85.  
  86.         // Plant FFM cookies
  87.         navigateToCertainPage(PHXShared_TextAndURLRepository.ffmCookieUrl, false);
  88.         BaseTest.sleepForSeconds(3);
  89.  
  90.         // Read excel files
  91.         List<ArrayList<String>> excelFileInfo = ExcelServer.readExcelIntoList("FFMRatingAreas.xls");
  92.         List<ArrayList<String>> returnedData = ExcelServer.readExcelIntoList("FFM_MP_Scenarios.xls");
  93.  
  94.         // Iterate through all scenarios
  95.         int zipCodeCounter = 0;
  96.         for (int i = 1; i < returnedData.get(0).size(); i++) {
  97.  
  98.             GlobalReporter.writeInformationTraceLine("---- Execute scenario #" + i);
  99.             MPAndFFM_ExcelWriter.addRow("Zip Code", "Rating Area", "County", setupCustomerAgesHeaders(), "Income", "MP Subsidy", " FFM Subsidy", "Error Message", true);
  100.  
  101.             while (zipCodeCounter < 3) {
  102.                 if (processZipCode(excelFileInfo, returnedData, "Scenario" + i)) {
  103.                     zipCodeCounter++;
  104.                 }
  105.             }
  106.             zipCodeCounter = 0;
  107.             MPAndFFM_ExcelWriter.reset();
  108.         }
  109.     }
  110.  
  111.     private Map<CarrierCustomerDataKey, String> setupCustomerAgesHeaders() {
  112.         HashMap<CarrierCustomerDataKey, String> map = new HashMap<CarrierCustomerDataKey, String>();
  113.  
  114.         map.put(CarrierCustomerDataKey.PRIMARY_AGE, "Primary Age");
  115.         map.put(CarrierCustomerDataKey.SPOUSE_AGE, "Spouse Age");
  116.         map.put(CarrierCustomerDataKey.DEPENDENT1_AGE, "Dep1 Age");
  117.         map.put(CarrierCustomerDataKey.DEPENDENT2_AGE, "Dep2 Age");
  118.         map.put(CarrierCustomerDataKey.DEPENDENT3_AGE, "Dep3 Age");
  119.         map.put(CarrierCustomerDataKey.DEPENDENT4_AGE, "Dep4 Age");
  120.         return map;
  121.     }
  122.  
  123.     private Map<CarrierCustomerDataKey, String> setupCustomerAges(CarrierCustomer customer, CarrierCustomerDataKey ... keys) {
  124.         HashMap<CarrierCustomerDataKey, String> map = new HashMap<CarrierCustomerDataKey, String>();
  125.  
  126.         for (CarrierCustomerDataKey key : keys) {
  127.             map.put(key, setUpCustomerRandomAge(customer, key));
  128.         }
  129.         return map;
  130.     }
  131.  
  132.     private boolean processZipCode(List<ArrayList<String>> excelFileInfo, List<ArrayList<String>> returnedData, String scenarioName) {
  133.         boolean increaseZipCodeCounter = true;
  134.         CarrierCustomer customer = new CarrierCustomer(returnedData, scenarioName);
  135.         // Prepare testing data
  136.         _applicants = 0;
  137.         Map<CarrierCustomerDataKey, String> customerAges = setupCustomerAges(customer, CarrierCustomerDataKey.PRIMARY_AGE, CarrierCustomerDataKey.SPOUSE_AGE, CarrierCustomerDataKey.DEPENDENT1_AGE, CarrierCustomerDataKey.DEPENDENT2_AGE, CarrierCustomerDataKey.DEPENDENT3_AGE, CarrierCustomerDataKey.DEPENDENT4_AGE);
  138.  
  139.         // Find a random zip code and county
  140.         PHX_FFM_SubsidyArea subsidyArea = PHX_FFM_SubsidyArea.factoryFromExcelFileInfo(excelFileInfo, new Random().nextInt((excelFileInfo.size() - 1) + 1) + 1);
  141.  
  142.         String income = calculateIncome();
  143.  
  144.         // Collect subsidy from FFM
  145.         String baseUrlToTest = String.format("https://imp1a.healthcare.gov/see-plans/en-US/%s/results/?zip=%s&income=%s&age=%s&smoker=&parent=&pregnant=&mec=&county=%s&division=1", subsidyArea.zipCode, subsidyArea.zipCode, income, customerAges.get(CarrierCustomerDataKey.PRIMARY_AGE), (subsidyArea.fipsCode + subsidyArea.countyCode));
  146.         String urlToTest = urlToTest(customerAges.values().toArray(new String[] {}), baseUrlToTest);
  147.         GlobalReporter.writeInformationTraceLine(urlToTest);
  148.         navigateToCertainPage(urlToTest, false);
  149.         if (isElementVisible(By.xpath("//a[contains(.,'Re-enter your ZIP Code')]"), 1)) {
  150.             GlobalReporter.writeWarningTraceLine("The zip code is not quoting");
  151.             increaseZipCodeCounter = false;
  152.         } else {
  153.             if (isElementVisible(By.xpath("//a[contains(@class, 'close-modal')]"), 2)) {
  154.                 clickElement(By.xpath("//a[contains(@class, 'close-modal')]"), "", 2);
  155.             }
  156.             int ffmSubsidy = 0;
  157.  
  158.             if (isElementVisible(_estTaxCreditPath, 1)) {
  159.                 ffmSubsidy = Integer.parseInt(getElementText(_estTaxCreditPath, "Subsidy for the applicant", 2).replace("$", "").replace(",", "").replace("/mo", "").replace("nth", ""));
  160.             }
  161.  
  162.             String mpZipCode = testMPCalculator(customer, subsidyArea.zipCode, subsidyArea.countyCode, income);
  163.  
  164.             BaseTest.sleepForSeconds(3);
  165.             Integer marketplaceSubsidy = getSubsidyValue();
  166.  
  167.             String errorMessage = "";
  168.             if (Math.abs(marketplaceSubsidy - ffmSubsidy) <= _applicants) {
  169.                 GlobalReporter.writeSuccessTraceLine("Subsidies almost or exactly match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy);
  170.             } else {
  171.                 GlobalReporter.writeWarningTraceLine("Subsidies do not match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy);
  172.                 errorMessage = "Subsidies do not match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy;
  173.             }
  174.             MPAndFFM_ExcelWriter.addRow(mpZipCode, (subsidyArea.state + ratingAreaCreation(subsidyArea.ratingArea)), subsidyArea.county, customerAges, income, String.valueOf(marketplaceSubsidy), String.valueOf(ffmSubsidy), errorMessage, false);
  175.             MPAndFFM_ExcelWriter.saveResults(scenarioName);
  176.         }
  177.         return increaseZipCodeCounter;
  178.     }
  179.  
  180.     private Integer getSubsidyValue() {
  181.         String json = getElementText(By.xpath("//body"), "", 5);
  182.         Integer marketplaceSubsidy = null;
  183.         try {
  184.             JSONObject jsonObj = new JSONObject(json);
  185.             String subsidy = jsonObj.get("amount").toString();
  186.             marketplaceSubsidy = Integer.parseInt(subsidy);
  187.         } catch (JSONException e) {
  188.             GlobalReporter.writeErrorTraceLine(e.getMessage(), e);
  189.         }
  190.         return marketplaceSubsidy;
  191.     }
  192.  
  193.     private String testMPCalculator(CarrierCustomer customer, String zipCode, String countyCode, String income) {
  194.         navigateToCertainPage("https://phx.uat.norvax.net/partner/dev/calculateSubsidy/", false);
  195.         String mpZipCode = enterZipCodeAndCounty(zipCode, countyCode);
  196.  
  197.         // Enter Primary Information
  198.         PopulateApplicants populateApplicants = new PopulateApplicants(this);
  199.         populateApplicants.enterPrimaryInformationForSubsidyCalculator(customer, effectiveDate);
  200.         populateApplicants.enterSpouseInformationForSubsidyCalculator(customer, effectiveDate);
  201.         populateApplicants.populateDependentsForSubsidy(1, customer, effectiveDate);
  202.         populateApplicants.populateDependentsForSubsidy(2, customer, effectiveDate);
  203.         populateApplicants.populateDependentsForSubsidy(3, customer, effectiveDate);
  204.         populateApplicants.populateDependentsForSubsidy(4, customer, effectiveDate);
  205.  
  206.         enterTextIntoElement(By.id("income"), income, "Enter income", 1);
  207.         enterTextIntoElement(By.id("household_size"), _applicants.toString(), "Enter household size", 1);
  208.         enterTextIntoElement(By.id("effective_date"), "20150101", "Eff date", 1);
  209.         clickElement(By.id("submit"), "Click Submit button");
  210.         return mpZipCode;
  211.     }
  212.  
  213.     /**
  214.      * Sets up random age for a customer.
  215.      *
  216.      * @param customer CarrierCustomer
  217.      * @param key CarrierCustomerDataKey
  218.      * @return generated age
  219.      */
  220.     public String setUpCustomerRandomAge(CarrierCustomer customer, CarrierCustomerDataKey key) {
  221.         Integer customerRandomAge = null;
  222.         Random rand = new Random();
  223.         if (!customer.getValueForKey(key).equals("")) {
  224.             _applicants = _applicants + 1;
  225.             String customerAgeRange = customer.getValueForKey(key);
  226.             String customerAgeMin = customerAgeRange.replaceAll("-.+$", "");
  227.             String customerAgeMax = customerAgeRange.replaceAll("^.+-", "");
  228.             customerRandomAge = rand.nextInt((Integer.parseInt(customerAgeMax) - Integer.parseInt(customerAgeMin)) + 1) + Integer.parseInt(customerAgeMin);
  229.             customer.setValueForKey(key, customerRandomAge.toString());
  230.         }
  231.         return customerRandomAge == null ? null : String.valueOf(customerRandomAge);
  232.     }
  233.  
  234.     private String ratingAreaCreation(String ratingArea) {
  235.         return "S" + org.apache.commons.lang.StringUtils.leftPad(ratingArea, 3, '0');
  236.     }
  237.  
  238.     private String calculateIncome() {
  239.         Integer baseIncome = 20000;
  240.         // Integer additionalPerMember = 8000;
  241.         // Integer income = _applicants.equals(1) ? baseIncome : (baseIncome + ((_applicants - 1) * additionalPerMember));
  242.         Integer income = _applicants.equals(1) ? baseIncome : 55000;
  243.         return income.toString();
  244.     }
  245.  
  246.     private String urlToTest(String[] allAges, String baseUrl) {
  247.         String urlToTest = baseUrl;
  248.         for (int i = 1; i < allAges.length; i++) {
  249.             if (allAges[i] != null) {
  250.                 urlToTest = urlToTest + "&age=" + allAges[i];
  251.             }
  252.         }
  253.         return urlToTest;
  254.     }
  255.  
  256.     private String enterZipCodeAndCounty(String zipCode, String countyCode) {
  257.         isElementVisible(By.id("zipcode"));
  258.         String zipCodeFinal = zipCode.length() == 4 ? "0" + zipCode : zipCode;
  259.         BaseSharedFunctions.clearInputEnterText(this, By.id("zipcode"), zipCodeFinal, "Zip Code");
  260.         BaseSharedFunctions.clearInputEnterText(this, By.id("county"), countyCode, "County Code");
  261.  
  262.         return zipCodeFinal;
  263.     }
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement