|
We are now on iteration 2. The goal of this iteration is to build the Search Results
panel. To refresh our memories, here's the mockup of the Search screen. The Search
Results panel is the panel on the right that shows a table of timecards.
Value Objects
To support the Search Results panel, the service layer must provide the ability
to get a list of timecards that match a specific criteria. Let's decide that we
will create a service called TimeTrackingService that will provide
this functionality via the method specified below:
public interface TimeTrackingService
{
public TimecardSummaryVO[] findTimecards(TimecardSearchCriteriaVO criteria);
}
Here TimecardSearchCriteriaVO is a value object that packages timecard
search criteria - if a field in this class is specified, then that criterion applies;
if the field is left as null, then that criterion does not apply. TimecardSummaryVO
is another value object that packages summary information about each timecard. Based
on the fields in the Search screen, let's design these two value objects. Note that
we need a status field in both these value objects. So first create an enumeration
called TimecardStatus under the org.andromda.timetracker.domain
package as shown below. To do this, create a class in the "Domain Objects" diagram,
and give it the stereotype of Enumeration. Then add the four enumeration
values as shown below - these are added as attributes. Make sure the enumeration
is created in the org.andromda.timetracker.domain package by inspecting
the containment tree.
Now that TimecardStatus is defined, we can define the two value objects
needed by the findTimecards() service method. Create TimecardSearchCriteriaVO
and TimecardSummaryVO under the org.andromda.timetracker.vo
package as shown below. Create these value objects in the "Value Objects" diagram.
Note that the multiplicity of each attribute in TimecardSearchCriteriaVO
is set to 0..1 - indicating that their value could be left as null. To specify the
multiplicity of an attribute, you must double-click on the attribute to open its
specification and then choose the right multiplicity. In addition to the two value
objects, create a class called TimecardSummaryVO[] to represent an
array of timecard summaries. Make sure these three classes are created in the
org.andromda.timetracker.vo package by inspecting the containment tree.
TimeTrackingService
We now have everything to define our TimeTrackingService. Create this
service under the org.andromda.timetracker.service package as shown
below. Create it in the "Services" diagram and make sure the service is created
in the org.andromda.timetracker.service package by inspecting the containment
tree. Also make sure that the return type of findTimecards is TimecardSummaryVO[]
by verifying it in the operation specification.
Now let's ask AndroMDA to generate code:
- Execute the command
mvn install in the Command Prompt. Make sure you
get a BUILD SUCCESSFUL message.
Verify that the following files are generated in the appropriate directories:
- common\target\src\org\andromda\timetracker\domain\TimecardStatus.java
- common\target\src\org\andromda\timetracker\vo\TimecardSummaryVO.java
- common\target\src\org\andromda\timetracker\vo\TimecardSearchCriteriaVO.java
- common\target\src\org\andromda\timetracker\service\TimeTrackingService.java
- core\target\src\org\andromda\timetracker\service\TimeTrackingServiceBase.java
- core\src\main\java\org\andromda\timetracker\service\TimeTrackingServiceImpl.java
TimeTrackingService Test
As with UserService, we will first write a test for TimeTrackingService
and then write the implementation to make the test pass. Follow the steps below
to create TimeTrackingServiceTest and run it:
- Copy
TimeTrackingServiceTest.java from the directory C:\timetracker-completed\core\src\test\java\org\andromda\timetracker\service
to the corresponding directory under your implementation. This file contains two
tests for findTimecards(): testFindAllTimecards() and
testFindTimecardsForSubmitter. Review both tests and make sure you
understand them.
- Edit your copy of
testng.xml under C:\timetracker\core\src\test\resources
and uncomment TimeTrackingServiceTest so that it is enabled for execution.
- Execute the following command in the
C:\timetracker directory to run
the test.
mvn -f core/pom.xml test
You will find that the test fails with the following message:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running Services Test
Tests run: 3, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.661 sec <<< FAILURE!
Results :
Tests run: 3, Failures: 2, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19 seconds
[INFO] Finished at: Sun Aug 06 18:38:26 EDT 2006
[INFO] Final Memory: 5M/11M
[INFO] ------------------------------------------------------------------------
- Let's look at the test results to see what happened. Open
C:\timetracker\core\target\surefire-reports\Services
Test.txt. You will see the following log:
-------------------------------------------------------------------------------
Test set: Services Test
-------------------------------------------------------------------------------
Tests run: 3, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.661 sec <<< FAILURE!
testFindAllTimecards Time elapsed: 0.31 sec <<< FAILURE!
java.lang.NullPointerException
at ...(TimeTrackingServiceTest.java:58)
at ...(TimeTrackingServiceTest.java:41)
testFindTimecardsForSubmitter Time elapsed: 0.01 sec <<< FAILURE!
java.lang.NullPointerException
at ...(TimeTrackingServiceTest.java:58)
at ...(TimeTrackingServiceTest.java:50)
Obviously the service is currently returning null instead of TimecardSummaryVO[].
This problem will be fixed when we implement the service.
What's Next?
The next step is to implement the findTimecards() method. Click the
Next link below to start this implementation.
|