4. MaintainJ UML Diagram Editor

MaintainJ UML Diagram Editor renders sequence and class diagrams from the call trace files. To view the UML diagrams, add the trace files to a MaintainJ Trace Files Project in Eclipse and open. MaintainJ Trace Files Project can be created by by following File->New->Project->MaintainJ->MaintainJ Trace Files Project.

All menu options in MaintainJ UML Diagram Editor are provided in context menus, which can be seen by right clicking anywhere in the diagram or the Eclipse Outline View. Depending on the selected figure, relevant options are displayed in the context menu. You can 'Undo' and 'Redo' most of the operations in the editor.


4.1 Sequence Diagram Features


4.2 Class Diagram Features

The class diagram is a class dependency diagram that shows the dependencies between the classes involved based on the call sequence.


4.3 Common Features in both Class and Sequence Diagrams

The following features are available to both class and sequence diagrams.


4.4 To Perform Impact Analysis

Demo

After changing the application to fix a defect or to add a new feature, you may want to find all the existing use cases impacted by the change. It is necessary to find the impacted use cases, so that proper regression testing can be conducted before the new code is put into production. Static time source code searching does not enable us to determine the use cases that depend on a class or database table.

The 'MaintainJ Search' feature allows you find out all the use cases that depend on a Java class or method or on a database table or field.

Click the menu option 'Search' (Control+H) in Eclipse. In the search dialog box opened, you will notice a 'MaintainJ Search' tab, where you can search for a trace file or class or a method across multiple trace file projects. This gets even better by allowing you to search for a particular method parameter value. Let us explain these powerful capabilities using two concrete examples.

1. Java class or method search: Consider the simple code snippet below, a very common pattern used in Java applications.

interface DataSource{
    String loadData();
}

class FileDataSource implements DataSource{
    String loadData(){
        //Read from file and return the data
    }
}

class NetworkDataSource implements DataSource{
    String loadData(){
        //Read from network and return the data
    }
}

class DataLoader{
    private DataSource dataSource;

    DataLoader(DataSource ds){
        dataSource=ds;
    }

    String loadData(){
        return dataSource.loadData();
    }
}

By analyzing the source code above, it is impossible to tell whether DataLoader uses FileDataSource or NetworkDataSource at runtime when a use case is executed. Using the static time source code analysis tools, it is impossible to precisely tell if a use case depends on FileDataSource or NetworkDataSource.

Because MaintainJ captures the classes, method calls and their parameters as the use cases are executed, it can precisely identify whether a use case calls FileDataSource or NetworkDataSource.

Once the trace files are captured for all use cases in the application, you simply need to search for FileDataSource to find out all the use cases that depend on it. Armed with this information, you can conduct focused and comprehensive regression testing and put the code back into production with more confidence.

2. SQL Search: Most Java applications use databases. Consider that we need to identify all the test cases impacted by a change to a table structure. This is not an easy task in an enterprise setting where many applications depend on the same database. There are many database frameworks for Java and each of them embeds the SQL differently in XML or source code or both. For code analysis tools, it is difficult to map a Java class to a SQL statement and impossible to map a use case to a set of tables used.

Because MaintainJ captures all the runtime SQL statements sent to database when a use case is executed, it can precisely identify the use cases that depend on a database table(s) or field(s).

To find all the use cases that use a table, use the following search criteria in the 'MaintainJ Search' tab:

Class name: '*Statement' (searches both Statement and PreparedStatement)
Method name: 'execute*'
Method parameter name: 'sqlStatment'
Method parameter value: <<Table name or field name as referred to in the SQL>>

The search results show all the use cases that depend on the table/field and show the SQL statements using those tables/fields.

A Powerful Feature

This is a very powerful feature that no available static time dependency analysis tools can offer. However, take note of the assumption and current limitations of the feature:

The assumption is that you have already captured the trace files for all use cases of the application. If this is a considerable effort during a release cycle, it can be started on more important modules of the application and expanded to other modules later.

The limitations are:
a) Assume that class ConcreteUser extends AbstractUser. If you change AbstractUser, there is a chance that use cases depending on ConcreteUser will be impacted though you did not change ConcreteUser. In the current release users will have to use their discretion when analyzing the impact of changes to classes in a class hierarchy.
b) Only the impact of changes to Java classes, JSP's and database resources can be identified currently. Impact of changes to HTML, CSS or Javascript cannot be predicted.


