Author Topic: Updating the Repository &  passing Parame  (Read 912 times)

Dermot

  • EA Administrator
  • EA User
  • *****
  • Posts: 583
  • Karma: +6/-0
    • View Profile
Updating the Repository &  passing Parame
« on: September 29, 2003, 08:58:24 pm »
This was based on request for gettting inforation on Formal-Requirements across into the Test Cases of that object.

This is short piece of Automation Interface code that gives an example of:
- making updates to the repository
- Calling an application using parameters from EA

It needs to be called as an executable from EA.  There are details on the web site for calling an application from EA -
http://www.sparxsystems.com.au/AutIntVBCallingFromEA.htm.

These details would differ for this application:

- The application Name: Requirements
- The command line would be: c:\{YourDir..}\Requirement.exe
- The Arguments would be:  $f, $p

On running EA - open the diagram with the Formal Requirements then select the installed application from the EA menu - Tools | Requirements.  This will give a simple msgbox asking if want to copy the name and notes of each Requirement element in that package.  On selecting 'Yes' it simply copies the Name and Details into a Test Case.


This is simple code.  It only checks if the records already
exist - if so it does not try to add the same name.


Here is the code below:


______________________________________________________________


Option Explicit
Public EARepos As EA.Repository        ' The instance of an EA repository

Private Sub Main()
   '_______________________________________________
   '
   'Get the command line parameters, Load the Repository
   'and set some defaults
   '_______________________________________________
   Dim Package As EA.Package
   Dim lPackageId As Long
   Dim EafileName As String

   'set what will be parameters in the procudure call
    If Len(Command) > 0 Then                    ' See if there are any arguments.

       ' The Ea repository location             'possible EA Arguments $f, $p
       EafileName = GetParams(Command, 0)
 
       ' get the package Id
       lPackageId = Val(GetParams(Command, 1))
       
   Else
   
       'No Arguments may not be running from EA..
       MsgBox ("Please set this up to be called as an application by EA passing the $f, $p arguments.  See: http://www.sparxsystems.com.au/AutIntVBCallingFromEA.htm")
       End
       
   End If
   
   OpenRepos (EafileName)                   'load up with sepcified path
   
   Set Package = EARepos.GetPackageByID(lPackageId)
   
   ScanElements Package
   
End Sub


Sub ScanElements(Package As Package)
   Dim idx As Integer, oElement As Element, PackageName As String
   
   '_______________________________________________________________
   '
   ' Scan through each Element - Ask user if they want to add to tests
   '_______________________________________________________________
   
   For idx = 0 To Package.Elements.Count - 1
   
       Set oElement = Package.Elements.GetAt(idx)
       
       ' Check if there are details for this element to be output
        If oElement.Type = "Requirement" Then
       
           ' if so list the details for the element
           If MsgBox(oElement.Name + "  - Pass to test?", vbYesNo, _
           "Copy to Element Requirements") = vbYes Then
               ElementDetailToTest oElement
           End If
           
       End If
       
   Next
End Sub

Public Sub ElementDetailToTest(oElement As EA.Element)
    '_______________________________________________________________
    '
    'Copy over the key details for a Requirement Element to Element Requirements
    '_______________________________________________________________
   
    Dim aTest As EA.Test, idx As Integer
   
    'Check the test is not already there
    For idx = 0 To oElement.Tests.Count - 1
       If oElement.Tests(idx).Name = oElement.Name Then
           MsgBox ("There is an existing Test of this name")
           Exit Sub
       End If
    Next
   
   ' Create a test case from the Formalrequirements
    Set aTest = oElement.Tests.AddNew(oElement.Name, "Standard")
    aTest.AcceptanceCriteria = oElement.Notes
    aTest.Input = oElement.Notes
   
    aTest.Update
   
End Sub


Public Function GetParams(ParamStr As String, ParamNum As Integer) As String
   Dim words() As String
   
   words = Split(ParamStr, ",")
 
   GetParams = words(ParamNum)
   
End Function


Public Function OpenRepos(EaProjName As String)

   'create the EA Reppository
   Set EARepos = New EA.Repository
 
   EARepos.OpenFile (EaProjName)                   'load up with sepcified path
   EARepos.ShowWindow (0)                          'optionally hide window

End Function


____________________________________________

Enjoy!