List of usage examples for org.json.simple JSONObject values
Collection<V> values();
From source file:com.ccstats.crypto.io.JSONEncryptedStatement.java
/** * Reads an encrypted .json statement file and attempts to decrypt it. Once decrypted, the transactions can be * pooled and returned as a joint statement. * * @param absolutePath The absolute path to the encrypted statement, including the file name. * @param password The password sequence to be used while attempting the decryption. * * @return A statement object containing all the discovered transactions as a pool. *//*from w w w. j ava2s . c o m*/ public Statement read(String absolutePath, String password) throws IOException, ParseException, BadPaddingException { TransactionPool transactions = new TransactionPool(); JSONParser parser = new JSONParser(); JSONObject main = (JSONObject) parser.parse(new FileReader(absolutePath)); JSONObject encryptedTransactions = (JSONObject) main.get("transactions"); worker.setKeyLength(Integer.valueOf((String) main.get("aes-key-length"))); try { JSONObject current; String date, description, amount, authorized; for (Object o : encryptedTransactions.values()) { current = (JSONObject) o; date = new String(worker.decrypt(password, (String) current.get("date"))); description = new String(worker.decrypt(password, (String) current.get("description"))); amount = new String(worker.decrypt(password, (String) current.get("amount"))); authorized = new String(worker.decrypt(password, (String) current.get("authorized"))); transactions.add(new Transaction(description, LocalDate.parse(date), Double.valueOf(amount), Boolean.valueOf(authorized))); } } catch (InvalidKeySpecException | NoSuchAlgorithmException | DecoderException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | NoSuchPaddingException e) { e.printStackTrace(); } return new Statement(transactions); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-251 Monthly runtime hours for provisioned user. * @param username the username//from www. j a va 2 s. co m * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = "provisioned", dataProviderClass = ApiDataProvider.class, priority = 10) public void monthlyRuntimeHoursForProvisionedUser(final String username, final String password, final String thermostatId) { setLogString("Verify runtime savings for provisioned thermostat.", true); final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); Assert.assertTrue(response.getStatus() == 200, "Error status: " + response.getStatus()); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); Assert.assertTrue(runtimes.length == 0, "Thermostat runtime savings exists for provisioned user."); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-197 Test_fetching_ thermostat_ runtime savings_ data_using_valid_thermostat id. * @param username the username/*from w ww .ja va 2s .co m*/ * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = HVAC_SYSTEMS, dataProviderClass = ApiDataProvider.class, priority = 1) public void thermostatRuntimeSavingsForvalidThermostatID(final String username, final String password, final String thermostatId) { setLogString("Verify runtime savings exists for valid thermostat.", true); final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); Assert.assertTrue(response.getStatus() == 200, "Error status: " + response.getStatus()); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); Assert.assertTrue(runtimes.length > 0, "Thermostat runtime savings not exists for given user account."); setLogString("Runtime savings exists for given thermostat.", true); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-226 Verify tstat runtimes for heat only user. * @param username the username//from w ww . j a v a2 s . c o m * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = "heatonlyuser", dataProviderClass = ApiDataProvider.class, priority = 12) public void verifyTstatRuntimesForHeatOnlyUser(final String username, final String password, final String thermostatId) { final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); setLogString("Verify only heat runtime_hours exists for given thermostat.", true); for (final Object runtime : runtimes) { final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); Assert.assertTrue(jsonRuntimeCool != null, "Cool run time hours not exists."); Assert.assertTrue(jsonRuntimeHeat != null, "Heat run time hours not exists."); } setLogString("Verified heat runtime_hours alone exists for given thermostat.", true); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-226 Verify tstat runtimes for cool only user. * @param username the username/*from ww w. j a v a2 s . c om*/ * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = "coolonlyuser", dataProviderClass = ApiDataProvider.class, priority = 13) public void verifyTstatRuntimesForCoolOnlyUser(final String username, final String password, final String thermostatId) { final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); setLogString("Verify cool runtime_hours alone exists for given thermostat.", true); for (final Object runtime : runtimes) { final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); Assert.assertTrue(jsonRuntimeCool != null, "Cool run time hours not exists."); Assert.assertTrue(jsonRuntimeHeat != null, "Heat run time hours not exists."); } setLogString("Verified cool runtime_hours alone exists for given thermostat.", true); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-226 Verify tstat runtimes for heat and cool user. * @param username the username/* ww w .jav a 2 s . co m*/ * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = HVAC_SYSTEMS, dataProviderClass = ApiDataProvider.class, priority = 14) public void verifyTstatRuntimesForHeatAndCoolUser(final String username, final String password, final String thermostatId) { final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); setLogString("Verify heat and cool runtime_hours exists for given thermostat.", true); for (final Object runtime : runtimes) { final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); Assert.assertTrue(jsonRuntimeCool != null, "Cool run time hours not exists."); Assert.assertTrue(jsonRuntimeHeat != null, "Heat run time hours not exists."); } setLogString("Verified heat and cool runtime_hours for given thermostat.", true); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-250 Negative runtime savings thermostat. * @param username the username/*from w ww . ja v a2 s . c om*/ * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = "negativeruntimethermostat", dataProviderClass = ApiDataProvider.class, priority = 6) public void negativeRuntimeSavings(final String username, final String password, final String thermostatId) { final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); setLogString("Verify negative runtime hours for given thermostat.", true); for (final Object runtime : runtimes) { final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); final float coolRuntimeHrsActual = Float.valueOf(jsonRuntimeCool.get("runtime_hours_saved").toString()); final float heatRuntimeHrsActual = Float.valueOf(jsonRuntimeHeat.get("runtime_hours_saved").toString()); setLogString("coolRuntimeHrsActual: " + coolRuntimeHrsActual, true); Assert.assertTrue(coolRuntimeHrsActual < 0, "Cool run time hours actual is not negative."); setLogString("heatRuntimeHrsActual: " + heatRuntimeHrsActual, true); Assert.assertTrue(heatRuntimeHrsActual < 0, "Heat run time hours actual is not negative."); } setLogString("Verified negative runtime hours for given thermostat.", true); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-203 Monthly runtime hours actual not exceeds max month hours. * @param username the username//w w w. j a va2s. c om * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = HVAC_SYSTEMS, dataProviderClass = ApiDataProvider.class, priority = 7) public void monthlyRuntimeHoursActualNotExceedsMaxMonthHours(final String username, final String password, final String thermostatId) { final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); for (final Object runtime : runtimes) { setLogString("Verify that runtime_hours_actual cannot exceed 31 (days) * 24 ( hours)", true); final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); final float coolRuntimeHrsActual = Float.valueOf(jsonRuntimeCool.get(RUNTIME_HRS_ACTUAL).toString()); final float heatRuntimeHrsActual = Float.valueOf(jsonRuntimeHeat.get(RUNTIME_HRS_ACTUAL).toString()); setLogString("coolRuntimeHrsActual: " + coolRuntimeHrsActual, true); Assert.assertTrue(coolRuntimeHrsActual < 744, "Cool run time hours actual is greater than maximum month hours"); setLogString("heatRuntimeHrsActual: " + heatRuntimeHrsActual, true); Assert.assertTrue(heatRuntimeHrsActual < 744, "Heat run time hours actual is greater than maximum month hours"); } }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-248 No data for runtime savings. * @param username the username//from w w w . j a v a 2s. c om * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = "nosavings", dataProviderClass = ApiDataProvider.class, priority = 11) public void noDataForRuntimeSavings(final String username, final String password, final String thermostatId) { setLogString("Verify runtime savings API for user with no savings data.", true); final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); Assert.assertTrue(response.getStatus() == 200, "Error status: " + response.getStatus()); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); for (final Object runtime : runtimes) { final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); final String coolRuntimeHrsActual = jsonRuntimeCool.get(RUNTIME_HRS_ACTUAL).toString(); final String heatRuntimeHrsActual = jsonRuntimeHeat.get(RUNTIME_HRS_ACTUAL).toString(); setLogString("coolRuntimeHrsActual: " + coolRuntimeHrsActual, true, CustomLogLevel.HIGH); Assert.assertTrue(coolRuntimeHrsActual.contains("0.0"), "cool runtime savings data available for user with no savings."); setLogString("heatRuntimeHrsActual: " + heatRuntimeHrsActual, true, CustomLogLevel.HIGH); Assert.assertTrue(heatRuntimeHrsActual.contains("0.0"), "Heat runtime savings data available for user with no savings."); } setLogString("Verified runtime savings API for user with no savings data.", true, CustomLogLevel.MEDIUM); }
From source file:com.ecofactor.qa.automation.consumerapi.ThermostatRuntimeSavings_Test.java
/** * APPS-208 Monthly runtime hours only with2 decimal precission. * @param username the username/*from www . j ava2 s.com*/ * @param password the password * @param thermostatId the thermostat id */ @Test(groups = { Groups.SANITY1, Groups.BROWSER }, dataProvider = "savingsprecision", dataProviderClass = ApiDataProvider.class, priority = 8) public void monthlyRuntimeHoursOnlyWith2DecimalPrecission(final String username, final String password, final String thermostatId) { setLogString("Verify runtime savings have two decimal point precision.", true); final Response response = consumerApiURL.getThermostatRuntimeSavings(thermostatId, securityCookie); Assert.assertTrue(response.getStatus() == 200, "Error status: " + response.getStatus()); setLogString("Response :'" + response + "'", true); final String content = response.readEntity(String.class); Assert.assertTrue(response.getStatus() == 200, "Error status: " + response.getStatus()); setLogString(JSON_RESPONSE, true, CustomLogLevel.MEDIUM); setLogString(content, true, CustomLogLevel.MEDIUM); final JSONObject jsonObject = JsonUtil.parseObject(content); final JSONObject mesgs = (JSONObject) jsonObject.get(MONTHS); final Object[] runtimes = mesgs.values().toArray(); setLogString("Verify that runtime_hours_actual have 2 decimal point precision.", true, CustomLogLevel.MEDIUM); for (final Object runtime : runtimes) { final JSONObject json = (JSONObject) runtime; final JSONObject jsonRuntimeCool = (JSONObject) json.get(COOL); final JSONObject jsonRuntimeHeat = (JSONObject) json.get(HEAT); final String coolRuntimeHrsActual = jsonRuntimeCool.get(RUNTIME_HRS_ACTUAL).toString(); final String heatRuntimeHrsActual = jsonRuntimeHeat.get(RUNTIME_HRS_ACTUAL).toString(); setLogString("coolRuntimeHrsActual: " + coolRuntimeHrsActual, true, CustomLogLevel.HIGH); Assert.assertTrue(coolRuntimeHrsActual.split("\\.").length > 1 ? coolRuntimeHrsActual.split("\\.")[1].length() <= 2 : true, "Cool run time hours have more than 2 decimal point precision."); setLogString("heatRuntimeHrsActual: " + heatRuntimeHrsActual, true, CustomLogLevel.HIGH); Assert.assertTrue(heatRuntimeHrsActual.split("\\.").length > 1 ? heatRuntimeHrsActual.split("\\.")[1].length() <= 2 : true, "Heat run time hours have more than 2 decimal point precision."); } setLogString("Verified that runtime savings have two decimal point precision.", true, CustomLogLevel.MEDIUM); }