locked
How to add Tested Requirements by ID in TFS Work Item using TFS java Sdk RRS feed

  • Question

  • Hi,

    Can any one help me to add existing requirements by ID in work Items. I know adding related links and all links in workitems by ID. Can you please help me to add existing requirements by id in a work items column "Tested Requirement" using TFS Java SDK ?

    Thanks In Advance,

    Rajesh

    Wednesday, April 16, 2014 7:54 AM

Answers

  • Hi Mirelle,

    Thank you for reply. its really helped me a lot. but after changing linkTypeID -136 to -5 its worked

    Thanks,

    Rajesh


    Monday, April 21, 2014 9:36 AM
  • Thanks Rajesh, sorry for the linktypeid, it looks like I misunderstood the link type you are looking for.

    Please let me know if you have any other questions/issues.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Tuesday, April 22, 2014 12:00 PM
    Monday, April 21, 2014 2:17 PM
    Moderator
  • Hi Mireille,

    I have built the application using TFS Java SDK so far. I don't have knowledge on .Net SDK. Can you give some other alternative for organizing test cases?

    Thanks,

    Rajesh

    • Edited by Rajesh_TFS Monday, May 5, 2014 3:38 PM
    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Monday, May 5, 2014 3:38 PM
  • Hi Rajesh,

    You can use area path, create each area path to represent a test plan. It will not look good in test manager if you use it but you can create and query test cases easily using the java sdk.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Tuesday, May 6, 2014 1:51 PM
    Moderator
  • Hi Mireille,

    Thank you for reply.

    I don't have any idea to create area path.

    can you please provide sample code snippets to create area path to represent a test plan for a test case using java sdk?

    Thanks,

    Rajesh

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Wednesday, May 7, 2014 11:29 AM
  • Hi Rajesh,

    Here is a code snippet for how to create an area path:

     // connect to tfs
      WorkItemClient client = tpc.getWorkItemClient();
    
    //get team project uri       
     String uri = tpc.getWorkItemClient().getProjects().get("TeamProjectName").getURI();
    
    // get list of all the nodes, the first one is the team project one
            NodeInfo[] nodes = tpc.getCommonStructureClient().listStructures(uri);
    
            // create a new area path under the team project
            String areaUri = tpc.getCommonStructureClient().createNode("NewAreaName", nodes[0].getURI());
    
            // refresh wit cache to be able to use that new area path
            client.refreshCache();

    Please let me know if you have any questions about that sample.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Monday, May 12, 2014 3:48 PM
    Moderator

