Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * $$Header$$
- *
- * ${project_name} - ${package_name}
- *
- * Copyright (C) ${year} Norvax, Inc.
- * All Rights Reserved
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Norvax, Inc.; the contents
- * of this file may not be disclosed to third parties, copied or duplicated
- * in any form, in whole or in part, without the prior written permission of
- * Norvax, Inc. The copyright notice above does not evidence any actual or
- * intended publication of such source code.
- *
- * Permission is hereby granted solely to the licensee for use of this source
- * code in its unaltered state. This source code may not be modified by
- * licensee except under direction of Norvax, Inc. Neither may this source
- * code be given under any circumstances to non-licensees in any form,
- * including source or binary. Modification of this source constitutes breach
- * of contract, which voids any potential pending support responsibilities by
- * Norvax, Inc. Divulging the exact or paraphrased contents of this source
- * code to unlicensed parties either directly or indirectly constitutes
- * violation of federal and international copyright and trade secret laws, and
- * will be duly prosecuted to the fullest extent permitted under law.
- *
- * This software is provided by Norvax, Inc. ``as is'' and any express or
- * implied warranties, including, but not limited to, the implied warranties
- * of merchantability and fitness for a particular purpose are disclaimed. In
- * no event shall the regents or contributors be liable for any direct,
- * indirect, incidental, special, exemplary, or consequential damages
- * (including, but not limited to, procurement of substitute goods or
- * services; loss of use, data, or profits; or business interruption) however
- * caused and on any theory of liability, whether in contract, strict
- * liability, or tort (including negligence or otherwise) arising in any way
- * out of the use of this software, even if advised of the possibility of such
- * damage.
- *
- **/
- package tests_PHX.FFM;
- import infrastructure.BaseSharedFunctions;
- import infrastructure.BaseTest;
- import infrastructure.ExcelServer;
- import infrastructure.GlobalReporter;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- import org.json.JSONException;
- import org.json.JSONObject;
- import org.openqa.selenium.By;
- import shared_Carriers.CarrierCustomer;
- import shared_Carriers.CarrierCustomerDataKey;
- import shared_Carriers.PopulateApplicants;
- import shared_PHX.PHXShared_AutomationTest;
- import shared_PHX.PHXShared_TextAndURLRepository;
- /**
- * 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.
- *
- * @author IS
- */
- public class PHX_FFM_CompareMPAndFFMSubsidy
- extends PHXShared_AutomationTest
- {
- private Integer _applicants;
- private final By _estTaxCreditPath = By.xpath("//div[contains(., 'Est. tax credit:')]/b[@class='dollars']");
- private String effectiveDate = /* PHXShared_DateUtils.calculateNextEffectiveDate(); */"01/01/2015";
- /**
- * Mandatory main test execution override method.
- */
- @Override
- public final void execute() {
- startTestCase();
- // Plant FFM cookies
- navigateToCertainPage(PHXShared_TextAndURLRepository.ffmCookieUrl, false);
- BaseTest.sleepForSeconds(3);
- // Read excel files
- List<ArrayList<String>> excelFileInfo = ExcelServer.readExcelIntoList("FFMRatingAreas.xls", "RANDOM");
- List<ArrayList<String>> excelFileInfo2 = ExcelServer.readExcelIntoList("FFMRatingAreas.xls", "CONSTANT");
- List<ArrayList<String>> returnedData = ExcelServer.readExcelIntoList("FFM_MP_Scenarios.xls");
- // Iterate through all scenarios
- int zipCodeCounter = 0;
- for (int i = 1; i < returnedData.get(0).size(); i++) {
- GlobalReporter.writeInformationTraceLine("---- Execute scenario #" + i);
- MPAndFFM_ExcelWriter.addRow("Zip Code", "Rating Area", "County", setupCustomerAgesHeaders(), "Income", "MP Subsidy", " FFM Subsidy", "Error Message", true);
- while (zipCodeCounter < 6) {
- if (processZipCode(excelFileInfo, excelFileInfo2, returnedData, "Scenario" + i, zipCodeCounter)) {
- zipCodeCounter++;
- }
- }
- zipCodeCounter = 0;
- MPAndFFM_ExcelWriter.reset();
- }
- }
- private Map<CarrierCustomerDataKey, String> setupCustomerAgesHeaders() {
- HashMap<CarrierCustomerDataKey, String> map = new HashMap<CarrierCustomerDataKey, String>();
- map.put(CarrierCustomerDataKey.PRIMARY_AGE, "Primary Age");
- map.put(CarrierCustomerDataKey.SPOUSE_AGE, "Spouse Age");
- map.put(CarrierCustomerDataKey.DEPENDENT1_AGE, "Dep1 Age");
- map.put(CarrierCustomerDataKey.DEPENDENT2_AGE, "Dep2 Age");
- map.put(CarrierCustomerDataKey.DEPENDENT3_AGE, "Dep3 Age");
- map.put(CarrierCustomerDataKey.DEPENDENT4_AGE, "Dep4 Age");
- return map;
- }
- private Map<CarrierCustomerDataKey, String> setupCustomerAges(CarrierCustomer customer, CarrierCustomerDataKey ... keys) {
- HashMap<CarrierCustomerDataKey, String> map = new HashMap<CarrierCustomerDataKey, String>();
- for (CarrierCustomerDataKey key : keys) {
- map.put(key, setUpCustomerRandomAge(customer, key));
- }
- return map;
- }
- private boolean processZipCode(List<ArrayList<String>> excelFileInfo, List<ArrayList<String>> excelFileInfo2, List<ArrayList<String>> returnedData, String scenarioName, int zipCodeCounter) {
- boolean increaseZipCodeCounter = true;
- CarrierCustomer customer = new CarrierCustomer(returnedData, scenarioName);
- // Prepare testing data
- _applicants = 0;
- Map<CarrierCustomerDataKey, String> customerAges = setupCustomerAges(customer, CarrierCustomerDataKey.PRIMARY_AGE, CarrierCustomerDataKey.SPOUSE_AGE, CarrierCustomerDataKey.DEPENDENT1_AGE, CarrierCustomerDataKey.DEPENDENT2_AGE, CarrierCustomerDataKey.DEPENDENT3_AGE, CarrierCustomerDataKey.DEPENDENT4_AGE);
- 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
- String income = calculateIncome();
- // Collect subsidy from FFM
- 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));
- String urlToTest = urlToTest(customerAges.values().toArray(new String[] {}), baseUrlToTest);
- GlobalReporter.writeInformationTraceLine(urlToTest);
- navigateToCertainPage(urlToTest, false);
- if (isElementVisible(By.xpath("//a[contains(.,'Re-enter your ZIP Code')]"), 1)) {
- GlobalReporter.writeWarningTraceLine("The zip code is not quoting");
- increaseZipCodeCounter = false;
- } else {
- if (isElementVisible(By.xpath("//a[contains(@class, 'close-modal')]"), 2)) {
- clickElement(By.xpath("//a[contains(@class, 'close-modal')]"), "", 2);
- }
- int ffmSubsidy = 0;
- if (isElementVisible(_estTaxCreditPath, 1)) {
- ffmSubsidy = Integer.parseInt(getElementText(_estTaxCreditPath, "Subsidy for the applicant", 2).replace("$", "").replace(",", "").replace("/mo", "").replace("nth", ""));
- }
- String mpZipCode = testMPCalculator(customer, subsidyArea.zipCode, subsidyArea.countyCode, income);
- BaseTest.sleepForSeconds(3);
- Integer marketplaceSubsidy = getSubsidyValue();
- String errorMessage = "";
- if (Math.abs(marketplaceSubsidy - ffmSubsidy) <= _applicants) {
- GlobalReporter.writeSuccessTraceLine("Subsidies almost or exactly match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy);
- } else {
- GlobalReporter.writeWarningTraceLine("Subsidies do not match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy);
- errorMessage = "Subsidies do not match! MP Subsidy: " + marketplaceSubsidy + " and FFM Subsidy: " + ffmSubsidy;
- }
- MPAndFFM_ExcelWriter.addRow(mpZipCode, (subsidyArea.state + ratingAreaCreation(subsidyArea.ratingArea)), subsidyArea.county, customerAges, income, String.valueOf(marketplaceSubsidy), String.valueOf(ffmSubsidy), errorMessage, false);
- MPAndFFM_ExcelWriter.saveResults(scenarioName);
- }
- return increaseZipCodeCounter;
- }
- private Integer getSubsidyValue() {
- String json = getElementText(By.xpath("//body"), "", 5);
- Integer marketplaceSubsidy = null;
- try {
- JSONObject jsonObj = new JSONObject(json);
- String subsidy = jsonObj.get("amount").toString();
- marketplaceSubsidy = Integer.parseInt(subsidy);
- } catch (JSONException e) {
- GlobalReporter.writeErrorTraceLine(e.getMessage(), e);
- }
- return marketplaceSubsidy;
- }
- private String testMPCalculator(CarrierCustomer customer, String zipCode, String countyCode, String income) {
- navigateToCertainPage("https://phx.uat.norvax.net/partner/dev/calculateSubsidy/", false);
- String mpZipCode = enterZipCodeAndCounty(zipCode, countyCode);
- // Enter Primary Information
- PopulateApplicants populateApplicants = new PopulateApplicants(this);
- populateApplicants.enterPrimaryInformationForSubsidyCalculator(customer, effectiveDate);
- populateApplicants.enterSpouseInformationForSubsidyCalculator(customer, effectiveDate);
- populateApplicants.populateDependentsForSubsidy(1, customer, effectiveDate);
- populateApplicants.populateDependentsForSubsidy(2, customer, effectiveDate);
- populateApplicants.populateDependentsForSubsidy(3, customer, effectiveDate);
- populateApplicants.populateDependentsForSubsidy(4, customer, effectiveDate);
- enterTextIntoElement(By.id("income"), income, "Enter income", 1);
- enterTextIntoElement(By.id("household_size"), _applicants.toString(), "Enter household size", 1);
- enterTextIntoElement(By.id("effective_date"), "20150101", "Eff date", 1);
- clickElement(By.id("submit"), "Click Submit button");
- return mpZipCode;
- }
- /**
- * Sets up random age for a customer.
- *
- * @param customer CarrierCustomer
- * @param key CarrierCustomerDataKey
- * @return generated age
- */
- public String setUpCustomerRandomAge(CarrierCustomer customer, CarrierCustomerDataKey key) {
- Integer customerRandomAge = null;
- Random rand = new Random();
- if (!customer.getValueForKey(key).equals("")) {
- _applicants = _applicants + 1;
- String customerAgeRange = customer.getValueForKey(key);
- String customerAgeMin = customerAgeRange.replaceAll("-.+$", "");
- String customerAgeMax = customerAgeRange.replaceAll("^.+-", "");
- customerRandomAge = rand.nextInt((Integer.parseInt(customerAgeMax) - Integer.parseInt(customerAgeMin)) + 1) + Integer.parseInt(customerAgeMin);
- customer.setValueForKey(key, customerRandomAge.toString());
- }
- return customerRandomAge == null ? null : String.valueOf(customerRandomAge);
- }
- private String ratingAreaCreation(String ratingArea) {
- return "S" + org.apache.commons.lang.StringUtils.leftPad(ratingArea, 3, '0');
- }
- private String calculateIncome() {
- Integer baseIncome = 20000;
- // Integer additionalPerMember = 8000;
- // Integer income = _applicants.equals(1) ? baseIncome : (baseIncome + ((_applicants - 1) * additionalPerMember));
- Integer income = _applicants.equals(1) ? baseIncome : 55000;
- return income.toString();
- }
- private String urlToTest(String[] allAges, String baseUrl) {
- String urlToTest = baseUrl;
- for (int i = 1; i < allAges.length; i++) {
- if (allAges[i] != null) {
- urlToTest = urlToTest + "&age=" + allAges[i];
- }
- }
- return urlToTest;
- }
- private String enterZipCodeAndCounty(String zipCode, String countyCode) {
- isElementVisible(By.id("zipcode"));
- String zipCodeFinal = zipCode.length() == 4 ? "0" + zipCode : zipCode;
- BaseSharedFunctions.clearInputEnterText(this, By.id("zipcode"), zipCodeFinal, "Zip Code");
- BaseSharedFunctions.clearInputEnterText(this, By.id("county"), countyCode, "County Code");
- return zipCodeFinal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement