Beispiel #1
0
        private ObservableList <AppModelParameter> GenerateJsonBody(ApplicationAPIModel aAM, JsonSchema4 operation)
        {
            string SampleBody = JsonSchemaTools.JsonSchemaFaker(operation);

            object[] BodyandModelParameters = JSONTemplateParser.GenerateBodyANdModelParameters(SampleBody);
            aAM.RequestBody = (string)BodyandModelParameters[0];
            return((ObservableList <AppModelParameter>)BodyandModelParameters[1]);
        }
        public static ObservableList <ActReturnValue> ParseResponseSampleIntoReturnValuesPerFileType(string FilePath)
        {
            string fileContent = System.IO.File.ReadAllText(FilePath);

            if (IsValidJson(fileContent))
            {
                return(JSONTemplateParser.ParseJSONResponseSampleIntoReturnValues(fileContent));
            }
            else if (IsValidXML(fileContent))
            {
                return(XMLTemplateParser.ParseXMLResponseSampleIntoReturnValues(fileContent));
            }
            return(null);
        }
        /// <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 CheckForJsonParser(string fileName)
 {
     try
     {
         JSONTemplateParser jsonParser = new JSONTemplateParser();
         ObservableList <ApplicationAPIModel> jsonList = new ObservableList <ApplicationAPIModel>();
         jsonList = jsonParser.ParseDocument(fileName, jsonList);
         if (jsonList == null || jsonList.Count == 0)
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Reporter.ToLog(eLogLevel.WARN, ex.Message, ex);
         return(false);
     }
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        private void TestToOutput(SoapUIUtils soapUIUtils, Act act)
        {
            Dictionary <string, List <string> > dict = new Dictionary <string, List <string> >();

            dict = soapUIUtils.RequestsAndResponds();
            foreach (KeyValuePair <string, List <string> > kpr in dict)
            {
                if (!string.IsNullOrEmpty(kpr.Value[1]))
                {
                    string requestQouteFixed = kpr.Value[1].Replace("\"", "");
                    requestQouteFixed = requestQouteFixed.Replace("\0", "");
                    act.AddOrUpdateReturnParamActual(kpr.Value[0] + "-Request", requestQouteFixed);
                }
                if (!string.IsNullOrEmpty(kpr.Value[2]))
                {
                    string responseQouteFixed = string.Empty;

                    //if response is JSON format then not replace double quotes
                    if (kpr.Value[2].IndexOf("{") > -1)
                    {
                        responseQouteFixed = kpr.Value[2];
                    }
                    else
                    {
                        responseQouteFixed = kpr.Value[2].Replace("\"", "");
                    }


                    responseQouteFixed = responseQouteFixed.Replace("\0", "");

                    act.AddOrUpdateReturnParamActual(kpr.Value[0] + "-Response", responseQouteFixed);
                    if (((ActSoapUI)act).AddXMLResponse_Value)
                    {
                        string fileContent = kpr.Value[2];
                        ObservableList <ActReturnValue> ReturnValues = null;
                        if (APIConfigurationsDocumentParserBase.IsValidJson(fileContent))
                        {
                            ReturnValues = JSONTemplateParser.ParseJSONResponseSampleIntoReturnValues(fileContent);
                            foreach (ActReturnValue ReturnValue in ReturnValues)
                            {
                                act.ReturnValues.Add(ReturnValue);
                            }
                        }
                        else if (APIConfigurationsDocumentParserBase.IsValidXML(fileContent))
                        {
                            XmlDocument xmlDoc1 = new XmlDocument();
                            xmlDoc1.LoadXml(kpr.Value[2]);

                            List <GingerCore.General.XmlNodeItem> outputTagsList1 = new List <GingerCore.General.XmlNodeItem>();
                            outputTagsList1 = General.GetXMLNodesItems(xmlDoc1);
                            foreach (GingerCore.General.XmlNodeItem outputItem in outputTagsList1)
                            {
                                act.AddOrUpdateReturnParamActualWithPath(outputItem.param, outputItem.value, outputItem.path);
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(kpr.Value[4]))
                {
                    string messageQouteFixed = kpr.Value[4].Replace("\"", "");
                    messageQouteFixed = messageQouteFixed.Replace("\0", "");
                    act.AddOrUpdateReturnParamActual(kpr.Value[0] + "-Message", kpr.Value[4]);
                }
                if (!string.IsNullOrEmpty(kpr.Value[5]))
                {
                    string propertiesQouteFixed = kpr.Value[4].Replace("\"", "");
                    propertiesQouteFixed = propertiesQouteFixed.Replace("\0", "");
                    act.AddOrUpdateReturnParamActual(kpr.Value[0] + "-Properties", kpr.Value[5]);
                }
            }

            Dictionary <List <string>, List <string> > dictValues = new Dictionary <List <string>, List <string> >();

            dictValues = soapUIUtils.OutputParamAndValues();
            foreach (KeyValuePair <List <string>, List <string> > Kpr in dictValues)
            {
                int index = 0;
                if (Kpr.Key.Count() != 0 && Kpr.Value.Count() != 0)
                {
                    foreach (string property in Kpr.Key)
                    {
                        act.AddOrUpdateReturnParamActual(Kpr.Key[index], Kpr.Value[index]);
                        index++;
                    }
                }
            }
        }