public void TestProcessPhoneNumberDescElementMergesWithGeneralDesc() { PhoneNumberDesc generalDesc = new PhoneNumberDesc.Builder() .SetPossibleNumberPattern("\\d{6}").Build(); XElement territoryElement = parseXmlString("<territory><fixedLine/></territory>"); var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine", false); Assert.Equal("\\d{6}", phoneNumberDesc.PossibleNumberPattern); }
[TestMethod] public void testProcessPhoneNumberDescElementMergesWithGeneralDesc() { PhoneNumberDesc.Builder generalDesc = PhoneNumberDesc.newBuilder(); generalDesc.setPossibleNumberPattern("\\d{6}"); XmlElement territoryElement = parseXmlString("<territory><fixedLine/></territory>"); PhoneNumberDesc.Builder phoneNumberDesc; phoneNumberDesc = BuildMetadataFromXml.processPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine", false); Assert.AreEqual("\\d{6}", phoneNumberDesc.getPossibleNumberPattern()); }
// Tests processPhoneNumberDescElement(). [TestMethod] public void testProcessPhoneNumberDescElementWithInvalidInput() { PhoneNumberDesc.Builder generalDesc = PhoneNumberDesc.newBuilder(); XmlElement territoryElement = parseXmlString("<territory/>"); PhoneNumberDesc.Builder phoneNumberDesc; phoneNumberDesc = BuildMetadataFromXml.processPhoneNumberDescElement( generalDesc, territoryElement, "invalidType", false); Assert.AreEqual("NA", phoneNumberDesc.getPossibleNumberPattern()); Assert.AreEqual("NA", phoneNumberDesc.getNationalNumberPattern()); }
// @VisibleForTesting internal static void setRelevantDescPatterns(PhoneMetadata.Builder metadata, XmlElement element, bool liteBuild, bool isShortNumberMetadata) { PhoneNumberDesc.Builder generalDesc = PhoneNumberDesc.newBuilder(); generalDesc = processPhoneNumberDescElement(generalDesc, element, GENERAL_DESC, liteBuild); metadata.setGeneralDesc(generalDesc); if (!isShortNumberMetadata) { // Set fields used only by regular length phone numbers. metadata.setFixedLine( processPhoneNumberDescElement(generalDesc, element, FIXED_LINE, liteBuild)); metadata.setMobile( processPhoneNumberDescElement(generalDesc, element, MOBILE, liteBuild)); metadata.setSharedCost( processPhoneNumberDescElement(generalDesc, element, SHARED_COST, liteBuild)); metadata.setVoip( processPhoneNumberDescElement(generalDesc, element, VOIP, liteBuild)); metadata.setPersonalNumber( processPhoneNumberDescElement(generalDesc, element, PERSONAL_NUMBER, liteBuild)); metadata.setPager( processPhoneNumberDescElement(generalDesc, element, PAGER, liteBuild)); metadata.setUan( processPhoneNumberDescElement(generalDesc, element, UAN, liteBuild)); metadata.setVoicemail( processPhoneNumberDescElement(generalDesc, element, VOICEMAIL, liteBuild)); metadata.setNoInternationalDialling( processPhoneNumberDescElement(generalDesc, element, NO_INTERNATIONAL_DIALLING, liteBuild)); metadata.setSameMobileAndFixedLinePattern( metadata.getMobile().getNationalNumberPattern().Equals( metadata.getFixedLine().getNationalNumberPattern())); } else { // Set fields used only by short numbers. metadata.setStandardRate( processPhoneNumberDescElement(generalDesc, element, STANDARD_RATE, liteBuild)); metadata.setShortCode( processPhoneNumberDescElement(generalDesc, element, SHORT_CODE, liteBuild)); metadata.setCarrierSpecific( processPhoneNumberDescElement(generalDesc, element, CARRIER_SPECIFIC, liteBuild)); metadata.setEmergency( processPhoneNumberDescElement(generalDesc, element, EMERGENCY, liteBuild)); } // Set fields used by both regular length and short numbers. metadata.setTollFree( processPhoneNumberDescElement(generalDesc, element, TOLL_FREE, liteBuild)); metadata.setPremiumRate( processPhoneNumberDescElement(generalDesc, element, PREMIUM_RATE, liteBuild)); }
public void TestProcessPhoneNumberDescElementOverridesGeneralDesc() { PhoneNumberDesc generalDesc = new PhoneNumberDesc.Builder() .SetPossibleNumberPattern("\\d{8}").Build(); String xmlInput = "<territory><fixedLine>" + " <possibleNumberPattern>\\d{6}</possibleNumberPattern>" + "</fixedLine></territory>"; XElement territoryElement = parseXmlString(xmlInput); var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine", false); Assert.Equal("\\d{6}", phoneNumberDesc.PossibleNumberPattern); }
public void TestProcessPhoneNumberDescElementOverridesGeneralDesc() { var generalDesc = new PhoneNumberDesc.Builder() .SetNationalNumberPattern("\\d{8}").Build(); var xmlInput = "<territory><fixedLine>" + " <nationalNumberPattern>\\d{6}</nationalNumberPattern>" + "</fixedLine></territory>"; var territoryElement = ParseXmlString(xmlInput); var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine"); Assert.Equal("\\d{6}", phoneNumberDesc.NationalNumberPattern); }
[TestMethod] public void testProcessPhoneNumberDescRemovesWhiteSpacesInPatterns() { PhoneNumberDesc.Builder generalDesc = PhoneNumberDesc.newBuilder(); String xmlInput = "<territory><fixedLine>" + " <possibleNumberPattern>\t \\d { 6 } </possibleNumberPattern>" + "</fixedLine></territory>"; XmlElement countryElement = parseXmlString(xmlInput); PhoneNumberDesc.Builder phoneNumberDesc; phoneNumberDesc = BuildMetadataFromXml.processPhoneNumberDescElement( generalDesc, countryElement, "fixedLine", false); Assert.AreEqual("\\d{6}", phoneNumberDesc.getPossibleNumberPattern()); }
[TestMethod] public void testProcessPhoneNumberDescOutputsExampleNumberByDefault() { PhoneNumberDesc.Builder generalDesc = PhoneNumberDesc.newBuilder(); String xmlInput = "<territory><fixedLine>" + " <exampleNumber>01 01 01 01</exampleNumber>" + "</fixedLine></territory>"; XmlElement territoryElement = parseXmlString(xmlInput); PhoneNumberDesc.Builder phoneNumberDesc; phoneNumberDesc = BuildMetadataFromXml.processPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine", false); Assert.AreEqual("01 01 01 01", phoneNumberDesc.getExampleNumber()); }
/** * Processes a phone number description element from the XML file and returns it as a * PhoneNumberDesc. If the description element is a fixed line or mobile number, the general * description will be used to fill in the whole element if necessary, or any components that are * missing. For all other types, the general description will only be used to fill in missing * components if the type has a partial definition. For example, if no "tollFree" element exists, * we assume there are no toll free numbers for that locale, and return a phone number description * with "NA" for both the national and possible number patterns. * * @param generalDesc a generic phone number description that will be used to fill in missing * parts of the description * @param countryXmlElement the XML element representing all the country information * @param numberType the name of the number type, corresponding to the appropriate tag in the XML * file with information about that type * @return complete description of that phone number type */ // @VisibleForTesting internal static PhoneNumberDesc.Builder processPhoneNumberDescElement(PhoneNumberDesc.Builder generalDesc, XmlElement countryXmlElement, String numberType, bool liteBuild) { var phoneNumberDescList = countryXmlElement.GetElementsByTagName(numberType); PhoneNumberDesc.Builder numberDesc = PhoneNumberDesc.newBuilder(); if (phoneNumberDescList.Count == 0 && !isValidNumberType(numberType)) { numberDesc.setNationalNumberPattern("NA"); numberDesc.setPossibleNumberPattern("NA"); return(numberDesc); } numberDesc.mergeFrom(generalDesc.build()); if (phoneNumberDescList.Count > 0) { XmlElement element = (XmlElement)phoneNumberDescList.Item(0); var possiblePattern = element.GetElementsByTagName(POSSIBLE_NUMBER_PATTERN); if (possiblePattern.Count > 0) { numberDesc.setPossibleNumberPattern( validateRE(possiblePattern.Item(0).FirstChild.Value, true)); } var validPattern = element.GetElementsByTagName(NATIONAL_NUMBER_PATTERN); if (validPattern.Count > 0) { numberDesc.setNationalNumberPattern( validateRE(validPattern.Item(0).FirstChild.Value, true)); } if (!liteBuild) { var exampleNumber = element.GetElementsByTagName(EXAMPLE_NUMBER); if (exampleNumber.Count > 0) { numberDesc.setExampleNumber(exampleNumber.Item(0).FirstChild.Value); } } } return(numberDesc); }
private static PhoneNumberDesc GetFakeArmeniaPhoneNumberDesc(bool generalDesc) { var desc = new PhoneNumberDesc.Builder().SetNationalNumberPattern(NATIONAL_NUMBER_PATTERN); if (!generalDesc) { desc.SetExampleNumber(EXAMPLE_NUMBER); } foreach (var i in PossibleLengths) { desc.AddPossibleLength(i); } foreach (var i in PossibleLengthsLocalOnly) { desc.AddPossibleLengthLocalOnly(i); } return(desc.Build()); }
public void TestProcessPhoneNumberDescElementOverridesGeneralDesc() { PhoneNumberDesc generalDesc = new PhoneNumberDesc.Builder() .SetPossibleNumberPattern("\\d{8}").Build(); String xmlInput = "<territory><fixedLine>" + " <possibleNumberPattern>\\d{6}</possibleNumberPattern>" + "</fixedLine></territory>"; XElement territoryElement = parseXmlString(xmlInput); var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine", false); Assert.AreEqual("\\d{6}", phoneNumberDesc.PossibleNumberPattern); }
public void TestProcessPhoneNumberDescElementMergesWithGeneralDesc() { PhoneNumberDesc generalDesc = new PhoneNumberDesc.Builder() .SetPossibleNumberPattern("\\d{6}").Build(); XElement territoryElement = parseXmlString("<territory><fixedLine/></territory>"); var phoneNumberDesc = BuildMetadataFromXml.ProcessPhoneNumberDescElement( generalDesc, territoryElement, "fixedLine", false); Assert.AreEqual("\\d{6}", phoneNumberDesc.PossibleNumberPattern); }