public boolean equals(Ad o) { return title.equals(o.getTitle()) && price == o.getPrice() && location.equals(o.getLocation()) && link.equals(o.getLink()) && date.equals(o.getDate()); }
protected void onPreExecute() { TextView title = (TextView) fragment.getActivity().findViewById(R.id.textTitle); TextView description = (TextView) fragment.getActivity().findViewById(R.id.textDescription); image = (ImageView) fragment.getActivity().findViewById(R.id.imageImage); image.setVisibility(View.INVISIBLE); title.setText(ad.getTitle()); description.setText(ad.getBody()); fragment.getActivity().setTitle(ad.getTitle()); }
public Ad parseInto(Ad ad) { char open = expect(OB); for (int i = 0; ; i++) { char c = saved = discardIgnored(SEP + WS); // Check for end of ad. if (check(c, CB)) { next(); return ad; } // Discard any extraneous separators or newlines. saved = discardIgnored(SEP + WS); // Read the first token. Object o = readValue(); // Check if it's anonymous or not. // FIXME: These switch cases should not be hardcoded... switch (c = expect(EQ + SEP + CB, " \t\b")) { case ':': // Check for assignment. case '=': // Determine the key. String k = o.toString(); o = findValue(); // Insert into ad as key-value pair. if (o instanceof Atom) ad.putObject(k, ((Atom) o).eval()); else ad.putObject(k, o); if (open > 0 && ad instanceof ParsedAd) ((ParsedAd) ad).setHint(open); open = 0; break; case '}': // Check for end and push char back if found. case ']': case ')': case '>': saved = c; case ',': // Check for separator. case ';': case '&': case ' ': case '\r': case '\n': // Insert into ad as list item. if (o instanceof Atom) ad.putObject(((Atom) o).eval()); else ad.putObject(o); if (open > 0 && ad instanceof ParsedAd) ((ParsedAd) ad).setHint(open); open = 0; } } }
/* */ public void getFromEffectTagStruct(Ad paramAd) { /* 117 */ paramAd = (Ad[])paramAd.a(); /* 118 */ for (int i = 0; i < this.effects.length; i++) { /* 119 */ this.effects[i].fromTagStructure(paramAd[i]); /* */ } /* 121 */ distributePoints(); /* */ }
/* */ public void fromTagStructure(Ad paramAd) /* */ { /* 73 */ ( /* 74 */ paramAd = (Ad[])paramAd.a())[ /* 74 */ 0].a(); /* 75 */ paramAd[1].a(); /* 76 */ getFromEffectTagStruct(paramAd[2]); /* */ }
@Test public void testJSONToPOJO() { Ad pojo = new Ad(); pojo.adId = 123; pojo.campaignId = 234876274; pojo.description = "sports"; pojo.sizes = Lists.newArrayList("200x350", "600x800"); pojo.startDate = new DateTime() .withDate(2016, 1, 1) .withMillisOfDay(0) .withZoneRetainFields(DateTimeZone.UTC) .toDate(); pojo.endDate = new DateTime() .withDate(2016, 2, 1) .withMillisOfDay(0) .withZoneRetainFields(DateTimeZone.UTC) .toDate(); operator.in.put(pojo); Assert.assertEquals(1, validDataSink.collectedTuples.size()); Assert.assertEquals(0, invalidDataSink.collectedTuples.size()); String expectedJSONString = "{\"adId\":123,\"campaignId\":234876274,\"sizes\":[\"200x350\",\"600x800\"],\"startDate\":\"Fri, 1 Jan 2016 00:00:00\",\"endDate\":\"01-Feb-2016\",\"desc\":\"sports\"}"; Assert.assertEquals(expectedJSONString, validDataSink.collectedTuples.get(0)); Assert.assertEquals(1, operator.getIncomingTuplesCount()); Assert.assertEquals(1, operator.getEmittedObjectCount()); Assert.assertEquals(0, operator.getErrorTupleCount()); }
@SuppressWarnings({"rawtypes"}) public void dcap() throws InterruptedException, IOException { // Appium auto start and Killing ADB server Start_Stop_AppiumServer as = new Start_Stop_AppiumServer(); System.out.println("Stopping the ADB server"); as.killadb(); System.out.println("ADB Server is stopped"); Thread.sleep(9000); System.out.println("==================================="); System.out.println("Stopping the appium server"); as.stopAppiumServer(); System.out.println("Appium server is stopped"); Thread.sleep(10000); System.out.println("Starting the appium server"); as.startAppiumServer(); System.out.println("Appium server is started and running"); Thread.sleep(50000); // Read data from PropertyFile Driver.property(); PropertyFile.property(); // Capabilities launching DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("appium-version", "1.0"); capabilities.setCapability("platformName", properties.getProperty("platformName")); capabilities.setCapability("platformVersion", properties.getProperty("platformVersion")); capabilities.setCapability("deviceName", properties.getProperty("deviceName")); capabilities.setCapability("app", properties.getProperty("appPath")); capabilities.setCapability("appPackage", "com.weather.Weather"); capabilities.setCapability("appActivity", "com.weather.Weather.app.SplashScreenActivity"); Ad = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); Ad.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); System.out.println("Working fine"); // System.out.println("logfile is ::"properties.getProperty("LogFilePath")); System.out.println("Capabilities are launched"); }
@Test public void testJSONToPOJONullFields() { Ad pojo = new Ad(); pojo.adId = 123; pojo.campaignId = 234876274; pojo.description = "sports"; pojo.sizes = null; pojo.startDate = null; pojo.endDate = null; operator.in.put(pojo); Assert.assertEquals(1, validDataSink.collectedTuples.size()); Assert.assertEquals(0, invalidDataSink.collectedTuples.size()); String expectedJSONString = "{\"adId\":123,\"campaignId\":234876274,\"sizes\":null,\"startDate\":null,\"endDate\":null,\"desc\":\"sports\"}"; Assert.assertEquals(expectedJSONString, validDataSink.collectedTuples.get(0)); Assert.assertEquals(1, operator.getIncomingTuplesCount()); Assert.assertEquals(1, operator.getEmittedObjectCount()); Assert.assertEquals(0, operator.getErrorTupleCount()); }
@SuppressWarnings({"unused", "unchecked", "rawtypes", "resource", "deprecation"}) public void SmokeTest_WFX() throws Exception { // app kill and relaunch the app app_Kill_Relaunch.Kill_realaunch(); System.out.println("Verification of WeatherFX Call Test_Case Started"); String adbPath = properties.getProperty("adbPath"); String[] str = {"/bin/bash", "-c", adbPath + " shell setprop log.tag.TwcAd DEBUG"}; Process p = Runtime.getRuntime().exec(str); System.out.println("Debug command is done"); String[] str1 = { "/bin/bash", "-c", adbPath + " -d logcat -v time >> " + properties.getProperty("LogFilePath") }; Process p1 = Runtime.getRuntime().exec(str1); System.out.println("Writing App logs to LogFile"); ATUReports.add("Launch the app", false); try { // Wait for 20 sec for element presence WebDriverWait wait = new WebDriverWait(Ad, 10); wait.until( ExpectedConditions.presenceOfElementLocated(By.id("com.weather.Weather:id/temperature"))); // Temperature Element MobileElement el = (MobileElement) Ad.findElementById("com.weather.Weather:id/temperature"); System.out.println("Temp : " + el.getText()); ATUReports.add("Scroll to Feed-1 Ad", false); Swipe.swipe(); Swipe.swipe(); // Ad.swipe(0,1800,0,20,2000); // Ad.swipe(0,1800,0,20,2000); } catch (Exception e) { // System.out.println("Exception message :: "+e); } MobileElement AdEle = (MobileElement) Ad.findElementById("com.weather.Weather:id/ad_view_holder"); WebDriverWait wait1 = new WebDriverWait(Ad, 4); wait1.until(ExpectedConditions.visibilityOf(AdEle)); if (AdEle.isDisplayed()) { System.out.println("Feed-1 Ad is displayed"); ATUReports.add("Feed-1 Ad is present", false); } Thread.sleep(6000); // Reading the log file for feed_1,to verify WFXTG value BufferedReader r = new BufferedReader(new FileReader(properties.getProperty("LogFilePath"))); String line = ""; String allLine = ""; while ((line = r.readLine()) != null) { System.out.println("Sys data is ::" + line); } String FilePath = properties.getProperty("LogFilePath"); try { FileInputStream fstream = new FileInputStream(FilePath); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; // / read log line by line ------ strLine = br.readLines(6, 10); / StringBuffer sb = new StringBuffer(""); while ((strLine = br.readLine()) != null) { sb.append(strLine); } Thread.sleep(2000); String req = null; String[] arrays; String[] key; String zipcode = null; List<String> pubad_zip = new ArrayList<String>(); ATUReports.add("Verify the PubAd_WFXTG values in Feed_1 Call", false); if (sb.toString().contains("slotName=weather.feed1")) { req = sb.toString().substring(sb.toString().lastIndexOf("slotName=weather.feed1")); req = req.substring(req.indexOf(",") + 1, req.indexOf("}")); System.out.println("Verifing the " + req); arrays = req.split(" "); for (String keys : arrays) { if (keys.contains("=")) { key = keys.split("="); // System.out.println("keys are :: "+key[0] + "---"+key[1]); if (key[0].contains("zip")) { key[1] = key[1].toString(); key[1] = key[1].substring(0, key[1].lastIndexOf(",")); pubad_zip.add(key[1]); break; } } } zipcode = pubad_zip.toString().replace("[", "").replace("]", ""); System.out.println("Zip value is :: " + zipcode); } List<String> pubad_ZCSvalues = wfxtg.getValues(req, "zcs"); List<String> pubad_HZCSvalues = wfxtg.getValues(req, "hzcs"); List<String> pubad_NZCSvalues = wfxtg.getValues(req, "nzcs"); Thread.sleep(1000); System.out.println("================================"); try { // Capturing the WFXTG Call Data String wfxValues = null; int test = 0; for (int i = 1; i <= 6; i++) { int index = sb.toString() .indexOf( "response from server is {" + "\"wfxtg\"" + ":{" + "\"current\"" + ":[", test); int emptyindex = sb.toString() .indexOf( "response from server is {" + "\"wfxtg\"" + ":{" + "\"current\"" + ":[]", test); if (index == -1) { break; } else if (index != emptyindex) { wfxValues = sb.toString().substring(index); wfxValues = wfxValues.substring( wfxValues.indexOf("scatterSegs" + '"' + ":") + 13, wfxValues.indexOf("]}}") + 1); // WFXTG call of https://triggers.wfxtriggers.com System.out.println("Verifing the WFXTG call" + wfxValues); } test = index + 2; } // if (sb.toString().contains("response from server is {" + '"' + "wfxtg")) { // String wfxValues = null; // if (sb.toString().contains("response from server is {" + "\"wfxtg\"")) { // wfxValues = sb.toString().substring(sb.toString().lastIndexOf("response from // server is {" + '"'+ "wfxtg")); // wfxValues = wfxValues.substring( // wfxValues.indexOf("scatterSegs" + '"' + ":") + 13, // wfxValues.indexOf("]}}") + 1); // System.out.println("Verifing the WFX call " + wfxValues); // } System.out.println("================================"); Thread.sleep(1000); List<String> segmentList = new ArrayList<String>(); String seg = null; String zip = zipcode; JSONParser parser = new JSONParser(); Object obj = parser.parse(wfxValues.toString()); JSONArray jsonObject = (JSONArray) obj; Map<String, List<String>> zcsmap = new HashMap<String, List<String>>(); Map<String, List<String>> hzcsmap = new HashMap<String, List<String>>(); Map<String, List<String>> nzcsmap = new HashMap<String, List<String>>(); for (int index = 0; index < jsonObject.size(); index++) { JSONObject obj1 = (JSONObject) jsonObject.get(index); if (obj1.containsKey("zcs")) { JSONArray array2 = (JSONArray) obj1.get("zcs"); for (int index2 = 0; index2 < array2.size(); index2++) { JSONObject obj2 = (JSONObject) array2.get(index2); JSONArray array3 = (JSONArray) obj2.get("segments"); List<String> list = new ArrayList<String>(); for (int index3 = 0; index3 < array3.size(); index3++) { list.add(((Long) array3.get(index3)).toString()); } zcsmap.put((String) obj2.get("zip"), list); } } else if (obj1.containsKey("hzcs")) { JSONArray array2 = (JSONArray) obj1.get("hzcs"); for (int index2 = 0; index2 < array2.size(); index2++) { JSONObject obj2 = (JSONObject) array2.get(index2); JSONArray array3 = (JSONArray) obj2.get("segments"); List<String> list = new ArrayList<String>(); for (int index3 = 0; index3 < array3.size(); index3++) { list.add(((Long) array3.get(index3)).toString()); } hzcsmap.put((String) obj2.get("zip"), list); } } else if (obj1.containsKey("nzcs")) { JSONArray array2 = (JSONArray) obj1.get("nzcs"); for (int index2 = 0; index2 < array2.size(); index2++) { JSONObject obj2 = (JSONObject) array2.get(index2); JSONArray array3 = (JSONArray) obj2.get("segments"); List<String> list = new ArrayList<String>(); for (int index3 = 0; index3 < array3.size(); index3++) { list.add(((Long) array3.get(index3)).toString()); } nzcsmap.put((String) obj2.get("zip"), list); } } } // Asserting the PubAd_ZCS_Values and WFX_APICall_ZCS_Values List<String> zcssegments = zcsmap.get(zip); List wfx_zcs = new ArrayList(); for (String i : zcssegments) { wfx_zcs.add(Integer.parseInt(i)); } Collections.sort(wfx_zcs); String wfx_zcs_values = wfx_zcs.toString().replace(" ", ""); String pubAd_zcs_values = pubad_ZCSvalues.toString(); System.out.println("PubAd_ZCS_values " + pubAd_zcs_values); System.out.println("WFX_APICall_ZCS_values " + wfx_zcs_values); // // ATUReports.add("PubAd_ZCS_values :: "+pubAd_zcs_values,false); // // ATUReports.add("WFX_APICall_ZCS_values :: "+wfx_zcs_values,false); ATUReports.add("ZCS_values are present in Feed-1_PubAd call", false); ATUReports.add("ZCS_values are present in WFX_APICall", false); if (wfx_zcs_values.equalsIgnoreCase(pubAd_zcs_values)) { System.out.println("PubAd_ZCS_values and WFX_APICall_ZCS_values are equal"); ATUReports.add("PubAd_ZCS_values and WFX_APICall_ZCS_values are equal", false); } else { System.out.println("PubAd_ZCS_values and WFX_APICall_ZCS_values are NOT equal"); ATUReports.add("PubAd_ZCS_values and WFX_APICall_ZCS_values are NOT equal", false); } System.out.println("================================"); // Asserting the PubAd_NZCS_Values and WFX_APICall_NZCS_Values List<String> nzcssegments = nzcsmap.get(zip); List wfx_nzcs = new ArrayList(); for (String j : nzcssegments) { wfx_nzcs.add(Integer.parseInt(j)); } Collections.sort(wfx_nzcs); String wfx_nzcs_values = wfx_nzcs.toString().replace(" ", ""); String pubAd_nzcs_values = pubad_NZCSvalues.toString(); System.out.println("PubAd_NZCS_values " + pubAd_nzcs_values); System.out.println("WFX_APICall_NZCS_values " + wfx_nzcs_values); // // ATUReports.add("PubAd_NZCS_values :: "+pubAd_nzcs_values,false); // // ATUReports.add("WFX_APICall_NZCS_values :: "+wfx_nzcs_values,false); ATUReports.add("NZCS_values are present in Feed-1_PubAd call", false); ATUReports.add("NZCS_values are present in WFX_APICall", false); if (wfx_nzcs_values.equalsIgnoreCase(pubAd_nzcs_values)) { System.out.println("PubAd_NZCS_values and WFX_APICall_NZCS_values are equal"); ATUReports.add("PubAd_NZCS_values and WFX_APICall_NZCS_values are equal", false); } else { System.out.println("PubAd_NZCS_values and WFX_APICall_NZCS_values are NOT equal"); ATUReports.add("PubAd_NZCS_values and WFX_APICall_NZCS_values are NOT equal", false); } System.out.println("================================"); // Asserting the PubAd_HZCS_Values and WFX_APICall_HZCS_Values List<String> hzcssegments = hzcsmap.get(zip); List wfx_hzcs = new ArrayList(); for (String j : hzcssegments) { wfx_hzcs.add(Integer.parseInt(j)); } Collections.sort(wfx_hzcs); String wfx_hzcs_values = wfx_hzcs.toString().replace(" ", ""); String pubAd_hzcs_values = pubad_HZCSvalues.toString(); System.out.println("PubAd_HZCS_values " + pubAd_hzcs_values); System.out.println("WFX_APICall_HZCS_values " + wfx_hzcs_values); // ATUReports.add("PubAd_HZCS_values :: "+pubAd_hzcs_values,false); // ATUReports.add("WFX_APICall_HZCS_values :: "+wfx_hzcs_values,false); ATUReports.add("HZCS_values are present in Feed-1_PubAd call", false); ATUReports.add("HZCS_values are present in WFX_APICall", false); if (wfx_hzcs_values.equalsIgnoreCase(pubAd_hzcs_values)) { System.out.println("PubAd_HZCS_values and WFX_APICall_HZCS_values are equal"); ATUReports.add("PubAd_HZCS_values and WFX_APICall_HZCS_values are equal", false); } else { System.out.println("PubAd_HZCS_values and WFX_APICall_HZCS_values are NOT equal"); ATUReports.add("PubAd_HZCS_values and WFX_APICall_HZCS_values are NOT equal", false); } System.out.println("================================"); // } br.close(); } catch (Exception e) { System.out.println("WFXTG values are showing as " + '"' + "nl" + '"' + "for ZCS/NZCS"); ATUReports.add("WFXTG values are showing as " + '"' + "nl" + '"' + "for ZCS/NZCS", false); } } catch (Exception e) { e.printStackTrace(); } System.out.println("Verifying WFX test case done"); }
// Retrieve photo from cache dir if available. Otherwise download it. protected Bitmap doInBackground(Void... voids) { Bitmap bitmap = null; String photoPath = null; boolean isInternet; File f; // No photo available if (ad.getImageFilename() == null) { Log.w(TAG, "photo is null"); return null; } try { f = Utils.getPhotoPath(context, ad); if (f.exists()) { bitmap = Utils.decodeSampledBitmapFromPath(f.getAbsolutePath(), 200, 200); } else { isInternet = Utils.isInternetAvailable(context); if (!isInternet) { errorMessage = context.getResources().getString(R.string.error_connecting); return null; } else { URL url = api.getPhotoUrlFromAd(ad); // If there's no photo then don't download it if (url == null) { return null; } Log.i(TAG, "Downloading image file " + url.toString()); BufferedInputStream bis = new BufferedInputStream(url.openStream()); int read = 0; byte[] bytes = new byte[1024]; f.createNewFile(); FileOutputStream fo = new FileOutputStream(f.getAbsoluteFile()); while ((read = bis.read(bytes)) != -1) { fo.write(bytes, 0, read); } fo.close(); Log.i(TAG, "File saved to: " + f.getAbsolutePath()); bitmap = Utils.decodeSampledBitmapFromPath(f.getAbsolutePath(), 200, 200); } } photoPath = f.getAbsolutePath(); } catch (NolotiroException e) { e.printStackTrace(); errorMessage = context.getResources().getString(R.string.error_retrieving_ads); } catch (MalformedURLException e) { e.printStackTrace(); errorMessage = context.getResources().getString(R.string.error_retrieving_ads); } catch (IOException e) { e.printStackTrace(); errorMessage = context.getResources().getString(R.string.error_retrieving_ads); } image.setTag(photoPath); return bitmap; }