Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Check of java annotation data

Reply
Thread Tools

Check of java annotation data

 
 
mike
Guest
Posts: n/a
 
      09-22-2011
Hi,


Today we have an annotation for each test called Info. I need to check
this information. Information is different depending if it is a
create, get, set, update operation.

@Info(
time = Time.ISO9600,
attr = {
AREA,
SERVICE,
ROUTING,
}, type = TestCaseType.CREATE, positive = false,
description = ""
)

Then I have a testsummary class that access to all this information
for each test case using a HashMap containing "TestCaseName",Info.
<String, Info>

What I want to do is to check information in @Info -tag depending if
it is a create, get, set, update test case type.

The idea I have is to have an abstract base class like:

public abstract AbstractInfoChecker{
public abstract boolean checkInfo(Info info);
}


and impl classes for each operation tests:

public class Create extends AbstractInfoChecker{

public boolean checkInfo(Info info){
if(info.time().equalsIngoreCase("ISO9600"){
//check other
return true;
}
return false;
}

Q: How do a create an instance of right type depending on
TestCaseType.nnn e.g. CREATE --> instance of
Create.
I have my Info stored in testsummary like this: Info info =
(Info) entry.getValue();
I can access the different values Info object.

All comments and hints are much appreciated.

br,

//mike
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      09-25-2011
On 09/22/2011 01:49 PM, mike wrote:
> Hi,
>
>
> Today we have an annotation for each test called Info. I need to check
> this information. Information is different depending if it is a
> create, get, set, update operation.
>
> @Info(
> time = Time.ISO9600,
> attr = {
> AREA,
> SERVICE,
> ROUTING,
> }, type = TestCaseType.CREATE, positive = false,
> description = ""
> )
>
> Then I have a testsummary class that access to all this information
> for each test case using a HashMap containing "TestCaseName",Info.
> <String, Info>
>
> What I want to do is to check information in @Info -tag depending if
> it is a create, get, set, update test case type.
>
> The idea I have is to have an abstract base class like:
>
> public abstract AbstractInfoChecker{
> public abstract boolean checkInfo(Info info);
> }
>
>
> and impl classes for each operation tests:
>
> public class Create extends AbstractInfoChecker{
>
> public boolean checkInfo(Info info){
> if(info.time().equalsIngoreCase("ISO9600"){
> //check other
> return true;
> }
> return false;
> }
>
> Q: How do a create an instance of right type depending on
> TestCaseType.nnn e.g. CREATE --> instance of
> Create.
> I have my Info stored in testsummary like this: Info info =
> (Info) entry.getValue();
> I can access the different values Info object.
>
> All comments and hints are much appreciated.


One way to do it: define a factory interface (or abstract class) which
creates AbstractInfoChecker. Create an enum map for TestCaseType as key
and the factory type as value. Initialize the map with the proper
factory instances (could even be anonymous classes).

Another way to do it: just create a factory method which returns
AbstractInfoChecker; implement it with a switch over TestCaseType.

Yet another way: put the specific logic into enum TestCaseType and use
it from there.

Kind regards

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Java Reflection API with Java Annotation Types for Thread Safety pek Java 2 10-23-2007 03:00 PM
What is a Java Annotation? marcwentink@hotmail.com Java 10 05-31-2006 02:58 PM
Check class file for annotation Ian Pilcher Java 6 01-24-2006 03:48 PM
java.text.Annotation srini Java 0 04-23-2004 11:25 PM
Getting Annotation for a Return Type (Java 1.5 Beta) Raymond McCrae Java 2 03-03-2004 06:37 PM



Advertisments