Check of java annotation data

Discussion in 'Java' started by mike, Sep 22, 2011.

  1. mike

    mike Guest

    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
    mike, Sep 22, 2011
    #1
    1. Advertising

  2. 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
    Robert Klemme, Sep 25, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond McCrae
    Replies:
    2
    Views:
    1,475
    Raymond McCrae
    Mar 3, 2004
  2. srini

    java.text.Annotation

    srini, Apr 24, 2004, in forum: Java
    Replies:
    0
    Views:
    497
    srini
    Apr 24, 2004
  3. Ian Pilcher

    Check class file for annotation

    Ian Pilcher, Jan 23, 2006, in forum: Java
    Replies:
    6
    Views:
    828
    Ian Pilcher
    Jan 24, 2006
  4. Replies:
    10
    Views:
    796
    Chris Uppal
    May 31, 2006
  5. pek
    Replies:
    2
    Views:
    1,047
Loading...

Share This Page