All replies

  • Hi Rajesh,

    Since you already know how to create a link I will not go into details, so you need to use LinkFactory.newRelatedLink(Workitem SourceWorkItem, WorkItem targetWorkItem, int LinkTypeID, String Comment, Boolean readOnly)

    and for the linkTypeID use -136 for this type of link.

    Please let me know if that does not answer your question.

    Thanks

    Mireille

    Wednesday, April 16, 2014 3:03 PM
    Moderator
  • Hi Mirelle,

    Thank you for reply. its really helped me a lot. but after changing linkTypeID -136 to -5 its worked

    Thanks,

    Rajesh


    Monday, April 21, 2014 9:36 AM
  • Thanks Rajesh, sorry for the linktypeid, it looks like I misunderstood the link type you are looking for.

    Please let me know if you have any other questions/issues.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Tuesday, April 22, 2014 12:00 PM
    Monday, April 21, 2014 2:17 PM
    Moderator
  • HI Mireille,

    Can you please clarify my 2 questions below

    1) When i use linkTypeID = -5 its creating Requirement ID links in both "Tested Requirement" & "All Links". I want to add existing requirements  for only "Tested Requirement". not to be added in "All Links"

    2) How can we add attachments for work items in TFS Using java SDK. can you please provide sample code snippets?

    Thanks,

    Rajesh


    • Edited by Rajesh_TFS Wednesday, April 23, 2014 8:49 AM
    Tuesday, April 22, 2014 11:58 AM
  • Hi Rajesh,

    for question 1) this is not possible because what When you add a link in Tested Requirement it is just a link of some type. The All links tab shows all links regardless of the type. If you create a test requirement link using TEE plugin or the web or VS still it will show in all links tab.

    2) here is the same code assuming that you already have the workitem:

     Attachment attachment = AttachmentFactory.newAttachment(new File("C:\\a.txt"), "some comment");
            workItem.getAttachments().add(attachment);
            workItem.save();

    Please let me know if you have any other questions/issues.

    Thanks

    Mireille

    Friday, April 25, 2014 9:19 PM
    Moderator
  • Thank you Mireille. Thanks alot. That really helped me a lot.

    can you please provide any alternative for adding testcases to hierarchy like Test Plans then to suites

    ie: we create manually Test Plans and Test Suites, then test cases should be added to

    Testplans>Test suites>TestCases1

    Testplans>Test suites>TestCases2

    Thanks,

    Rajesh



    • Edited by Rajesh_TFS Tuesday, April 29, 2014 11:09 AM
    Tuesday, April 29, 2014 9:53 AM
  • Hi Rajesh,

    you are welcome.

    I am not sure of what you are asking for, are you asking of some other alternative for organizing test cases? or other way to add test cases to test suites and test plans?

    Thanks

    Mireille

    Tuesday, April 29, 2014 1:56 PM
    Moderator
  • Hi Mireille,

    I am asking for other ways to add test cases to test suites and test plans?

    Thanks,

    Rajesh

    Monday, May 5, 2014 12:41 PM
  • Hi Rajesh,

    You can use the .Net SDK, if that works for you.

    Thanks

    Mireille

    Monday, May 5, 2014 1:54 PM
    Moderator
  • Hi Mireille,

    I have built the application using TFS Java SDK so far. I don't have knowledge on .Net SDK. Can you give some other alternative for organizing test cases?

    Thanks,

    Rajesh

    • Edited by Rajesh_TFS Monday, May 5, 2014 3:38 PM
    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Monday, May 5, 2014 3:38 PM
  • Hi Rajesh,

    You can use area path, create each area path to represent a test plan. It will not look good in test manager if you use it but you can create and query test cases easily using the java sdk.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Tuesday, May 6, 2014 1:51 PM
    Moderator
  • Hi Mireille,

    Thank you for reply.

    I don't have any idea to create area path.

    can you please provide sample code snippets to create area path to represent a test plan for a test case using java sdk?

    Thanks,

    Rajesh

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Wednesday, May 7, 2014 11:29 AM
  • Hi Rajesh,

    Here is a code snippet for how to create an area path:

     // connect to tfs
      WorkItemClient client = tpc.getWorkItemClient();
    
    //get team project uri       
     String uri = tpc.getWorkItemClient().getProjects().get("TeamProjectName").getURI();
    
    // get list of all the nodes, the first one is the team project one
            NodeInfo[] nodes = tpc.getCommonStructureClient().listStructures(uri);
    
            // create a new area path under the team project
            String areaUri = tpc.getCommonStructureClient().createNode("NewAreaName", nodes[0].getURI());
    
            // refresh wit cache to be able to use that new area path
            client.refreshCache();

    Please let me know if you have any questions about that sample.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    Monday, May 12, 2014 3:48 PM
    Moderator
  • HI Mireille,

    Thank you for reply, I am able to create area path using the snippets you provided.

    I have one more question.

    how to iterate(get) areaUri to create another sub level area path under teamproject after creating area path?

     i.e as you are storing in areaUri string variable

    // create a new area path under the team project
            String areaUri = tpc.getCommonStructureClient().createNode("NewAreaName", nodes[0].getURI());

    if i won't store in a variable(areaUri) then how to loop to find the node that i need as a parent and use it is URL

    Where can we get sample code snippets or help for TFS related questions ?

    Thanks In Advance,

    Rajesh





    • Edited by Rajesh_TFS Tuesday, May 13, 2014 2:30 PM
    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 8:44 AM
    • Unmarked as answer by Rajesh_TFS Monday, May 19, 2014 5:39 AM
    Tuesday, May 13, 2014 1:24 PM
  • Hi Rajesh,

    You can use the same way to create sub nodes, the method createNode takes the name of the new node and the parent url so, if you get the list of nodes as above and instead of using the first element, loop to find the node that you need as a parent and use it is URL.

    Please let me know if you still more help doing this.

    As for TFS samples, there are some samples with the sdk itself but they cover very little. W'll try to add more in the future.

    Thanks

    Mireille

    • Marked as answer by Rajesh_TFS Wednesday, May 14, 2014 1:03 PM
    • Unmarked as answer by Rajesh_TFS Monday, May 19, 2014 5:39 AM
    Tuesday, May 13, 2014 2:05 PM
    Moderator
  • Thank you Mireille for your post, now I am able to create sub level area path.

    but after creating areapath , i could not set areavalue immediately it to a WorkItem using below code  eventhough i have used below

    WorkItemClient client = obj.getWorkItemClient();
        client.refreshCache();

    newWorkItem.getFields().getField(CoreFieldReferenceNames.AREA_PATH).setValue(newareapath);)

    it could not set new area value to workitem.

    and one more question.

    Is there any possibility/alternative to create Suites Hierarchy using java sdk? if possible, can you please provide code samples?

    Thanks In Advance,

    Rajesh

    • Edited by Rajesh_TFS Wednesday, May 14, 2014 12:46 PM
    Tuesday, May 13, 2014 2:44 PM