List of usage examples for org.apache.commons.lang3 StringUtils countMatches
public static int countMatches(final CharSequence str, final char ch)
Counts how many times the char appears in the given string.
A null or empty ("") String input returns 0 .
StringUtils.countMatches(null, *) = 0 StringUtils.countMatches("", *) = 0 StringUtils.countMatches("abba", 0) = 0 StringUtils.countMatches("abba", 'a') = 2 StringUtils.countMatches("abba", 'b') = 2 StringUtils.countMatches("abba", 'x') = 0
From source file:org.openecomp.sdc.common.config.EcompErrorLogUtil.java
private static Either<String, Boolean> setDescriptionParams(EcompErrorEnum ecompErrorEnum, String... descriptionParams) { String description = ecompErrorEnum.getEcompErrorCode().getDescription(); // Counting number of params in description int countMatches = StringUtils.countMatches(description, AbsEcompErrorManager.PARAM_STR); // Catching cases when there are more params passed than there are in // the description (formatter will ignore extra params and won't throw // exception) if (countMatches != descriptionParams.length) { return Either.right(false); }//from w w w . j a va 2s . c o m // Setting params of the description if any StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); try { formatter.format(description, (Object[]) descriptionParams).toString(); return Either.left(formatter.toString()); } catch (IllegalFormatException e) { // Number of passed params doesn't match number of params in config // file return Either.right(false); } finally { formatter.close(); } }
From source file:org.openecomp.sdc.vendorlicense.licenseartifacts.impl.VendorLicenseArtifactsServiceTest.java
@Test public void onlyAddChangedEntitiesToVendorArtifact() throws IOException { Version vlmVersion = vspDetails.getVlmVersion(); EntitlementPoolEntity updatedEP = ep11; String updatedNameEP = "updatedNameEP"; updatedEP.setName(updatedNameEP);//from w w w. ja va 2 s. c om LicenseKeyGroupEntity updatedLKG = new LicenseKeyGroupEntity(); updatedLKG.setId(lkg11Id); updatedLKG.setVendorLicenseModelId(lkg11.getVendorLicenseModelId()); String updateDescLKG = "UpdateDescLKG"; updatedLKG.setName(lkg11.getName()); updatedLKG.setDescription(updateDescLKG); createThirdFinalVersionForVLMChangeEpLKGInSome(ep11.getVendorLicenseModelId(), updatedEP, updatedLKG); licenseArtifacts = vendorLicenseArtifactsService.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups(), USER1); String actual = IOUtils.toString(licenseArtifacts.getFileContent( org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH), StandardCharsets.UTF_8); // System.out.println("onlyAddChangedEntitiesToVendorArtifact = " + actual); int countUpdatedLKG = StringUtils.countMatches(actual, updateDescLKG); Assert.assertEquals(countUpdatedLKG, 1); int countUpdatedEp = StringUtils.countMatches(actual, updatedNameEP); Assert.assertEquals(countUpdatedEp, 1); int epOccurrences = StringUtils.countMatches(actual, "<entitlement-pool>"); Assert.assertEquals(epOccurrences, 3); }
From source file:org.openlmis.functional.FacilityAPI.java
@Test(groups = { "webserviceSmoke" }) public void testFacilityAPI() throws SQLException { HttpClient client = new HttpClient(); client.createContext();//from ww w . j av a 2 s .com ResponseEntity responseEntity = client.SendJSON("", format(URL, "F10"), GET, commTrackUser, "Admin123"); String response = responseEntity.getResponse(); assertTrue("Response entity : " + response, response.contains("\"code\":\"F10\"")); assertTrue("Response entity : " + response, response.contains("\"name\":\"Village Dispensary\"")); assertTrue("Response entity : " + response, response.contains("\"facilityType\":\"Lvl3 Hospital\"")); assertTrue("Response entity : " + response, response.contains("\"description\":\"IT department\"")); assertTrue("Response entity : " + response, response.contains("\"gln\":\"G7645\"")); assertTrue("Response entity : " + response, response.contains("\"mainPhone\":\"9876234981\"")); assertTrue("Response entity : " + response, response.contains("\"fax\":\"fax\"")); assertTrue("Response entity : " + response, response.contains("\"address1\":\"A\"")); assertTrue("Response entity : " + response, response.contains("\"address2\":\"B\"")); assertTrue("Response entity : " + response, response.contains("\"geographicZone\":\"Ngorongoro\"")); assertTrue("Response entity : " + response, response.contains("\"catchmentPopulation\":333")); assertTrue("Response entity : " + response, response.contains("\"latitude\":22.1")); assertTrue("Response entity : " + response, response.contains("\"longitude\":1.2")); assertTrue("Response entity : " + response, response.contains("\"altitude\":3.3")); assertTrue("Response entity : " + response, response.contains("\"operatedBy\":\"NGO\"")); assertTrue("Response entity : " + response, response.contains("\"coldStorageGrossCapacity\":9.9")); assertTrue("Response entity : " + response, response.contains("\"coldStorageNetCapacity\":6.6")); assertTrue("Response entity : " + response, response.contains("\"suppliesOthers\":true")); assertTrue("Response entity : " + response, response.contains("\"sdp\":true")); assertTrue("Response entity : " + response, response.contains("\"hasElectricity\":true")); assertTrue("Response entity : " + response, response.contains("\"online\":true")); assertTrue("Response entity : " + response, response.contains("\"hasElectronicSCC\":true")); assertTrue("Response entity : " + response, response.contains("\"hasElectronicDAR\":true")); assertTrue("Response entity : " + response, response.contains("\"active\":true")); assertTrue("Response entity : " + response, response.contains("\"goLiveDate\":1352572200000")); assertTrue("Response entity : " + response, response.contains("\"goDownDate\":-2592106200000")); assertTrue("Response entity : " + response, response.contains("\"stringGoLiveDate\":\"11-11-2012\"")); assertTrue("Response entity : " + response, response.contains("\"stringGoDownDate\":\"11-11-1887\"")); assertTrue("Response entity : " + response, response.contains("\"satellite\":true")); assertTrue("Response entity : " + response, response.contains("\"virtualFacility\":false")); assertFalse("Response entity : " + response, response.contains("\"parentFacility\"")); assertTrue("Response entity : " + response, response.contains("\"comment\":\"fc\"")); assertTrue("Response entity : " + response, response.contains("\"modifiedDate\":")); assertTrue("Response entity : " + response, response.contains("\"programsSupported\":[")); assertTrue("Response entity : " + response, response.contains("\"HIV\"")); assertTrue("Response entity : " + response, response.contains("\"ESS_MEDS\"")); assertTrue("Response entity : " + response, response.contains("\"VACCINES\"")); assertTrue("Response entity : " + response, response.contains("\"enabled\":true")); assertEquals(StringUtils.countMatches(response, ":"), 37); dbWrapper.updateFieldValue("facilities", "enabled", "false", "name", "Village Dispensary"); responseEntity = client.SendJSON("", format(URL, "F10"), GET, commTrackUser, "Admin123"); response = responseEntity.getResponse(); assertTrue("Response entity : " + response, response.contains("\"enabled\":false")); dbWrapper.deleteProgramToFacilityMapping("ESS_MEDS"); responseEntity = client.SendJSON("", format(URL, "F10"), GET, commTrackUser, "Admin123"); response = responseEntity.getResponse(); assertTrue("Response entity : " + response, response.contains("\"programsSupported\":[")); assertTrue("Response entity : " + response, response.contains("\"HIV\"")); assertTrue("Response entity : " + response, response.contains("\"VACCINES\"")); responseEntity = client.SendJSON("", format(URL, "INVALID_FACILITY_CODE"), GET, commTrackUser, "Admin123"); response = responseEntity.getResponse(); assertEquals(response, "{\"error\":\"Invalid Facility code\"}"); assertEquals(responseEntity.getStatus(), 400); }
From source file:org.openlmis.functional.FacilityFeed.java
@Test(groups = { "webserviceSmoke" }) public void testFacilityFeedUsingCommTrack() throws IOException, ParserConfigurationException, SAXException { HttpClient client = new HttpClient(); client.createContext();/*from www . j a va 2s. c o m*/ Agent agentJson = readObjectFromFile(FULL_JSON_TXT_FILE_NAME, Agent.class); agentJson.setAgentCode(DEFAULT_AGENT_CODE); agentJson.setAgentName(DEFAULT_AGENT_NAME); agentJson.setParentFacilityCode(DEFAULT_PARENT_FACILITY_CODE); agentJson.setPhoneNumber(PHONE_NUMBER); agentJson.setActive(ACTIVE_STATUS); client.SendJSON(getJsonStringFor(agentJson), CREATE_URL, POST, commTrackUser, "Admin123"); String stringGoLiveDate = new SimpleDateFormat("dd-MM-yyyy").format(new Date()); ResponseEntity responseEntity = client.SendJSON("", FACILITY_FEED_URL, "GET", "", ""); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"code\":\"" + DEFAULT_AGENT_CODE + "\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"name\":\"" + DEFAULT_AGENT_NAME + "\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"facilityType\":\"Lvl3 Hospital\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"mainPhone\":\"" + PHONE_NUMBER + "\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"geographicZone\":\"Ngorongoro\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"active\":" + ACTIVE_STATUS + "")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"stringGoLiveDate\":\"" + stringGoLiveDate + "\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"goLiveDate\"")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"virtualFacility\":true")); assertTrue("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse() .contains("\"parentFacility\":\"" + DEFAULT_PARENT_FACILITY_CODE + "\"")); assertFalse("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"facilityIsOnline\":")); assertFalse("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"hasElectricity\":")); assertFalse("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"hasElectronicSCC\":")); assertFalse("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"hasElectronicDAR\":")); assertFalse("Response entity : " + responseEntity.getResponse(), responseEntity.getResponse().contains("\"satelliteFacility\":")); assertEquals(StringUtils.countMatches(responseEntity.getResponse(), ":"), 29); agentJson.setActive("false"); client.SendJSON(getJsonStringFor(agentJson), UPDATE_URL + DEFAULT_AGENT_CODE + JSON_EXTENSION, PUT, commTrackUser, "Admin123"); ResponseEntity responseEntityUpdated = client.SendJSON("", FACILITY_FEED_URL, "GET", "", ""); assertTrue("Response entity : " + responseEntityUpdated.getResponse(), responseEntityUpdated.getResponse().contains("\"active\":false")); assertFalse("Response entity : " + responseEntityUpdated.getResponse(), responseEntityUpdated.getResponse().contains("\"facilityIsOnline\":")); assertFalse("Response entity : " + responseEntityUpdated.getResponse(), responseEntityUpdated.getResponse().contains("\"hasElectricity\":")); assertFalse("Response entity : " + responseEntityUpdated.getResponse(), responseEntityUpdated.getResponse().contains("\"hasElectronicSCC\":")); assertFalse("Response entity : " + responseEntityUpdated.getResponse(), responseEntityUpdated.getResponse().contains("\"hasElectronicDAR\":")); assertFalse("Response entity : " + responseEntityUpdated.getResponse(), responseEntityUpdated.getResponse().contains("\"satelliteFacility\":")); List<String> feedJSONList = XmlUtils.getNodeValues(responseEntityUpdated.getResponse(), "content"); assertTrue("feed json list : " + feedJSONList.get(0), feedJSONList.get(0).contains("\"active\":true")); assertTrue("feed json list : " + feedJSONList.get(0), feedJSONList.get(0).contains("\"enabled\":true")); assertTrue("feed json list : " + feedJSONList.get(0), feedJSONList.get(0).contains("\"sdp\":true")); assertTrue("feed json list : " + feedJSONList.get(1), feedJSONList.get(1).contains("\"active\":false")); assertTrue("feed json list : " + feedJSONList.get(1), feedJSONList.get(1).contains("\"enabled\":true")); }
From source file:org.openlmis.functional.FacilityProgramSupportedFeed.java
@Test(groups = { "webserviceSmoke" }, dataProvider = "Data-Provider-Function-Positive") public void testFacilityProgramSupportedFeed_Upload(String user, String program, String[] credentials) throws FileNotFoundException, InterruptedException, ParserConfigurationException, SAXException { HttpClient client = new HttpClient(); client.createContext();//from w w w. j a va 2s .co m HomePage homePage = loginPage.loginAs(credentials[0], credentials[1]); UploadPage uploadPage = homePage.navigateUploads(); uploadPage.uploadProgramSupportedByFacilities("QA_program_supported_WebService.csv"); Thread.sleep(2000); ResponseEntity responseEntity = client.SendJSON("", PROGRAM_SUPPORTED_FEED_URL, "GET", "", ""); String expected = "{\"code\":\"" + program + "\",\"name\":\"" + program + "\",\"active\":true,\"startDate\":1296585000000,\"stringStartDate\":\"02/02/2011\"}"; assertTrue(responseEntity.getResponse().contains(expected)); assertEquals(StringUtils.countMatches(responseEntity.getResponse(), ":"), 29); uploadPage.uploadProgramSupportedByFacilities("QA_program_supported_Subsequent_WebService.csv"); Thread.sleep(2000); responseEntity = client.SendJSON("", PROGRAM_SUPPORTED_FEED_URL, "GET", "", ""); List<String> feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); expected = "{\"code\":\"" + program + "\",\"name\":\"" + program + "\",\"active\":false,\"startDate\":1296585000000,\"stringStartDate\":\"02/02/2011\"}"; String expected1 = "{\"code\":\"" + program + "\",\"name\":\"" + program + "\",\"active\":true,\"startDate\":1304533800000,\"stringStartDate\":\"05/05/2011\"}"; assertTrue(feedJSONList.get(1).contains(expected)); assertTrue(feedJSONList.get(2).contains(expected1)); }
From source file:org.openlmis.functional.GetRequisitionDetailsAPI.java
@Test(groups = { "webserviceSmoke" }) public void testGetRequisitionDetails() throws SQLException { HttpClient client = new HttpClient(); client.createContext();/*from w w w.j av a 2 s . c o m*/ submitRequisition("commTrack1", "HIV"); dbWrapper.updateRequisitionStatus("AUTHORIZED", "commTrack", "HIV"); Long id = (long) dbWrapper.getMaxRnrID(); ResponseEntity responseEntity = client.SendJSON("", URL + id, "GET", "commTrack", "Admin123"); checkRequisitionStatus("AUTHORIZED", responseEntity); checkOrderDetailsNotPresent(responseEntity); assertEquals(StringUtils.countMatches(responseEntity.getResponse(), ":"), 20); }
From source file:org.openlmis.functional.RequisitionStatusFeed.java
@Test(groups = { "webserviceSmoke" }) public void testRequisitionStatusUsingCommTrackUserForExportOrderFlagFalse() throws IOException, SQLException, ParserConfigurationException, SAXException { HttpClient client = new HttpClient(); client.createContext();/*from w ww .j a v a2s. c o m*/ submitRnRThroughApi("V10", "HIV", "P10", 1, 10, 1, 0, 0, 2); Long id = (long) dbWrapper.getMaxRnrID(); ResponseEntity responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); assertEquals(StringUtils.countMatches(responseEntity.getResponse(), ":"), 41); List<String> feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkRequisitionStatusOnFeed("INITIATED", feedJSONList.get(0), id); checkRequisitionStatusOnFeed("SUBMITTED", feedJSONList.get(1), id); checkRequisitionStatusOnFeed("AUTHORIZED", feedJSONList.get(2), id); dbWrapper.setExportOrdersFlagInSupplyLinesTable(false, "F10"); approveRequisition(id, 65); dbWrapper.updateRestrictLogin("commTrack", false); convertToOrder("commTrack", "Admin123"); dbWrapper.updateRestrictLogin("commTrack", true); responseEntity = client.SendJSON("", URL + "1", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkRequisitionStatusOnFeed("APPROVED", feedJSONList.get(3), id); checkRequisitionStatusOnFeed("RELEASED", feedJSONList.get(4), id); responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkOrderStatusOnFeed("READY_TO_PACK", feedJSONList.get(0), generateOrderNumberForIdAndDefaultConfiguration(id, "HIV"), id); dbWrapper.assignRight("store in-charge", "MANAGE_POD"); OrderPOD OrderPODFromJson = JsonUtility.readObjectFromFile(FULL_JSON_POD_TXT_FILE_NAME, OrderPOD.class); OrderPODFromJson.getPodLineItems().get(0).setQuantityReceived(65); OrderPODFromJson.getPodLineItems().get(0).setProductCode("P10"); client.SendJSON(getJsonStringFor(OrderPODFromJson), format(POD_URL, generateOrderNumberForIdAndDefaultConfiguration(id, "HIV")), "POST", "commTrack", "Admin123"); responseEntity = client.SendJSON("", URL + "recent", "GET", "", ""); assertEquals(200, responseEntity.getStatus()); feedJSONList = XmlUtils.getNodeValues(responseEntity.getResponse(), "content"); checkOrderStatusOnFeed("RECEIVED", feedJSONList.get(1), generateOrderNumberForIdAndDefaultConfiguration(id, "HIV"), id); }
From source file:org.openscore.lang.systemtests.flows.DataFlowTest.java
@Test public void testBindingsFlow() throws Exception { URI resource = getClass().getResource("/yaml/system-flows/bindings_flow.yaml").toURI(); URI operations = getClass().getResource("/yaml/system-flows/bindings_flow_operations.yaml").toURI(); SlangSource dep = SlangSource.fromFile(operations); Set<SlangSource> path = Sets.newHashSet(dep); CompilationArtifact compilationArtifact = slang.compile(SlangSource.fromFile(resource), path); Map<String, Serializable> userInputs = new HashMap<>(); userInputs.put("base_input", ">"); Map<String, StepData> steps = triggerWithData(compilationArtifact, userInputs, null); Map<String, Serializable> flowOutputs = steps.get(EXEC_START_PATH).getOutputs(); String final_output = (String) flowOutputs.get("final_output"); Assert.assertEquals("some of the inputs or outputs were not bound correctly", 13, final_output.length()); Assert.assertEquals("some of the inputs were not bound correctly", 6, StringUtils.countMatches(final_output, ">")); Assert.assertEquals("some of the outputs were not bound correctly", 5, StringUtils.countMatches(final_output, "<")); Assert.assertEquals("some of the results were not bound correctly", 2, StringUtils.countMatches(final_output, "|")); }
From source file:org.opensextant.extractors.xcoord.GeocoordMatch.java
/** * Evaluate DMS patterns only... evaluate if match contains dashes as field * separators or as hemispheres. Or both. If match contains dash sep on lat, * but not in lon, then the match is invalid. This suggests the match is not * a geocoordinate.// w ww. j a v a 2 s . co m * * @return true if coordinate is invalid because * * @throws NormalizationException */ public boolean evaluateInvalidDashes() throws NormalizationException { if (lat == null || lon == null) { throw new NormalizationException("Set lat/lon first before evaluating dashes"); } if (lat.offsetOrdinate < 0 || lon.offsetOrdinate < 0) { throw new NormalizationException("Degree offsets my exist"); } // Relative offsets to text. Given the match, find where the degree // starts. // // LAT / LON pairs -- where does lat start and end? // // D:M:S H sep D:M:S H // H D:M:S sep H D:M:S // Choose the end of the latitude text based on the hemisphere. // OR Based on the start of the longitude hemisphere int x2 = lon.offsetOrdinate; // Remains as-is, by default. if (offsetSeparator > 0) { // Offsets are regex char 1.. based or 0.. based? x2 = offsetSeparator - 1; // Exclude the offset; should remain // as-is; } else if (lat.offsetHemi > 0 && lat.offsetHemi > lat.offsetDeg) { x2 = lat.offsetHemi + 1; // Include the hemisphere for Lat. +1 } // By this point x2 offset should be exclusive end of LAT String latText = getText().substring(lat.offsetDeg, x2).trim(); String lonText = getText().substring(lon.offsetOrdinate).trim(); // TODO: This fails to work if "-" is used as a separator, <Lat> - <Lon> // But in certain situations it is helpful to know if dash as field // separators can reveal a false positive // for example in scientific data that employs patterns that look like // DMS or DM lat/lon // int lat_dashes = StringUtils.countMatches(latText, "-"); int lon_dashes = StringUtils.countMatches(lonText, "-"); // ASSUMPTION: LON follows LAT, so where LAT, -LON // the "-" may be part of the LAT field. if (lon.hemisphere.symbol != null) { if ("-".equals(lon.hemisphere.symbol)) { --lon_dashes; } } // Dash count is even? return lat_dashes != lon_dashes; // Caller should override this assessment if counting dashes in lat or // lon is irrelevant. }
From source file:org.openstreetmap.josm.plugins.opendata.core.util.OdUtils.java
public static final String[] stripQuotesAndExtraChars(String[] split, String sep) { List<String> result = new ArrayList<>(); boolean append = false; for (int i = 0; i < split.length; i++) { if (append) { int index = result.size() - 1; if (split[i].endsWith("\"") && StringUtils.countMatches(split[i], "\"") % 2 == 1) { append = false;/*w w w .ja v a 2 s. c o m*/ } result.set(index, result.get(index) + sep + split[i].replaceAll("\"", "")); } else if (split[i].startsWith("\"")) { if (!(split[i].endsWith("\"") && StringUtils.countMatches(split[i], "\"") % 2 == 0)) { append = true; } result.add(split[i].replaceAll("\"", "")); } else { result.add(split[i]); } } // Remove exotic characters such as U+FEFF found in some CSV files for (ListIterator<String> it = result.listIterator(); it.hasNext();) { it.set(Utils.strip(it.next())); } return result.toArray(new String[0]); }