Пример #1
0
        /// <summary>
        /// Sets basic authentication properties such as type, username, password and pre-authenticate in API module
        /// </summary>
        /// <param name="apiTestStep">returns module of apiTeststep</param>
        /// <param name="wseTestStep">returns username, password, preauthenticate information of wseTestStep</param>
        public void Execute(XTestStep apiTestStep, XTestStep wseTestStep)
        {
            try {
                FileLogger.Instance.Info("Inside Basic Auth Credentials Migrator");
                string userName        = GetWseUsernameValue(wseTestStep);
                string password        = GetWsePasswordValue(wseTestStep);
                string preAuthenticate = GetWsePreAuthenticateValue(wseTestStep);
                if (!string.IsNullOrEmpty(userName) || !string.IsNullOrEmpty(password) ||
                    !string.IsNullOrEmpty(preAuthenticate))
                {
                    ApiModule apiModule = (ApiModule)apiTestStep.Module;
                    apiModule.AddXParamToModuleAttribute("AuthenticationType", "Basic", ParamTypeE.TechnicalID);
                    apiModule.AddXParamToModuleAttribute("Username", userName, ParamTypeE.TechnicalID);
                    apiModule.AddXParamToModuleAttribute("Password", password, ParamTypeE.TechnicalID);
                    apiModule.AddXParamToModuleAttribute("PreAuthenticate",
                                                         preAuthenticate == "Yes" ? "true" : "false",
                                                         ParamTypeE.TechnicalID);
                }

                FileLogger.Instance.Info("Complete Basic Auth Credentials Migrator");
            }
            catch (Exception ex) {
                FileLogger.Instance.Error(
                    $"Error occurred while migration of Auth Credentials for WSE TestStep : 'Name: {wseTestStep?.Name}' NodePath:'{wseTestStep?.NodePath}' Exception:'{ex.ToString()}'");
            }
        }
        private (ApiModule requestApiModule, ApiModule responseApiModule) GetExistingOrCreateNewApiModulePair(
            TCObject objectToExecuteOn,
            XTestStep wseTestStep,
            IWseArtifactsParser wseParser)
        {
            ApiModule requestApiModule  = null;
            ApiModule responseApiModule = null;

            if (!IsModuleSearchCriteriaEmpty(wseParser))
            {
                (requestApiModule, responseApiModule) =
                    CommonUtilities.SearchExistingApiModule(objectToExecuteOn, wseParser, wseTestStep);
            }

            if (requestApiModule != null)
            {
                return(requestApiModule, responseApiModule);
            }

            FolderStructureHandler folderStructureHandler = new FolderStructureHandler();

            (TCFolder apiModuleFolder, string moduleName) =
                folderStructureHandler.CreateFolderForApiModules(objectToExecuteOn, wseTestStep, wseParser);
            return(ApiModuleHandler.CreateApiModulePair(apiModuleFolder, moduleName, wseParser));
        }
        /// <summary>
        /// Creates and set Body Param at request and response module and teststeps.
        /// </summary>
        /// <param name="apiTestStep">Teststep of ApiEngine</param>
        /// <param name="wseTestStepValues">Teststepvalues of WseEngine</param>
        public static void CreateBodyParameterForRequestAndResponse(XTestStep apiTestStep,
                                                                    List <XTestStepValue> wseTestStepValues)
        {
            if (!wseTestStepValues.Any())
            {
                return;
            }

            XModuleAttribute bodyXModuleAttribute = (XModuleAttribute)
                                                    apiTestStep.Module.Search(
                "=>SUBPARTS:XModuleAttribute[Name==\"Body\" and Path==\"Body\" and PathType==\"Body\"]")
                                                    .FirstOrDefault();

            if (bodyXModuleAttribute == null)
            {
                bodyXModuleAttribute = (apiTestStep.Module as ApiModule).CreateModuleAttribute("Body",
                                                                                               string.Empty,
                                                                                               string.Empty,
                                                                                               "Body",
                                                                                               "Body",
                                                                                               XTestStepActionMode
                                                                                               .Select,
                                                                                               ModuleAttributeDataType
                                                                                               .String);
                bodyXModuleAttribute.Cardinality = "0-N";
            }

            CreateBodyParameterAtTeststepLevel(wseTestStepValues, bodyXModuleAttribute, apiTestStep);
        }