4.5 Export the Diagrams to UML2 (and import into UML compliant tools like RSA)

Demo

You can export the MaintainJ sequence and class diagrams into UML2 model files and then import those model files into other UML2 compliant tools like Rational Software Architect(RSA) 8. Using these model files, RSA can display the sequence and class diagrams.

If the generated trace files are large, you can apply filters on the diagrams or delete the unwanted packages/classes/methods from the 'Outline view' and save the diagram as .mnj file. Open the .mnj file using the 'MaintainJ Editor to Save As UML2 Model' editor (select the .mnj file and right click to see this editor in the context menu). When you click 'Save As' (File->Save As), you will be prompted to enter the model file name. The UML2 model file will be saved in the same folder as the .mnj file.

You can choose if you want to export all class attributes, methods and/or class hierarchy of the classes called in the sequence diagram. The source code of the called classes must be in the workspace to export attributes/methods/hierarchy to the UML2 model. By default only the methods called in a class are exported.

The classes and calls currently visible in the diagram will only be exported to the model file. In other words, if a call is collapsed, just that call will be exported into the model file and none of the nested calls will be exported.

If you are going to import the model files into RSA, name the model files as .emx files. You have two options to view the class and sequence diagrams in RSA.

1. Install the 'MaintainJ UML2 Diagram Creator For RSA' plug-in (download link provided below). Copy the .emx file to any project and from any view like the Navigator view where you can see the file name with the .emx extension, right click the mouse. In the context menu, you will find 'Create MaintainJ UML2 Diagrams' option. When you click this option, the sequence and class diagrams will be opened in RSA.

2. You do not really need the above MaintainJ plug-in to generate the UML diagrams from the UML2 model file in RSA. Copy the .emx files into any project in RSA, open the 'Modeling perspective' and then open the .emx file using the 'Rational Model Editor'.

To open the model file as a sequence diagram, expand the model (in Model perspective, Project Explorer view) and follow 'Collaboration -> Interaction -> Right click the mouse ->Add Diagram->Sequence Diagram'.
To create the class diagram, expand the model, select all domain classes (or the classes you want to include in the class diagram), right click the mouse and follow 'Add to New Diagram File ->Class Diagram'.

Note when viewing the diagrams in RSA: Sequence diagrams with more than 50 calls take some time to open in RSA. Because it really depends on your computer's processing power, start with less number of calls and increase the diagram size depending on how it scales. You may use the 'predefined filters' to reduce the MaintainJ diagram size by removing redundant calls.

Installation Links and Notes:
The feature to export the diagrams as UML2 model files is implemented in a separate Eclipse plug-in called 'MaintainJ UML2 Model Creator', which is not packaged in the core 'MaintainJ Feature'. So, you need to install this plug-in separately. Below are relevant url's to install this plugin.

Eclipse Update url: http://maintainj.com/updates/4.0.0/uml2
Zip file: MaintainJ_UML2_Converter_4.0.0.zip The zip file contents should be placed in the 'eclipse/plugins' folder.

To install the 'MaintainJ UML2 Diagram Creator For RSA' plug-in (to follow the first approach above to view the diagrams in RSA), download MaintainJ_UML2_Diagram_Creator_4.0.0.zip file and unzip to 'eclipse/plugins' folder. Please note that this plug-in works only in RSA.

This feature is tested in Eclipse 3.5 and above, RSA 8 and RAD 7.5 and above. When installing in RSA or RAD, you can use either the 'update url' or the zip file. But when installing in Eclipse, use the update url because Eclipse would automatically fetch and install the other plug-ins that this plug-in depends on. If you cannot use the update url, make sure that you have both 'UML2 Extender SDK' and 'EMF Model Transaction SDK' plug-ins installed before installing this plug-in. In RSA and RAD these 2 plug-ins are pre-installed.

License Note: This feature is not included in the current licensing. Please contact us to use this feature on your application. However, you can try this feature using the sample trace file copied to the 'MaintainJ Trace Files Project'.