001: package test.mannotation;
002:
003: import java.lang.reflect.Method;
004:
005: import org.testng.Assert;
006: import org.testng.annotations.Configuration;
007: import org.testng.annotations.Test;
008: import org.testng.internal.annotations.DefaultAnnotationTransformer;
009: import org.testng.internal.annotations.IConfiguration;
010: import org.testng.internal.annotations.ITest;
011: import org.testng.internal.annotations.JDK15AnnotationFinder;
012:
013: public class MAnnotation2SampleTest {
014: private JDK15AnnotationFinder m_finder;
015:
016: @Configuration(beforeTestClass=true,enabled=true,groups="current")
017: public void init() {
018: m_finder = new JDK15AnnotationFinder(
019: new DefaultAnnotationTransformer());
020: }
021:
022: @Test
023: public void verifyTestGroupsInheritance() throws SecurityException,
024: NoSuchMethodException {
025: {
026: Method method = MTest3.class.getMethod("groups1",
027: new Class[0]);
028: ITest test1 = (ITest) m_finder.findAnnotation(method,
029: ITest.class);
030: Assert.assertEqualsNoOrder(new String[] { "method-test3",
031: "child-class-test3", "base-class" }, test1
032: .getGroups());
033: }
034:
035: {
036: Method method = MTest3.class.getMethod("groups2",
037: new Class[0]);
038: ITest test1 = (ITest) m_finder.findAnnotation(method,
039: ITest.class);
040: Assert.assertEqualsNoOrder(new String[] {
041: "child-class-test3", "base-class" }, test1
042: .getGroups());
043: }
044: }
045:
046: @Test
047: public void verifyTestDependsOnGroupsInheritance()
048: throws SecurityException, NoSuchMethodException {
049: {
050: Method method = MTest3.class.getMethod("dependsOnGroups1",
051: new Class[0]);
052: ITest test1 = (ITest) m_finder.findAnnotation(method,
053: ITest.class);
054: Assert.assertEqualsNoOrder(new String[] { "dog2", "dog1",
055: "dog3" }, test1.getDependsOnGroups());
056: }
057:
058: {
059: Method method = MTest3.class.getMethod("dependsOnGroups2",
060: new Class[0]);
061: ITest test1 = (ITest) m_finder.findAnnotation(method,
062: ITest.class);
063: Assert.assertEqualsNoOrder(new String[] { "dog1", "dog3" },
064: test1.getDependsOnGroups());
065: }
066:
067: }
068:
069: @Test
070: public void verifyTestDependsOnMethodsInheritance()
071: throws SecurityException, NoSuchMethodException {
072: {
073: Method method = MTest3.class.getMethod("dependsOnMethods1",
074: new Class[0]);
075: ITest test1 = (ITest) m_finder.findAnnotation(method,
076: ITest.class);
077: Assert.assertEqualsNoOrder(new String[] { "dom2", "dom3",
078: "dom1" }, test1.getDependsOnMethods());
079: }
080:
081: {
082: Method method = MTest3.class.getMethod("dependsOnMethods2",
083: new Class[0]);
084: ITest test1 = (ITest) m_finder.findAnnotation(method,
085: ITest.class);
086: Assert.assertEqualsNoOrder(new String[] { "dom1", "dom3" },
087: test1.getDependsOnMethods());
088: }
089:
090: }
091:
092: @Test
093: public void verifyConfigurationGroupsInheritance()
094: throws SecurityException, NoSuchMethodException {
095: Method method = MTest3.class.getMethod("beforeSuite",
096: new Class[0]);
097: IConfiguration test1 = (IConfiguration) m_finder
098: .findAnnotation(method, IConfiguration.class);
099: Assert.assertEqualsNoOrder(new String[] { "method-test3",
100: "child-class-test3", "base-class" }, test1.getGroups());
101: }
102:
103: @Test(groups="current")
104: public void verifyTestEnabledInheritance()
105: throws SecurityException, NoSuchMethodException {
106: {
107: Method method = MTest3.class.getMethod("enabled1",
108: new Class[0]);
109: ITest test1 = (ITest) m_finder.findAnnotation(method,
110: ITest.class);
111: Assert.assertFalse(test1.getEnabled());
112: }
113:
114: {
115: Method method = MTest3.class.getMethod("enabled2",
116: new Class[0]);
117: ITest test1 = (ITest) m_finder.findAnnotation(method,
118: ITest.class);
119: Assert.assertTrue(test1.getEnabled());
120: }
121:
122: }
123:
124: // @Test(groups = "current")
125: // public void verifyCapture()
126: // throws SecurityException, NoSuchMethodException
127: // {
128: // {
129: // Method method = MChildCaptureTest.class.getMethod("shouldBelongToGroupChild", new Class[0]);
130: // ITest test1 = (ITest) m_finder.findAnnotation(method, ITest.class);
131: // Assert.assertEqualsNoOrder(new String[] { "child" },
132: // test1.getGroups());
133: // }
134: // }
135:
136: }
|