Пример #4
0
        /// <summary>
        /// Parse WSE XTestStep to get data.
        /// </summary>
        /// <param name="xTestStep">WSE XTestStep</param>
        /// <param name="payloadParser">XML or Json Payload Parser.
        /// The request payload is extracted from XTestStep.
        /// The response paylod is extracted from Module.
        /// </param>
        public void Parse(XTestStep xTestStep, IPayloadParser payloadParser)
        {
            try {
                var methodParser = new MethodParser();
                Method = methodParser.Parse(xTestStep);

                var addressParser = new AddressParser();
                AddressParserResult addressParserResult = addressParser.Parse(xTestStep);
                Endpoint    = addressParserResult.Endpoint;
                Resource    = addressParserResult.Resource;
                QueryParams = addressParserResult.QueryParams;

                var headerParser = new HeaderParser();
                Headers         = headerParser.Parse(xTestStep, AddOnConstants.TestStepRequestHeadersTql);
                Headers         = CommonUtilities.ModifyContentTypeToEmpty(Headers);
                ResponseHeaders = headerParser.Parse(xTestStep, AddOnConstants.TestStepResponseHeadersTql);

                var statusCodeParser = new StatusCodeParser();
                ResponseStatus = statusCodeParser.ParseResponseStatus(xTestStep);

                RequestPayload = payloadParser.Parse(xTestStep,
                                                     "=>SUBPARTS:XTestStepValue[Name==\"Request\"]->SUBPARTS:XTestStepValue");
                ResponsePayload = payloadParser.Parse(xTestStep.Module, AddOnConstants.ResponsePayloadTql);
                HashCode        = GetHashCode(xTestStep);
            }
            catch (Exception e) {
                FileLogger.Instance.Error(e);
            }
        }
        private XTestStepValue GetOrCreateApiXTestStepValue(XTestStep apiTestStep,
                                                            KeyValuePair <string, string> wseTestStepValue)
        {
            XTestStepValue apiTeststepValue =
                (XTestStepValue)apiTestStep
                .Search(string.Format(TqlToGetApiTestStepValue, wseTestStepValue.Key))
                .FirstOrDefault();

            //if xTestStepValue not present,create it.
            if (apiTeststepValue == null)
            {
                //check if module attribute is present.
                var xModuleAttribute =
                    (XModuleAttribute)apiTestStep
                    .Module.Search(
                        string.Format(TqlToGetModuleAttributeInApiModule,
                                      wseTestStepValue.Key)).FirstOrDefault();
                //if not present, Create it.
                if (xModuleAttribute == null)
                {
                    XModuleAttribute m =
                        CreateModuleAttribute(apiTestStep.Module as ApiModule, wseTestStepValue);
                    apiTeststepValue = apiTestStep.CreateXTestStepValue(m);
                }
                //if already present, use it.
                else
                {
                    apiTeststepValue = apiTestStep.CreateXTestStepValue(xModuleAttribute);
                }
            }

            return(apiTeststepValue);
        }
Пример #6
0
        /// <summary>
        /// Create API Modules Folder Name on the basis of SoapAction, Resource, Endpoint and Method(HttpVerbs)
        /// </summary>
        /// <param name="xTestStep">Wse Teststep</param>
        /// <param name="parserResult">Contains transport info(Endpoint, Method, Resource, Headers)</param>
        /// <returns>FolderName</returns>
        public static string CreateModuleFolderName(XTestStep xTestStep, IWseArtifactsParser parserResult)
        {
            try {
                var soapAction = GetSoapAction(parserResult.Headers);

                if (!string.IsNullOrEmpty(soapAction))
                {
                    var action = soapAction.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                    if (!string.IsNullOrEmpty(action))
                    {
                        return(AppendMethod(action, parserResult.Method));
                    }
                }

                if (!string.IsNullOrEmpty(parserResult.Resource))
                {
                    return(AppendMethod(parserResult.Resource, parserResult.Method));
                }

                if (!string.IsNullOrEmpty(parserResult.Endpoint))
                {
                    return(AppendMethod(parserResult.Endpoint, parserResult.Method));
                }
            }
            catch (Exception) {
                // ignored
            }

            return("UnknownResource");
        }
Пример #7
0
        /// <summary>
        /// Get WseTestSteps on the basis of TQL
        /// </summary>
        /// <param name="rootComponentFolder">Component Folder on which migration is executing</param>
        /// <param name="wseModuleTestSteps">WSE XTestSteps</param>
        /// <returns>List of WSE XTesSteps</returns>
        public static List <XTestStep> GetFilteredWseTestSteps(TCObject rootComponentFolder,
                                                               IEnumerable <XTestStep> wseModuleTestSteps)
        {
            var list = new List <XTestStep>();

            foreach (XTestStep testStep in wseModuleTestSteps)
            {
                try {
                    XTestStep xtestStep = (XTestStep)rootComponentFolder
                                          .Search(
                        $"=>COMPLEMENT(=>UNION(=>SUBPARTS: XTestStep[UniqueId == \"{testStep.UniqueId}\"],=>SUBPARTS:TestStepFolderReference=>ReusedItem=>SUBPARTS:XTestStep[UniqueId == \"{testStep.UniqueId}\"]),=>SUBPARTS:TestCaseTemplateInstance=>SUBPARTS:XTestStep[UniqueId == \"{testStep.UniqueId}\"])")
                                          .FirstOrDefault();
                    if (xtestStep == null)
                    {
                        continue;
                    }
                    list.Add(xtestStep);
                }
                catch (Exception ex) {
                    FileLogger.Instance.Error("Failed to get WSETestStep", ex);
                }
            }

            return(list);
        }
        static void Main(string[] args)
        {
            using (TCAPI tcapi = TCAPI.CreateInstance())
            {
                TCWorkspace     workspace      = tcapi.OpenWorkspace(@"C:\Users\estan\Desktop\trainings\TOSCA Customizations\Tosca Workspace\Training Customizations\Training Customizations.tws", "Admin", "");
                TCProject       project        = workspace.GetProject();
                List <TCObject> result         = project.Search($"=>SUBPARTS:TCFolder[UniqueId==\"{unique_id_test_case_folder}\"]");
                TCFolder        testCaseFolder = (TCFolder)result.First();
                testCaseFolder.Checkout();

                TestCase testCase = testCaseFolder.CreateTestCase();
                testCase.Name = "Test Creating Test Case";

                XModule tboxSetBuffer = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_set_buffer}\"]").First();
                XModule tboxWait      = (XModule)project.Search($"=>SUBPARTS:XModule[UniqueId==\"{unique_id_tbox_wait}\"]").First();


                XTestStep      setBufferTestStep  = testCase.CreateXTestStepFromXModule(tboxSetBuffer);
                XTestStepValue setBUfferStepvalue = setBufferTestStep.CreateXTestStepValue(tboxSetBuffer.Attributes.First());
                setBUfferStepvalue.Name       = "Test Buffer Creation";
                setBUfferStepvalue.Value      = "42";
                setBUfferStepvalue.ActionMode = XTestStepActionMode.Input;

                XTestStep      tboxSetWaitTimeStep      = testCase.CreateXTestStepFromXModule(tboxWait);
                XTestStepValue tboxWaitSettimeStepValue = tboxSetWaitTimeStep.TestStepValues.First();
                tboxWaitSettimeStepValue.Value = "500";
            }
        }
        /// <summary>
        /// Handles response data in Xml/JSON Resource specialization
        /// </summary>
        /// <param name="wseTestStep">TestStep of WSE Artifacts</param>
        /// <param name="apiTestStep">TestStep of API Engine Artifacts</param>
        /// <param name="payloadParser">Parse xml and json payload from Wse XModules and TestSteps</param>
        /// <param name="payloadSetterFactory">Create module attributes and Set values for payload in for Api artifacts </param>
        public override void HandleSpecialization(XTestStep wseTestStep,
                                                  XTestStep apiTestStep,
                                                  IPayloadParser payloadParser,
                                                  IPayloadSetterFactory payloadSetterFactory)
        {
            XModule specializationModule =
                (XModule)wseTestStep.Search(TqlToGetWseTestStepSpecializationModule)?.FirstOrDefault();

            if (specializationModule != null)
            {
                try {
                    var wseTestStepValue =
                        (XTestStepValue)wseTestStep.Search(TqlToGetWseTestStepValue)?.FirstOrDefault();
                    if (wseTestStepValue != null && !StringExtensions.IsNullOrBlankInTosca(wseTestStepValue.Value))
                    {
                        TestCase testCase = (TestCase)wseTestStep.Search(TqlToSearchTestCase)?.FirstOrDefault();

                        if (testCase != null)
                        {
                            ResourceManagerHandler.AddResourceToResourceId(testCase.Name, wseTestStepValue.Value);
                        }
                    }
                }
                catch (Exception ex) {
                    FileLogger.Instance.Error("Unable to fetch WSE tesstep value ", ex);
                }
            }
            else
            {
                successor?.HandleSpecialization(wseTestStep, apiTestStep, payloadParser, payloadSetterFactory);
            }
        }
        /// <summary>
        /// Parses WSE XTestStep to get payload
        /// </summary>
        /// <param name="xTestStep">WSE XTestStep</param>
        /// <param name="tql">tql to get root json object from request/reponse object</param>
        /// <returns>payload</returns>
        public string Parse(XTestStep xTestStep, string tql = "")
        {
            try {
                if (xTestStep == null)
                {
                    return(string.Empty);
                }
                XTestStepValue jsonObject = xTestStep.Search(tql).Cast <XTestStepValue>().FirstOrDefault(
                    x => x.ModuleAttribute.BusinessType
                    == "JsonObject" ||
                    x.ModuleAttribute.BusinessType == "JsonArray");

                if (jsonObject != null)
                {
                    JArray  arrayObject = new JArray();
                    JObject plainObject = CommonUtilities.ConstructJsonStructure(jsonObject, new JObject());
                    if (jsonObject.ModuleAttribute.BusinessType == "JsonObject")
                    {
                        return(Convert.ToString(plainObject));
                    }

                    arrayObject.Add(plainObject.Values());
                    return(Convert.ToString(arrayObject));
                }
            }
            catch (Exception e) {
                FileLogger.Instance.Error(
                    $"Failed to create Json payload for request :{xTestStep?.Name}",
                    e);
            }

            return(string.Empty);
        }
        /// <summary>
        /// Fills XML payload using recursive call to method
        /// </summary>
        /// <param name="tcObjects">XML payload testStepValues</param>
        /// <param name="apiTestStep">apiTestStep</param>
        /// <param name="wseTestStep">wseTestStep</param>
        /// <param name="xPath">xpTah</param>
        /// <param name="parent">xModule and xModuleAttribute of API</param>
        /// <param name="parentTest">XTestStep and xTestStepValue of ApiTesstep</param>
        public virtual void FillPayloadInternal(IEnumerable <XTestStepValue> tcObjects,
                                                XTestStep apiTestStep,
                                                XTestStep wseTestStep,
                                                string xPath,
                                                dynamic parent,
                                                dynamic parentTest)
        {
            XTestStepValue wseTestStepValue = null;
            string         tXpathFormat     = "/*[local-name()='{0}']";

            if (!tcObjects.Any())
            {
                return;
            }
            var firstObject = tcObjects.First();
            var lastObject  = tcObjects.Last();

            foreach (var tcObject in tcObjects.Where(x => x.ModuleAttribute.BusinessType == "XmlElement"))
            {
                bool isArray = false;
                try {
                    wseTestStepValue = tcObject;
                    string currXpath;
                    if (firstObject.Name == lastObject.Name && !ReferenceEquals(firstObject, lastObject))
                    {
                        currXpath = xPath + string.Format(tXpathFormat,
                                                          wseTestStepValue.Name);
                        isArray = true;
                    }
                    else
                    {
                        currXpath = xPath + string.Format(tXpathFormat, wseTestStepValue.Name);
                    }

                    XTestStepValue apiTestStepValue = CreateModuleAttributeForPayload(wseTestStepValue,
                                                                                      currXpath,
                                                                                      parent,
                                                                                      (ApiModule)apiTestStep.Module,
                                                                                      parentTest,
                                                                                      wseTestStepValue
                                                                                      .ModuleAttribute
                                                                                      ?.Cardinality,
                                                                                      isArray
                                                                                      );
                    FillPayloadInternal(tcObject.SubValues,
                                        apiTestStep,
                                        wseTestStep,
                                        currXpath,
                                        apiTestStepValue.ModuleAttribute,
                                        apiTestStepValue);
                }
                catch (Exception ex) {
                    FileLogger.Instance.Error(
                        $"Error occurred while creating Business Parameter for WSE TestStep : 'Name: {wseTestStep?.Name}' NodePath:'{wseTestStep?.NodePath}' TestStepValue:'{wseTestStepValue?.Name}' Exception:'{ex.ToString()}'");
                }
            }
        }
        private void MoveBodyAttributeAtLast(XTestStep xTestStep)
        {
            var bodyAttribute = xTestStep.Module.Attributes.FirstOrDefault(x => x.Name == "Body");

            if (bodyAttribute != null)
            {
                xTestStep.Module.Move(bodyAttribute);
            }
        }
        /// <summary>
        /// Evaluates Json path of wseteststep values.
        /// </summary>
        /// <param name="wseTestStep">parent node of wseteststep</param>
        /// <param name="wseTestStepValue">node for which json path is to be evaluated</param>
        /// <param name="jsonPath">reform json path for static or dynamic payload</param>
        /// <returns></returns>
        public virtual string GetJsonPath(XTestStep wseTestStep, XTestStepValue wseTestStepValue, string jsonPath)
        {
            TCObject rootObject = wseTestStep
                                  .Search("=>SUBPARTS:XTestStepValue[Name==\"Response\"]->SUBPARTS")
                                  .FirstOrDefault();

            var rootObjectNodePath = rootObject?.NodePath;

            return(ExtractToscaJsonPath(rootObjectNodePath, wseTestStepValue, jsonPath));
        }
 private void FillPayload(XTestStep apiTestStep,
                          XTestStep wseTestStep)
 {
     try {
         var tcObjects = wseTestStep.Search(TqlToGetAllWseTestStepValue).Cast <XTestStepValue>().ToList();
         FillPayloadRec(apiTestStep, wseTestStep, tcObjects, apiTestStep.Module, apiTestStep, string.Empty);
     }
     catch (Exception ex) {
         FileLogger.Instance.Error("Unable to creation payload ", ex);
     }
 }
