public void AddAPIFromXMLAndAvoidDuplicateNodesTest() { //Arrange string XmlfFilePath = TestResources.GetTestResourcesFile(@"XML\createPaymentRequest2.xml"); ObservableList <ApplicationAPIModel> AAMTempList = new ObservableList <ApplicationAPIModel>(); XmlDocument doc = new XmlDocument(); List <XMLDocExtended> xmlElements = new List <XMLDocExtended>(); List <XMLDocExtended> xmlElementsAvoidDuplicatesNodes = new List <XMLDocExtended>(); List <AppModelParameter> AppModelParameters = new List <AppModelParameter>(); List <AppModelParameter> AppModelParametersAvoidNodes = new List <AppModelParameter>(); //Act AAMTempList = new XMLTemplateParser().ParseDocument(XmlfFilePath, AAMTempList, false); doc.LoadXml(AAMTempList[0].RequestBody); xmlElements = new XMLDocExtended(doc).GetAllNodes().Where(x => x.Name == "tag").ToList(); AppModelParameters = AAMTempList[0].AppModelParameters.Where(x => x.TagName == "tag").ToList(); AAMTempList = new XMLTemplateParser().ParseDocument(XmlfFilePath, AAMTempList, true); doc.LoadXml(AAMTempList[0].RequestBody); xmlElementsAvoidDuplicatesNodes = new XMLDocExtended(doc).GetAllNodes().Where(x => x.Name == "tag").ToList(); AppModelParametersAvoidNodes = AAMTempList[0].AppModelParameters.Where(x => x.TagName == "tag").ToList(); //Assert Assert.AreEqual(xmlElements.Count, 4); Assert.AreEqual(xmlElementsAvoidDuplicatesNodes.Count, 1); Assert.AreEqual(AppModelParameters.Count, 4); Assert.AreEqual(AppModelParametersAvoidNodes.Count, 1); }
private async Task <bool> ShowXMLTemplatesOperations() { bool parseSuccess = true; AddAPIModelWizard.ProcessStarted(); XMLTemplateParser WSDLP = new XMLTemplateParser(); ObservableList <ApplicationAPIModel> AAMTempList = new ObservableList <ApplicationAPIModel>(); ObservableList <ApplicationAPIModel> AAMCompletedList = new ObservableList <ApplicationAPIModel>(); foreach (TemplateFile XTF in AddAPIModelWizard.XTFList) { try { AAMTempList = await Task.Run(() => WSDLP.ParseDocument(XTF.FilePath, AAMCompletedList, AddAPIModelWizard.AvoidDuplicatesNodes)); if (!string.IsNullOrEmpty(XTF.MatchingResponseFilePath)) { AAMTempList.Last().ReturnValues = await Task.Run(() => APIConfigurationsDocumentParserBase.ParseResponseSampleIntoReturnValuesPerFileType(XTF.MatchingResponseFilePath)); } } catch (Exception ex) { Reporter.ToUser(eUserMsgKey.ParsingError, "Failed to Parse the XML" + XTF.FilePath); Reporter.ToLog(eLogLevel.ERROR, "Error Details: " + ex.Message + "Failed to Parse the XML" + XTF.FilePath); parseSuccess = false; } } AddAPIModelWizard.LearnedAPIModelsList = AAMCompletedList; xApisSelectionGrid.DataSourceList = AddAPIModelWizard.LearnedAPIModelsList; AddAPIModelWizard.ProcessEnded(); return(parseSuccess); }
public void XMLTemplateParesrCreatePaymentProfile() { //Arrange XMLTemplateParser xMLTemplateParser = new XMLTemplateParser(); string createPaymentProfileFileName = TestResources.GetTestResourcesFile(@"AutoPilot\XMLTemplates\bankCode.xml"); //Act ObservableList <ApplicationAPIModel> createPaymentProfileModels = new ObservableList <ApplicationAPIModel>(); xMLTemplateParser.ParseDocument(createPaymentProfileFileName, createPaymentProfileModels); TemplateFile TempleteFile = new TemplateFile() { FilePath = createPaymentProfileFileName }; createPaymentProfileModels[0].OptionalValuesTemplates.Add(TempleteFile); Dictionary <Tuple <string, string>, List <string> > OptionalValuesPerParameterDict = new Dictionary <Tuple <string, string>, List <string> >(); ImportOptionalValuesForParameters ImportOptionalValues = new ImportOptionalValuesForParameters(); ImportOptionalValues.ShowMessage = false; ImportOptionalValues.GetAllOptionalValuesFromExamplesFiles(createPaymentProfileModels[0], OptionalValuesPerParameterDict); ImportOptionalValues.PopulateOptionalValuesForAPIParameters(createPaymentProfileModels[0], OptionalValuesPerParameterDict); //Assert Assert.AreEqual(createPaymentProfileModels.Count, 1, "APIModels count"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters.Count, 1, "AppModelParameters count"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[0].PlaceHolder, "{BLZ}", "PlaceHolder name check"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[0].OptionalValuesList.Count, 1, "AppModelParameters count"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[0].OptionalValuesList[0].Value, "46451012", "OptionalValue check"); }
/// <summary> /// This method will parse the request body and add the app parameters to model /// </summary> /// <param name="aPIModel"></param> /// <param name="act"></param> /// <param name="parameterizeRequestBody"></param> private void ParameterizeApiModellBody(ApplicationAPIModel aPIModel, Act act, bool parameterizeRequestBody) { ObservableList <ActInputValue> actInputs = ((ActWebAPIBase)act).DynamicElements; if (actInputs == null || actInputs.Count == 0) { string requestBody = string.Empty; if (aPIModel.RequestBodyType == ApplicationAPIUtils.eRequestBodyType.TemplateFile) { string fileUri = WorkSpace.Instance.SolutionRepository.ConvertSolutionRelativePath(aPIModel.TemplateFileNameFileBrowser); if (File.Exists(fileUri)) { aPIModel.RequestBody = System.IO.File.ReadAllText(fileUri); aPIModel.RequestBodyType = ApplicationAPIUtils.eRequestBodyType.FreeText; } } if (!string.IsNullOrEmpty(aPIModel.RequestBody)) { requestBody = aPIModel.RequestBody; } if (!string.IsNullOrEmpty(requestBody)) { ObservableList <ApplicationAPIModel> applicationAPIModels = new ObservableList <ApplicationAPIModel>(); if (aPIModel.RequestBody.StartsWith("{"))//TODO: find better way to identify JSON format { JSONTemplateParser jsonTemplate = new JSONTemplateParser(); jsonTemplate.ParseDocumentWithJsonContent(requestBody, applicationAPIModels); } else if (aPIModel.RequestBody.StartsWith("<"))//TODO: find better way to identify XML format { XMLTemplateParser parser = new XMLTemplateParser(); parser.ParseDocumentWithXMLContent(requestBody, applicationAPIModels); } if (applicationAPIModels[0].AppModelParameters != null && applicationAPIModels[0].AppModelParameters.Count > 0) { aPIModel.RequestBody = applicationAPIModels[0].RequestBody; aPIModel.AppModelParameters = applicationAPIModels[0].AppModelParameters; } } } else { aPIModel.AppModelParameters = ParseParametersFromRequestBodyInputs(aPIModel, actInputs); } }
private bool CheckForXmlParser(string fileName) { try { XMLTemplateParser xmlParser = new XMLTemplateParser(); ObservableList <ApplicationAPIModel> xmlList = new ObservableList <ApplicationAPIModel>(); xmlList = xmlParser.ParseDocument(fileName, xmlList); if (xmlList == null || xmlList.Count == 0) { return(false); } return(true); } catch (Exception ex) { Reporter.ToLog(eLogLevel.WARN, ex.Message, ex); return(false); } }
private ObservableList <AppModelParameter> GenerateXMLBody(ApplicationAPIModel aAM, JsonSchema4 operation) { string SampleBody = JsonSchemaTools.JsonSchemaFaker(operation, true); string XMlName = operation.HasReference? XMlName = operation.Reference.Xml.Name: XMlName = operation.Xml.Name; SampleBody = "{\"" + XMlName + "\":" + SampleBody + "}"; string s2 = SampleBody; string xmlbody = JsonConvert.DeserializeXmlNode(SampleBody).OuterXml; string temppath = System.IO.Path.GetTempFileName(); File.WriteAllText(temppath, xmlbody); XMLTemplateParser XTp = new XMLTemplateParser(); ApplicationAPIModel aam = XTp.ParseDocument(temppath).ElementAt(0); object[] BodyandModelParameters = JSONTemplateParser.GenerateBodyANdModelParameters(SampleBody); aAM.RequestBody = aam.RequestBody; aAM.RequestBodyType = ApplicationAPIUtils.eRequestBodyType.FreeText; aam.ContentType = ApplicationAPIUtils.eContentType.XML; return(aam.AppModelParameters); }
private async Task <bool> ShowXMLTemplatesOperations() { bool parseSuccess = true; AddAPIModelWizard.ProcessStarted(); XMLTemplateParser WSDLP = new XMLTemplateParser(); ObservableList <ApplicationAPIModel> AAMTempList = new ObservableList <ApplicationAPIModel>(); ObservableList <ApplicationAPIModel> AAMCompletedList = new ObservableList <ApplicationAPIModel>(); foreach (TemplateFile XTF in AddAPIModelWizard.XTFList) { try { AAMTempList = await Task.Run(() => WSDLP.ParseDocument(XTF.FilePath, AddAPIModelWizard.AvoidDuplicatesNodes)); if (!string.IsNullOrEmpty(XTF.MatchingResponseFilePath)) { AAMTempList[0].ReturnValues = await Task.Run(() => APIConfigurationsDocumentParserBase.ParseResponseSampleIntoReturnValuesPerFileType(XTF.MatchingResponseFilePath)); } AAMCompletedList.Add(AAMTempList[0]); } catch (Exception ex) { MessageBox.Show("Error Details:" + Environment.NewLine + ex.Message, "Failed to Parse the XML" + XTF.FilePath, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error, System.Windows.MessageBoxResult.None); GingerCoreNET.ReporterLib.Reporter.ToLog(GingerCoreNET.ReporterLib.eLogLevel.ERROR, "Error Details: " + ex.Message + "Failed to Parse the XML" + XTF.FilePath); parseSuccess = false; } } AddAPIModelWizard.AAMList = AAMCompletedList; xApisSelectionGrid.DataSourceList = AddAPIModelWizard.AAMList; // AddAPIModelWizard.FinishEnabled = false; AddAPIModelWizard.ProcessEnded(); return(parseSuccess); }