Home | History | Annotate | Download | only in mannotation
      1 package test.mannotation;
      2 
      3 import org.testng.Assert;
      4 import org.testng.annotations.Configuration;
      5 import org.testng.annotations.IConfigurationAnnotation;
      6 import org.testng.annotations.ITestAnnotation;
      7 import org.testng.annotations.Test;
      8 import org.testng.internal.IConfiguration;
      9 import org.testng.internal.annotations.IAnnotationFinder;
     10 
     11 import java.lang.reflect.Method;
     12 
     13 public class MAnnotation2SampleTest {
     14   private IConfiguration m_configuration = new org.testng.internal.Configuration();
     15   private IAnnotationFinder m_finder;
     16 
     17   @Configuration(beforeTestClass = true, enabled = true, groups="current")
     18   public void init() {
     19     m_finder = m_configuration.getAnnotationFinder();
     20   }
     21 
     22   @Test
     23   public void verifyTestGroupsInheritance()
     24     throws SecurityException, NoSuchMethodException
     25   {
     26     {
     27       Method method = MTest3.class.getMethod("groups1", new Class[0]);
     28       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     29       Assert.assertEqualsNoOrder(new String[] { "method-test3", "child-class-test3", "base-class" },
     30           test1.getGroups());
     31     }
     32 
     33     {
     34       Method method = MTest3.class.getMethod("groups2", new Class[0]);
     35       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     36       Assert.assertEqualsNoOrder(new String[] { "child-class-test3", "base-class" },
     37           test1.getGroups());
     38     }
     39   }
     40 
     41   @Test
     42   public void verifyTestDependsOnGroupsInheritance()
     43     throws SecurityException, NoSuchMethodException
     44   {
     45     {
     46       Method method = MTest3.class.getMethod("dependsOnGroups1", new Class[0]);
     47       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     48       Assert.assertEqualsNoOrder(new String[] { "dog2", "dog1", "dog3" },
     49           test1.getDependsOnGroups());
     50     }
     51 
     52     {
     53       Method method = MTest3.class.getMethod("dependsOnGroups2", new Class[0]);
     54       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     55       Assert.assertEqualsNoOrder(new String[] { "dog1", "dog3" },
     56           test1.getDependsOnGroups());
     57     }
     58 
     59   }
     60 
     61   @Test
     62   public void verifyTestDependsOnMethodsInheritance()
     63     throws SecurityException, NoSuchMethodException
     64   {
     65     {
     66       Method method = MTest3.class.getMethod("dependsOnMethods1", new Class[0]);
     67       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     68       Assert.assertEqualsNoOrder(new String[] { "dom2", "dom3", "dom1" },
     69           test1.getDependsOnMethods());
     70     }
     71 
     72     {
     73       Method method = MTest3.class.getMethod("dependsOnMethods2", new Class[0]);
     74       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     75       Assert.assertEqualsNoOrder(new String[] { "dom1", "dom3" },
     76           test1.getDependsOnMethods());
     77     }
     78 
     79   }
     80 
     81 
     82   @Test
     83   public void verifyConfigurationGroupsInheritance()
     84     throws SecurityException, NoSuchMethodException
     85   {
     86     Method method = MTest3.class.getMethod("beforeSuite", new Class[0]);
     87     IConfigurationAnnotation test1 = (IConfigurationAnnotation) m_finder.findAnnotation(method, IConfigurationAnnotation.class);
     88     Assert.assertEqualsNoOrder(new String[] { "method-test3", "child-class-test3", "base-class" },
     89         test1.getGroups());
     90   }
     91 
     92   @Test(groups="current")
     93   public void verifyTestEnabledInheritance()
     94     throws SecurityException, NoSuchMethodException
     95   {
     96     {
     97       Method method = MTest3.class.getMethod("enabled1", new Class[0]);
     98       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
     99       Assert.assertFalse(test1.getEnabled());
    100     }
    101 
    102     {
    103       Method method = MTest3.class.getMethod("enabled2", new Class[0]);
    104       ITestAnnotation test1 = (ITestAnnotation) m_finder.findAnnotation(method, ITestAnnotation.class);
    105       Assert.assertTrue(test1.getEnabled());
    106     }
    107 
    108   }
    109 
    110 //  @Test(groups = "current")
    111 //  public void verifyCapture()
    112 //    throws SecurityException, NoSuchMethodException
    113 //  {
    114 //    {
    115 //      Method method = MChildCaptureTest.class.getMethod("shouldBelongToGroupChild", new Class[0]);
    116 //      ITest test1 = (ITest) m_finder.findAnnotation(method, ITest.class);
    117 //      Assert.assertEqualsNoOrder(new String[] { "child" },
    118 //          test1.getGroups());
    119 //    }
    120 //  }
    121 
    122 
    123 }
    124