Пример #15
0
        /// <summary>
        /// Identify whether WSE XtestStepvalues(Request) is using Web service request data in JSON Resource specialization
        /// Identify whether WSE XtestStepvalues(Request) is using Web service request data in XML Resource specialization
        /// </summary>
        /// <param name="testStep">Wse TestStep</param>
        /// <param name="embeddedModule">Specialization Module for Request</param>
        /// <returns>true if xmodule is using specialization</returns>
        public static bool IsRequestIsUsingEmbeddedModule(XTestStep testStep, out XModule embeddedModule)
        {
            var name = "Request";
            var specializationModulesToExclude = new List <string>()
            {
                "Web service request data in JSON Resource",
                "Web service request data in XML Resource"
            };

            return(IsUsingEmbeddedModule(testStep, name, specializationModulesToExclude, out embeddedModule));
        }
Пример #16
0
        private static int GetHashCode(XTestStep xTestStep)
        {
            var stringBuilder = new StringBuilder();
            var treeObjects   = xTestStep.Search("=>SUBPARTS:XTestStepValue[Name==\"Request\"]=>SUBPARTS");

            foreach (var t in treeObjects)
            {
                stringBuilder.Append(t.DisplayedName);
            }

            return(stringBuilder.ToString().GetHashCode());
        }
        private void FillPayload(XTestStep apiTestStep,
                                 XTestStep wseTestStep)
        {
            var tcObjects = wseTestStep.Search(TqlToGetWseTestStepValue)
                            .Cast <XTestStepValue>().ToList();

            FillPayloadInternal(tcObjects,
                                apiTestStep,
                                wseTestStep,
                                string.Empty,
                                (ApiModule)apiTestStep.Module,
                                apiTestStep);
        }
Пример #18
0
        private static void CreateBodyParameterAtTeststepLevel(List <XTestStepValue> tcObjects,
                                                               XModuleAttribute bodyAttribute,
                                                               XTestStep apiTestStep)
        {
            foreach (XTestStepValue wseTestStepValue in tcObjects)
            {
                var apiTestStepValue = apiTestStep.CreateXTestStepValue(bodyAttribute);
                if (wseTestStepValue.SpecializationModule.Name == "Web service request data in XML Resource" ||
                    wseTestStepValue.SpecializationModule.Name == "Web service request data in JSON Resource")
                {
                    apiTestStepValue.DataType   = wseTestStepValue.DataType;
                    apiTestStepValue.ActionMode = XTestStepActionMode.Insert;
                    if (!wseTestStepValue.Value.IsNullOrBlankInTosca())
                    {
                        apiTestStepValue.Value = "{RES[" + wseTestStepValue.Value + "]}";
                    }

                    break;
                }

                if (wseTestStepValue.SpecializationModule.Name == "Plain Text")
                {
                    if (wseTestStepValue.SubValues != null && wseTestStepValue.SubValues.Any())
                    {
                        apiTestStepValue.DataType   = wseTestStepValue.SubValues.First().DataType;
                        apiTestStepValue.ActionMode = wseTestStepValue.SubValues.First().ActionMode;
                        //if (StringExtensions.IsNullOrBlank(wTestStepValue))
                        apiTestStepValue.Value =
                            wseTestStepValue.SubValues.FirstOrDefault(x => x.Name == "Value")?.Value;
                    }

                    if (!string.IsNullOrEmpty(apiTestStepValue.Value))
                    {
                        apiTestStepValue.Value = CommonUtilities.RemoveExtraDoubleQuotes(apiTestStepValue.Value);
                    }
                    break;
                }

                var wTestStepValue = wseTestStepValue.SubValues.FirstOrDefault(x => x.Name == "Filepath")?.Value;
                if (!wTestStepValue.IsNullOrBlankInTosca())
                {
                    apiTestStepValue.ActionProperty = $"File";
                    apiTestStepValue.Operator       = Operator.Equals;
                    apiTestStepValue.Value          = wTestStepValue;
                    apiTestStepValue.ActionMode     = XTestStepActionMode.Select;
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Gets payload from WSE TestStep
        /// </summary>
        /// <param name="xTestStep">WSE TestStep</param>
        /// <param name="tql">Tql to get root xml element from WSE Request or Response XTestStepValue</param>
        /// <returns></returns>
        public string Parse(XTestStep xTestStep, string tql = "")
        {
            if (xTestStep == null)
            {
                return(string.Empty);
            }
            try {
                var rootAttribute = xTestStep.Search(tql).Cast <XTestStepValue>().FirstOrDefault();
                return(Parse(rootAttribute));
            }
            catch (Exception) {
                // do nothing as this could happen possibly, just move on with the other attributes
            }

            return(string.Empty);
        }
 /// <summary>
 /// Create Body Parameter for Response API Modules for Transform Response WSE XTestStepValues
 /// </summary>
 /// <param name="apiTestStep">TestStep of API Engine</param>
 /// <param name="wseTestStep">TestStep of WSE Engine</param>
 public static void FillTransformResponse(XTestStep apiTestStep, XTestStep wseTestStep)
 {
     try {
         List <XTestStepValue> wseTestStepValues = wseTestStep
                                                   .Search(
             "=>SUBPARTS:XTestStepValue[Name==\"Transform response\"]=>SubValues[Name==\"Response transformation\"]")
                                                   .Where(x => x.DisplayedName
                                                          == "Response transformation: Save Response")
                                                   .Cast <XTestStepValue>()
                                                   .ToList();
         BodyParamHandler.CreateBodyParameterForRequestAndResponse(apiTestStep, wseTestStepValues);
     }
     catch (Exception) {
         //ignored
     }
 }
Пример #21
0
        private string GetTestStepValue(XTestStep wseTestStep, string searchString)
        {
            string value     = string.Empty;
            var    tcObjects = wseTestStep.Search(String.Format(TqlToGetWseAuthTestStepValue, searchString));

            foreach (var tcObject in tcObjects)
            {
                if (tcObject is XTestStepValue)
                {
                    var x = tcObject as XTestStepValue;
                    return(x.Value);
                }
            }

            return(value);
        }
Пример #22
0
        /// <summary>
        /// Get Request/Response API Module on the basis of scanTag.
        /// </summary>
        /// <param name="objectToExecuteOn">TcObjects</param>
        /// <param name="wseArtifactsParser">Contains Transport information</param>
        /// <param name="wseTestStep">WSE TestSteps</param>
        /// <returns>Request/Response API Module</returns>
        public static (ApiModule, ApiModule) SearchExistingApiModule(TCObject objectToExecuteOn,
                                                                     IWseArtifactsParser wseArtifactsParser,
                                                                     XTestStep wseTestStep)
        {
            if (SpecializationHelper.IsUsingEmbeddedResource(wseTestStep, out TCFolder searchFolder))
            {
                var requestModule  = SearchRequestModule(searchFolder, wseArtifactsParser);
                var responseModule = SearchResponseModule(searchFolder, wseArtifactsParser);
                if (requestModule != null)
                {
                    return(requestModule, responseModule);
                }
            }

            return(SearchRequestModule(objectToExecuteOn, wseArtifactsParser),
                   SearchResponseModule(objectToExecuteOn, wseArtifactsParser));
        }
Пример #23
0
        /// <summary>
        /// Extracts method from WSE TestStep
        /// </summary>
        /// <param name="xTestStep">WSE TestStep</param>
        /// <returns>HTTP Method</returns>
        public string Parse(XTestStep xTestStep)
        {
            try {
                XTestStepValue method =
                    (XTestStepValue)xTestStep.Search(AddOnConstants.TestStepMethodTql).FirstOrDefault();
                if (method == null)
                {
                    return(string.Empty);
                }
                return(method.Value);
            }
            catch (Exception ex) {
                FileLogger.Instance.Error(ex);
            }

            return(string.Empty);
        }
Пример #24
0
        /// <summary>
        /// Identify whether WSE XtestStepvalues(Request/Response) is using Web service request/response data in JSON Resource specialization
        /// Identify whether WSE XtestStepvalues(Request/Response) is using Web service request/response data in XML Resource specialization
        /// </summary>
        /// <param name="wseTestStep">Wse TestStep</param>
        /// <param name="tcFolder">Specialization Module</param>
        /// <returns>true if xmodule is using specialization</returns>
        public static bool IsUsingEmbeddedResource(XTestStep wseTestStep, out TCFolder tcFolder)
        {
            if (IsRequestIsUsingEmbeddedModule(wseTestStep, out XModule requestSpecializationModule))
            {
                tcFolder = (TCFolder)requestSpecializationModule.ParentFolder;
                return(true);
            }

            if (IsResponseIsUsingEmbeddedModule(wseTestStep, out XModule responseSpecializationModule))
            {
                tcFolder = (TCFolder)responseSpecializationModule.ParentFolder;
                return(true);
            }

            tcFolder = null;
            return(false);
        }
        private void FillPayloadRec(XTestStep apiTestStep,
                                    XTestStep wseTestStep,
                                    List <XTestStepValue> tcObjects,
                                    dynamic moduleData,
                                    dynamic testStepData,
                                    string jsonPath)
        {
            var arrayTemplate  = "{0}";
            var objectTemplate = ".{0}";

            try {
                int index = 0;
                foreach (var wseTestStepValue in tcObjects)
                {
                    string curJsonPath;
                    if (wseTestStepValue.ParentValue.ModuleAttribute.BusinessType == "JsonArray")
                    {
                        curJsonPath = jsonPath + string.Format(arrayTemplate, $"[{Convert.ToString(index++)}]");
                    }
                    else
                    {
                        curJsonPath = jsonPath + string.Format(objectTemplate, wseTestStepValue.Name);
                    }

                    curJsonPath = GetJsonPath(wseTestStep, wseTestStepValue, curJsonPath);
                    var apiXTestStepValue = CreateModuleAttributeForPayload(wseTestStepValue,
                                                                            curJsonPath,
                                                                            moduleData,
                                                                            (ApiModule)apiTestStep.Module,
                                                                            testStepData,
                                                                            wseTestStepValue
                                                                            .ModuleAttribute?.Cardinality);
                    FillPayloadRec(apiTestStep,
                                   wseTestStep,
                                   wseTestStepValue.SubValues.ToList(),
                                   apiXTestStepValue.ModuleAttribute,
                                   apiXTestStepValue,
                                   curJsonPath);
                }
            }
            catch (Exception ex) {
                FileLogger.Instance.Error("Error while creating module attribute {1} ", ex);
            }
        }
        public void Execute(XTestStep apiTestStep, XTestStep wseTestStep)
        {
            try {
                Dictionary <string, string> testStepKeyValueList = GetWseTestStepValueAsKeyValPair(wseTestStep);
                if (!testStepKeyValueList.Any())
                {
                    return;
                }

                foreach (var wseTestStepValue in testStepKeyValueList)
                {
                    //Extract value need to be filled in api test step
                    string wseValue = wseTestStepValue.Value;
                    string apiValue = String.Empty;
                    //Note: we ignore this step in case of response.
                    if (!IsResponseTestStepValue)
                    {
                        //get api value
                        apiValue =
                            GetValueInApiModule(apiTestStep.Module as ApiModule, wseTestStepValue.Key);
                        //if values match,do nothing.

                        if (!Regex.IsMatch(wseValue, @"\{.*\}") &&
                            apiValue == CommonUtilities.RemoveExtraDoubleQuotes(wseValue))
                        {
                            return;
                        }
                    }

                    //if values does not match , Search if there is already a API xTestStepValue present.
                    XTestStepValue apiTeststepValue = GetOrCreateApiXTestStepValue(apiTestStep, wseTestStepValue);

                    //API xTestStepValue is present now. Assign Values to it now.
                    UpdateValueRange(apiTeststepValue, apiValue, wseValue);
                    apiTeststepValue.Value      = wseTestStepValue.Value;
                    apiTeststepValue.ActionMode =
                        IsResponseTestStepValue ? XTestStepActionMode.Verify : XTestStepActionMode.Insert;
                }
            }
            catch (Exception e) {
                FileLogger.Instance.Error("Multiple value setter failed", e);
            }
        }
Пример #27
0
        private static bool IsUsingEmbeddedModule(XTestStep testStep,
                                                  string name,
                                                  List <string> specializationModulesToExclude,
                                                  out XModule embeddedModule)
        {
            var module = testStep.TestStepValues
                         .FirstOrDefault(x => x.Name == name && x.SpecializationModule != null &&
                                         !specializationModulesToExclude.Contains(
                                             x.SpecializationModule.Name))
                         ?.SpecializationModule;

            if (module != null)
            {
                embeddedModule = module;
                return(true);
            }

            embeddedModule = null;
            return(false);
        }
Пример #28
0
        /// <summary>
        /// Gets Response Status Code from WSE TestStep
        /// </summary>
        /// <param name="xTestStep">WSE TestStep</param>
        /// <returns>Status code</returns>
        public string ParseResponseStatus(XTestStep xTestStep)
        {
            try {
                TCObject statusCodeModuleAttribute =
                    xTestStep.Search(AddOnConstants.TestStepResponseStatusTql)
                    .FirstOrDefault();
                if (statusCodeModuleAttribute == null)
                {
                    return(string.Empty);
                }

                XTestStepValue statusCodeXModuleAttribute = statusCodeModuleAttribute as XTestStepValue;
                return(statusCodeXModuleAttribute?.Value);
            }
            catch (Exception ex) {
                FileLogger.Instance.Error("Failed to retrieve response Status Code :", ex);
            }

            return(string.Empty);
        }
Пример #29
0
        private string GetWsePasswordValue(XTestStep wseTestStep)
        {
            FileLogger.Instance.Info("Inside Basic Auth Credentials Password Migrator");
            Type[] methodParams      = new[] { typeof(string) };
            string decrptedPassword  = string.Empty;
            string encryptedPassword = string.Empty;

            try {
                encryptedPassword = GetTestStepValue(wseTestStep, "Password");
                if (!string.IsNullOrEmpty(encryptedPassword))
                {
                    var(type, methodInfo) =
                        AssemblyHelper.GetClassTypeAndMethodTypeFromAssembly(
                            AssemblyName,
                            ClassName,
                            MethodName,
                            methodParams);
                    var flags    = BindingFlags.Public | BindingFlags.Static;
                    var runnable = type.GetProperty("Instance", flags);
                    var result   =
                        methodInfo?.Invoke(runnable?.GetValue(null), new object[] { encryptedPassword });
                    decrptedPassword = result?.ToString();
                }
            }
            catch (Exception ex) {
                FileLogger.Instance.Error(
                    $"Error occurred while migrating of Basic Auth Password for WSE TestStep : 'Name: {wseTestStep?.Name}' NodePath:'{wseTestStep?.NodePath}' Exception:'{ex.ToString()}'");
            }

            FileLogger.Instance.Info("Complete Basic Auth Credentials Password Migrator");

            if (String.IsNullOrEmpty(decrptedPassword))
            {
                return(encryptedPassword);
            }

            return(decrptedPassword);
        }
Пример #30
0
        /// <summary>
        /// Handles Web service response data in XML/JSON embedded specialization
        /// </summary>
        /// <param name="wseTestStep">TestStep of WSE Artifacts</param>
        /// <param name="apiTestStep">TestStep of API Engine Artifacts</param>
        /// <param name="payloadParser">Parse xml and json payload from Wse XModules and TestSteps</param>
        /// <param name="payloadSetterFactory">Create module attributes and Set values for payload in for Api artifacts </param>
        public override void HandleSpecialization(XTestStep wseTestStep,
                                                  XTestStep apiTestStep,
                                                  IPayloadParser payloadParser,
                                                  IPayloadSetterFactory payloadSetterFactory)
        {
            if (wseTestStep.TestStepValues == null)
            {
                return;
            }

            if (SpecializationHelper.IsResponseIsUsingEmbeddedModule(wseTestStep,
                                                                     out XModule responseSpecializationModule))
            {
                var responsePayload =
                    payloadParser.Parse(responseSpecializationModule, AddOnConstants.TestStepXmlPayloadTql);
                var apiModule = (apiTestStep.Module as ApiModule);
                apiModule?.APISetMessagePayload(responsePayload);
            }
            else
            {
                successor?.HandleSpecialization(wseTestStep, apiTestStep, payloadParser, payloadSetterFactory);
            }
        }