Ejemplo n.º 1
0
        /// <summary>
        /// Login to the RQM server and perform some OSLC actions
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            CommandLineDictionary cmd = CommandLineDictionary.FromArguments(args);

            if (!ValidateOptions(cmd))
            {
                logger.Error("Syntax:  /url=https://<server>:port/<context>/ /user=<user> /password=<password> /project=\"<project_area>\"");
                logger.Error("Example: /url=https://exmple.com:9443/qm /user=ADMIN /password=ADMIN /project=\"JKE Banking (Quality Management)\"");
                return;
            }

            String webContextUrl = cmd["url"];
            String user          = cmd["user"];
            String passwd        = cmd["password"];
            String projectArea   = cmd["project"];

            try {
                //STEP 1: Initialize a Jazz rootservices helper and indicate we're looking for the QualityManagement catalog
                //RQM contains both Quality and Change Management providers, so need to look for QM specifically
                JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_QM_V2);

                //STEP 2: Create a new Form Auth client with the supplied user/password
                JazzFormAuthClient client = helper.InitFormClient(user, passwd);

                //STEP 3: Login in to Jazz Server
                if (client.FormLogin() == HttpStatusCode.OK)
                {
                    //STEP 4: Get the URL of the OSLC QualityManagement catalog
                    String catalogUrl = helper.GetCatalogUrl();

                    //STEP 5: Find the OSLC Service Provider for the project area we want to work with
                    String serviceProviderUrl = client.LookupServiceProviderUrl(catalogUrl, projectArea);

                    //STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries
                    String queryCapability = client.LookupQueryCapability(serviceProviderUrl,
                                                                          OSLCConstants.OSLC_QM_V2,
                                                                          OSLCConstants.QM_TEST_RESULT_QUERY);

                    //SCENARIO A: Run a query for all TestResults with a status of passed with OSLC paging of 10 items per
                    //page turned on and list the members of the result
                    OslcQueryParameters queryParams = new OslcQueryParameters();
                    queryParams.SetWhere("oslc_qm:status=\"com.ibm.rqm.execution.common.state.passed\"");
                    OslcQuery query = new OslcQuery(client, queryCapability, 10, queryParams);

                    OslcQueryResult result = query.Submit();

                    bool processAsDotNetObjects = true;
                    ProcessPagedQueryResults(result, client, processAsDotNetObjects);

                    Console.WriteLine("\n------------------------------\n");

                    //SCENARIO B:  Run a query for a specific TestResult selecting only certain
                    //attributes and then print it as raw XML.  Change the dcterms:title below to match a
                    //real TestResult in your RQM project area
                    OslcQueryParameters queryParams2 = new OslcQueryParameters();
                    queryParams2.SetWhere("dcterms:title=\"Consistent_display_of_currency_Firefox_DB2_WAS_Windows_S1\"");
                    queryParams2.SetSelect("dcterms:identifier,dcterms:title,dcterms:creator,dcterms:created,oslc_qm:status");
                    OslcQuery query2 = new OslcQuery(client, queryCapability, queryParams2);

                    OslcQueryResult     result2     = query2.Submit();
                    HttpResponseMessage rawResponse = result2.GetRawResponse();
                    ProcessRawResponse(rawResponse);
                    rawResponse.ConsumeContent();

                    //SCENARIO C:  RQM TestCase creation and update
                    TestCase testcase = new TestCase();
                    testcase.SetTitle("Accessibility verification using a screen reader");
                    testcase.SetDescription("This test case uses a screen reader application to ensure that the web browser content fully complies with accessibility standards");
                    testcase.AddTestsChangeRequest(new Link(new Uri("http://cmprovider/changerequest/1"), "Implement accessibility in Pet Store application"));

                    //Get the Creation Factory URL for test cases so that we can create a test case
                    String testcaseCreation = client.LookupCreationFactory(
                        serviceProviderUrl, OSLCConstants.OSLC_QM_V2,
                        testcase.GetRdfTypes()[0].ToString());

                    //Create the test case
                    HttpResponseMessage creationResponse = client.CreateResource(
                        testcaseCreation, testcase,
                        OslcMediaType.APPLICATION_RDF_XML);
                    creationResponse.ConsumeContent();
                    String testcaseLocation = creationResponse.Headers.Location.ToString();
                    Console.WriteLine("Test Case created a location " + testcaseLocation);

                    //Get the test case from the service provider and update its title property
                    testcase = client.GetResource(testcaseLocation,
                                                  OslcMediaType.APPLICATION_RDF_XML).Content.ReadAsAsync <TestCase>(client.GetFormatters()).Result;
                    testcase.SetTitle(testcase.GetTitle() + " (updated)");

                    //Create a partial update URL so that only the title will be updated.
                    //Assuming (for readability) that the test case URL does not already contain a '?'
                    String updateUrl = testcase.GetAbout() + "?oslc.properties=dcterms:title";

                    //Update the test case at the service provider
                    client.UpdateResource(updateUrl, testcase,
                                          OslcMediaType.APPLICATION_RDF_XML).ConsumeContent();
                }
            } catch (RootServicesException re) {
                logger.Error("Unable to access the Jazz rootservices document at: " + webContextUrl + "/rootservices", re);
            } catch (Exception e) {
                logger.Error(e.Message, e);
            }
        }