Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.03 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", "RANDOM");
  92.         List<ArrayList<String>> excelFileInfo2 = ExcelServer.readExcelIntoList("FFMRatingAreas.xls", "CONSTANT");
  93.         List<ArrayList<String>> returnedData = ExcelServer.readExcelIntoList("FFM_MP_Scenarios.xls");
  94.  
  95.         // Iterate through all scenarios
  96.         int zipCodeCounter = 0;
  97.         for (int i = 1; i < returnedData.get(0).size(); i++) {
  98.  
  99.             GlobalReporter.writeInformationTraceLine("---- Execute scenario #" + i);
  100.             MPAndFFM_ExcelWriter.addRow("Zip Code", "Rating Area", "County", setupCustomerAgesHeaders(), "Income", "MP Subsidy", " FFM Subsidy", "Error Message", true);
  101.  
  102.             while (zipCodeCounter < 6) {
  103.                 if (processZipCode(excelFileInfo, excelFileInfo2, returnedData, "Scenario" + i, zipCodeCounter)) {
  104.                     zipCodeCounter++;
  105.                 }
  106.             }
  107.             zipCodeCounter = 0;
  108.             MPAndFFM_ExcelWriter.reset();
  109.         }
  110.     }
  111.  
  112.     private Map<CarrierCustomerDataKey, String> setupCustomerAgesHeaders() {
  113.         HashMap<CarrierCustomerDataKey, String> map = new HashMap<CarrierCustomerDataKey, String>();
  114.  
  115.         map.put(CarrierCustomerDataKey.PRIMARY_AGE, "Primary Age");
  116.         map.put(CarrierCustomerDataKey.SPOUSE_AGE, "Spouse Age");
  117.         map.put(CarrierCustomerDataKey.DEPENDENT1_AGE, "Dep1 Age");
  118.         map.put(CarrierCustomerDataKey.DEPENDENT2_AGE, "Dep2 Age");
  119.         map.put(CarrierCustomerDataKey.DEPENDENT3_AGE, "Dep3 Age");
  120.         map.put(CarrierCustomerDataKey.DEPENDENT4_AGE, "Dep4 Age");
  121.         return map;
  122.     }
  123.  
  124.     private Map<CarrierCustomerDataKey, String> setupCustomerAges(CarrierCustomer customer, CarrierCustomerDataKey ... keys) {
  125.         HashMap<CarrierCustomerDataKey, String> map = new HashMap<CarrierCustomerDataKey, String>();
  126.  
  127.         for (CarrierCustomerDataKey key : keys) {
  128.             map.put(key, setUpCustomerRandomAge(customer, key));
  129.         }
  130.         return map;
  131.     }
  132.  
  133.     private boolean processZipCode(List<ArrayList<String>> excelFileInfo, List<ArrayList<String>> excelFileInfo2, List<ArrayList<String>> returnedData, String scenarioName, int zipCodeCounter) {
  134.  
  135.         boolean increaseZipCodeCounter = true;
  136.  
  137.         CarrierCustomer customer = new CarrierCustomer(returnedData, scenarioName);
  138.         // Prepare testing data
  139.         _applicants = 0;
  140.         Map<CarrierCustomerDataKey, String> customerAges = setupCustomerAges(customer, CarrierCustomerDataKey.PRIMARY_AGE, CarrierCustomerDataKey.SPOUSE_AGE, CarrierCustomerDataKey.DEPENDENT1_AGE, CarrierCustomerDataKey.DEPENDENT2_AGE, CarrierCustomerDataKey.DEPENDENT3_AGE, CarrierCustomerDataKey.DEPENDENT4_AGE);
  141.         PHX_FFM_SubsidyArea subsidyArea = (zipCodeCounter < 3) ? PHX_FFM_SubsidyArea.factoryFromExcelFileInfo(excelFileInfo, new Random().nextInt((excelFileInfo.size() - 1) + 1) + 1) : PHX_FFM_SubsidyArea.factoryFromExcelFileInfo(excelFileInfo2, zipCodeCounter - 2);// the first zipCodeCounter in
  142.  
  143.         String income = calculateIncome();
  144.  
  145.         // Collect subsidy from FFM
  146.         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));
  147.         String urlToTest = urlToTest(customerAges.values().toArray(new String[] {}), baseUrlToTest);
  148.         GlobalReporter.writeInformationTraceLine(urlToTest);
  149.         navigateToCertainPage(urlToTest, false);
  150.         if (isElementVisible(By.xpath("//a[contains(.,'Re-enter your ZIP Code')]"), 1)) {
  151.             GlobalReporter.writeWarningTraceLine("The zip code is not quoting");
  152.             increaseZipCodeCounter = false;
  153.         } else {
  154.             if (isElementVisible(By.xpath("//a[contains(@class, 'close-modal')]"), 2)) {
  155.                 clickElement(By.xpath("//a[contains(@class, 'close-modal')]"), "", 2);
  156.             }
  157.             int ffmSubsidy = 0;
  158.  
  159.             if (isElementVisible(_estTaxCreditPath, 1)) {
  160.                 ffmSubsidy = Integer.parseInt(getElementText(_estTaxCreditPath, "Subsidy for the applicant", 2).replace("$", "").replace(",", "").replace("/mo", "").replace("nth", ""));
  161.             }
  162.  
  163.             String mpZipCode = testMPCalculator(customer, subsidyArea.zipCode, subsidyArea.countyCode, income);
  164.  
  165.             BaseTest.sleepForSeconds(3);
  166.             Integer marketplaceSubsidy = getSubsidyValue();
  167.  
  168.             String errorMessage = "";
  169.             if (Math.abs(marketplaceSubsidy - ffmSubsidy) <= _applicants) {
  170.                 GlobalReporter.writeSuccessTraceLine("Subsidies almost or exactly match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy);
  171.             } else {
  172.                 GlobalReporter.writeWarningTraceLine("Subsidies do not match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy);
  173.                 errorMessage = "Subsidies do not match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy;
  174.             }
  175.             MPAndFFM_ExcelWriter.addRow(mpZipCode, (subsidyArea.state + ratingAreaCreation(subsidyArea.ratingArea)), subsidyArea.county, customerAges, income, String.valueOf(marketplaceSubsidy), String.valueOf(ffmSubsidy), errorMessage, false);
  176.             MPAndFFM_ExcelWriter.saveResults(scenarioName);
  177.         }
  178.         return increaseZipCodeCounter;
  179.     }
  180.  
  181.     private Integer getSubsidyValue() {
  182.         String json = getElementText(By.xpath("//body"), "", 5);
  183.         Integer marketplaceSubsidy = null;
  184.         try {
  185.             JSONObject jsonObj = new JSONObject(json);
  186.             String subsidy = jsonObj.get("amount").toString();
  187.             marketplaceSubsidy = Integer.parseInt(subsidy);
  188.         } catch (JSONException e) {
  189.             GlobalReporter.writeErrorTraceLine(e.getMessage(), e);
  190.         }
  191.         return marketplaceSubsidy;
  192.     }
  193.  
  194.     private String testMPCalculator(CarrierCustomer customer, String zipCode, String countyCode, String income) {
  195.         navigateToCertainPage("https://phx.uat.norvax.net/partner/dev/calculateSubsidy/", false);
  196.         String mpZipCode = enterZipCodeAndCounty(zipCode, countyCode);
  197.  
  198.         // Enter Primary Information
  199.         PopulateApplicants populateApplicants = new PopulateApplicants(this);
  200.         populateApplicants.enterPrimaryInformationForSubsidyCalculator(customer, effectiveDate);
  201.         populateApplicants.enterSpouseInformationForSubsidyCalculator(customer, effectiveDate);
  202.         populateApplicants.populateDependentsForSubsidy(1, customer, effectiveDate);
  203.         populateApplicants.populateDependentsForSubsidy(2, customer, effectiveDate);
  204.         populateApplicants.populateDependentsForSubsidy(3, customer, effectiveDate);
  205.         populateApplicants.populateDependentsForSubsidy(4, customer, effectiveDate);
  206.  
  207.         enterTextIntoElement(By.id("income"), income, "Enter income", 1);
  208.         enterTextIntoElement(By.id("household_size"), _applicants.toString(), "Enter household size", 1);
  209.         enterTextIntoElement(By.id("effective_date"), "20150101", "Eff date", 1);
  210.         clickElement(By.id("submit"), "Click Submit button");
  211.         return mpZipCode;
  212.     }
  213.  
  214.     /**
  215.      * Sets up random age for a customer.
  216.      *
  217.      * @param customer CarrierCustomer
  218.      * @param key CarrierCustomerDataKey
  219.      * @return generated age
  220.      */
  221.     public String setUpCustomerRandomAge(CarrierCustomer customer, CarrierCustomerDataKey key) {
  222.         Integer customerRandomAge = null;
  223.         Random rand = new Random();
  224.         if (!customer.getValueForKey(key).equals("")) {
  225.             _applicants = _applicants + 1;
  226.             String customerAgeRange = customer.getValueForKey(key);
  227.             String customerAgeMin = customerAgeRange.replaceAll("-.+$", "");
  228.             String customerAgeMax = customerAgeRange.replaceAll("^.+-", "");
  229.             customerRandomAge = rand.nextInt((Integer.parseInt(customerAgeMax) - Integer.parseInt(customerAgeMin)) + 1) + Integer.parseInt(customerAgeMin);
  230.             customer.setValueForKey(key, customerRandomAge.toString());
  231.         }
  232.         return customerRandomAge == null ? null : String.valueOf(customerRandomAge);
  233.     }
  234.  
  235.     private String ratingAreaCreation(String ratingArea) {
  236.         return "S" + org.apache.commons.lang.StringUtils.leftPad(ratingArea, 3, '0');
  237.     }
  238.  
  239.     private String calculateIncome() {
  240.         Integer baseIncome = 20000;
  241.         // Integer additionalPerMember = 8000;
  242.         // Integer income = _applicants.equals(1) ? baseIncome : (baseIncome + ((_applicants - 1) * additionalPerMember));
  243.         Integer income = _applicants.equals(1) ? baseIncome : 55000;
  244.         return income.toString();
  245.     }
  246.  
  247.     private String urlToTest(String[] allAges, String baseUrl) {
  248.         String urlToTest = baseUrl;
  249.         for (int i = 1; i < allAges.length; i++) {
  250.             if (allAges[i] != null) {
  251.                 urlToTest = urlToTest + "&age=" + allAges[i];
  252.             }
  253.         }
  254.         return urlToTest;
  255.     }
  256.  
  257.     private String enterZipCodeAndCounty(String zipCode, String countyCode) {
  258.         isElementVisible(By.id("zipcode"));
  259.         String zipCodeFinal = zipCode.length() == 4 ? "0" + zipCode : zipCode;
  260.         BaseSharedFunctions.clearInputEnterText(this, By.id("zipcode"), zipCodeFinal, "Zip Code");
  261.         BaseSharedFunctions.clearInputEnterText(this, By.id("county"), countyCode, "County Code");
  262.  
  263.         return zipCodeFinal;
  264.     }
  265.  
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement