/// <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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles Web service request/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)
            {
                var wseTestStepValue = (XTestStepValue)wseTestStep.Search(TqlToGetWseTestStepValue)?.FirstOrDefault();
                BodyParamHandler.CreateBodyParameterForRequestAndResponse(
                    apiTestStep,
                    new List <XTestStepValue>()
                {
                    wseTestStepValue
                });
            }
            else
            {
                successor?.HandleSpecialization(wseTestStep, apiTestStep, payloadParser, payloadSetterFactory);
            }
        }
 /// <summary>
 /// Handles Web service request 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.IsRequestIsUsingEmbeddedModule(wseTestStep,
                                                             out XModule requestSpecializationModule))
     {
         var requestPayload =
             payloadParser.Parse(wseTestStep,
                                 "=>SUBPARTS:XTestStepValue[Name==\"Request\"]->SUBPARTS:XTestStepValue");
         var apiModule = (apiTestStep.Module as ApiModule);
         apiModule?.APISetMessagePayload(requestPayload);
     }
     else
     {
         successor?.HandleSpecialization(wseTestStep, apiTestStep, payloadParser, payloadSetterFactory);
     }
 }
        /// <summary>
        /// Migrates WSE XTestStep to API XTestStep.(Also Applies any transformation which are performed on Request or Response.Currently a limited list
        /// of transformation is supported.)
        /// </summary>
        /// <param name="rootComponentFolder">Folder on which the migration is performed</param>
        /// <param name="requestApiModule">Request API Module</param>
        /// <param name="responseApiModule">Response API Module</param>
        /// <param name="payloadParser">Instance of XML or JSON parser depending upon Module Type</param>
        /// <param name="payloadSetterFactory">Instance of XML or JSON Setter depending upon Module Type</param>
        /// <param name="wseTestStep">WSE XTestStep to be migrated</param>
        public void Migrate(TCObject rootComponentFolder,
                            ApiModule requestApiModule,
                            ApiModule responseApiModule,
                            IPayloadParser payloadParser,
                            IPayloadSetterFactory payloadSetterFactory,
                            XTestStep wseTestStep)
        {
            try {
                FileLogger.Instance.Info(
                    $"Migrating XTestStep:{wseTestStep.Name} -- NodePath:{wseTestStep.NodePath}");
                bool isWseStepDisabled = wseTestStep.Disabled;
                //disable wse teststep
                wseTestStep.Disabled = true;

                //Get Parent of wse teststep
                var parent = wseTestStep.ParentFolder ?? (dynamic)wseTestStep.TestCase;

                //Create API Request TestStep
                XTestStep requestTestStep = (XTestStep)parent.CreateXTestStepFromXModule(requestApiModule);
                requestTestStep.Name = wseTestStep.Name;

                AbstractSpecializationHandler requestSpecializationHandler =
                    SpecializationFactory.GetRequestSpecializationHandler();
                requestSpecializationHandler.HandleSpecialization(wseTestStep,
                                                                  requestTestStep,
                                                                  payloadParser,
                                                                  payloadSetterFactory);

                RequestValueSetters.ForEach(setter => setter.Execute(requestTestStep, wseTestStep));
                wseTestStep.Reorder(requestTestStep, "Yes");

                //Create API Response TestStep
                XTestStep responseTestStep = (XTestStep)parent.CreateXTestStepFromXModule(responseApiModule);
                responseTestStep.Name = wseTestStep.Name + " Response";

                ResponseValueSetters.ForEach(setter => setter.Execute(responseTestStep, wseTestStep));
                requestTestStep.Reorder(responseTestStep, "Yes");

                AbstractSpecializationHandler responseSpecializationHandler =
                    SpecializationFactory.GetResponseSpecializationHandler();
                responseSpecializationHandler.HandleSpecialization(wseTestStep,
                                                                   responseTestStep,
                                                                   payloadParser,
                                                                   payloadSetterFactory);

                //For Payload
                payloadSetterFactory.GetRequestPayloadSetter().Execute(requestTestStep, wseTestStep);
                payloadSetterFactory.GetResponsePayloadSetter().Execute(responseTestStep, wseTestStep);

                CommonParserMethods.FillTransformRequest(requestTestStep, wseTestStep);
                CommonParserMethods.FillTransformResponse(responseTestStep, wseTestStep);

                if (isWseStepDisabled)
                {
                    requestTestStep.Disable(wseTestStep.DisabledDescription);
                    responseTestStep.Disable(wseTestStep.DisabledDescription);
                    requestTestStep.Disabled  = true;
                    responseTestStep.Disabled = true;
                }

                if (!string.IsNullOrEmpty(wseTestStep.Condition))
                {
                    requestTestStep.Condition  = wseTestStep.Condition;
                    responseTestStep.Condition = wseTestStep.Condition;
                }

                if (!string.IsNullOrEmpty(wseTestStep.Path))
                {
                    requestTestStep.Path  = wseTestStep.Path;
                    responseTestStep.Path = wseTestStep.Path;
                }

                MoveBodyAttributeAtLast(requestTestStep);
                MoveBodyAttributeAtLast(responseTestStep);
            }
            catch (Exception e) {
                FileLogger.Instance.Error(e);
            }
        }
 /// <summary>
 /// Handles all types of Specialization for WSE TestStep
 /// </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 abstract void HandleSpecialization(XTestStep wseTestStep,
                                           XTestStep apiTestStep,
                                           IPayloadParser payloadParser,
                                           IPayloadSetterFactory payloadSetterFactory);