本文整理汇总了Java中org.springframework.test.context.TestContext.getTestMethod方法的典型用法代码示例。如果您正苦于以下问题:Java TestContext.getTestMethod方法的具体用法?Java TestContext.getTestMethod怎么用?Java TestContext.getTestMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.test.context.TestContext
的用法示例。
在下文中一共展示了TestContext.getTestMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
@Override
public void afterTestMethod(TestContext testContext) {
Method method = testContext.getTestMethod();
if (DataSetAnnotationUtils.isRun(method)) {
try {
MybatisTestProcessor mybatisTestProcessor = testContext.
getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
boolean success = mybatisTestProcessor.compareResult(method);
if (!success) {
logger.info("Data test result : failure");
Assert.fail();
}
} catch (EasyMallTestException e) {
logger.error(e.getMessage(), e);
Assert.fail(e.getMessage());
}
}
logger.info("Data test result : success");
MDC.clear();
}
示例2: afterTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
@Override
public void afterTestMethod(TestContext testContext) {
Method method = testContext.getTestMethod();
if (DataSetAnnotationUtils.isRun(method)) {
try {
DataProcessor dataProcessor = testContext.
getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
boolean success = dataProcessor.compareResult(method);
if (!success) {
logger.info("Data test result : failure");
Assert.fail();
}
} catch (EasyTestException e) {
logger.error(e.getMessage(), e);
Assert.fail(e.getMessage());
}
}
logger.info("Data test result : success");
MDC.clear();
}
示例3: initDatabase
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
/**
* 初始化数据源
*
* @param testContext
*/
private void initDatabase(TestContext testContext) {
SqlConfig.Database database = null;
Class<?> testClass = testContext.getTestClass();
SqlConfig sqlConfigInClass = testClass.getAnnotation(SqlConfig.class);
if (sqlConfigInClass != null) {
database = sqlConfigInClass.database();
}
Method method = testContext.getTestMethod();
SqlConfig sqlConfigInMethod = method.getAnnotation(SqlConfig.class);
if (sqlConfigInMethod != null) {
database = sqlConfigInMethod.database();
}
if (database != null) {
UnitTestDataSource.selectDataSource(database);
}
}
示例4: afterTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
/**
* If a transaction is currently active for the supplied
* {@linkplain TestContext test context}, this method will end the transaction
* and run {@link AfterTransaction @AfterTransaction} methods.
* <p>{@code @AfterTransaction} methods are guaranteed to be invoked even if
* an error occurs while ending the transaction.
*/
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
Method testMethod = testContext.getTestMethod();
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext();
// If there was (or perhaps still is) a transaction...
if (txContext != null) {
TransactionStatus transactionStatus = txContext.getTransactionStatus();
try {
// If the transaction is still active...
if ((transactionStatus != null) && !transactionStatus.isCompleted()) {
txContext.endTransaction();
}
}
finally {
runAfterTransactionMethods(testContext);
}
}
}
示例5: setAlertCapability
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
private void setAlertCapability(TestContext context) {
Method testMethod = context.getTestMethod();
if (testMethod != null) {
UnexpectedAlertCapability capability = testMethod.getAnnotation(UnexpectedAlertCapability.class);
if (capability != null) {
alertCapability.set(capability.capability());
}
}
}
示例6: beforeTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
final String uuid = testCases.get();
final Class<?> testClass = testContext.getTestClass();
final Method testMethod = testContext.getTestMethod();
final String id = getHistoryId(testClass, testMethod);
final TestResult result = new TestResult()
.withUuid(uuid)
.withHistoryId(id)
.withName(testMethod.getName())
.withFullName(String.format("%s.%s", testClass.getCanonicalName(), testMethod.getName()))
.withLinks(getLinks(testClass, testMethod))
.withLabels(
new Label().withName("package").withValue(testClass.getCanonicalName()),
new Label().withName("testClass").withValue(testClass.getCanonicalName()),
new Label().withName("testMethod").withValue(testMethod.getName()),
new Label().withName("suite").withValue(testClass.getName()),
new Label().withName("host").withValue(getHostName()),
new Label().withName("thread").withValue(getThreadName())
);
result.getLabels().addAll(getLabels(testClass, testMethod));
getDisplayName(testMethod).ifPresent(result::setName);
getLifecycle().scheduleTestCase(result);
getLifecycle().startTestCase(uuid);
}
示例7: beforeTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
@Override
public void beforeTestMethod(TestContext testContext) {
Method method = testContext.getTestMethod();
if (DataSetAnnotationUtils.isRun(method)) {
try{
MybatisTestProcessor mybatisTestProcessor = testContext.
getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
mybatisTestProcessor.insertPrepareData(method);
} catch (EasyMallTestException e) {
logger.error(e.getMessage(), e);
Assert.fail(e.getMessage());
}
}
}
示例8: beforeTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
@Override
public void beforeTestMethod(TestContext testContext) {
Method method = testContext.getTestMethod();
if (DataSetAnnotationUtils.isRun(method)) {
try {
DataProcessor dataProcessor = testContext.
getApplicationContext().getBean(DataSetAnnotationUtils.getImplName(method));
dataProcessor.insertPrepareData(method);
} catch (EasyTestException e) {
logger.error(e.getMessage(), e);
Assert.fail(e.getMessage());
}
}
}
示例9: initTestData
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
private void initTestData(TestContext testContext) {
List<String> sqlFiles = new ArrayList<String>();
/**
* 读取测试类指定的sql文件
*/
Class<?> testClass = testContext.getTestClass();
SqlConfig sqlConfigInClass = testClass.getAnnotation(SqlConfig.class);
if (sqlConfigInClass != null) {
String[] sqlFilesInClass = sqlConfigInClass.sqlFiles();
if (ArrayUtils.isNotEmpty(sqlFilesInClass)) {
sqlFiles.addAll(Arrays.asList(sqlFilesInClass));
}
}
/**
* 读取测试方法指定的sql文件
*/
Method method = testContext.getTestMethod();
SqlConfig sqlConfigInMethod = method.getAnnotation(SqlConfig.class);
if (sqlConfigInMethod != null) {
String[] sqlFilesInMethod = sqlConfigInMethod.sqlFiles();
if (ArrayUtils.isNotEmpty(sqlFilesInMethod)) {
sqlFiles.addAll(Arrays.asList(sqlFilesInMethod));
}
}
/**
* 执行sql
*/
for (String sqlFile : sqlFiles) {
LOGGER.info(String.format("execute sql file [%s]", sqlFile));
this.executeSqlScript(testContext, sqlFile, false);
}
}
示例10: beforeTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
/**
* If the test method of the supplied {@linkplain TestContext test context}
* is configured to run within a transaction, this method will run
* {@link BeforeTransaction @BeforeTransaction} methods and start a new
* transaction.
* <p>Note that if a {@code @BeforeTransaction} method fails, any remaining
* {@code @BeforeTransaction} methods will not be invoked, and a transaction
* will not be started.
* @see org.springframework.transaction.annotation.Transactional
* @see #getTransactionManager(TestContext, String)
*/
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
final Method testMethod = testContext.getTestMethod();
final Class<?> testClass = testContext.getTestClass();
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
TransactionContext txContext = TransactionContextHolder.removeCurrentTransactionContext();
if (txContext != null) {
throw new IllegalStateException("Cannot start a new transaction without ending the existing transaction.");
}
PlatformTransactionManager tm = null;
TransactionAttribute transactionAttribute = this.attributeSource.getTransactionAttribute(testMethod, testClass);
if (transactionAttribute != null) {
transactionAttribute = TestContextTransactionUtils.createDelegatingTransactionAttribute(testContext,
transactionAttribute);
if (logger.isDebugEnabled()) {
logger.debug("Explicit transaction definition [" + transactionAttribute + "] found for test context "
+ testContext);
}
if (transactionAttribute.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) {
return;
}
tm = getTransactionManager(testContext, transactionAttribute.getQualifier());
}
if (tm != null) {
txContext = new TransactionContext(testContext, tm, transactionAttribute, isRollback(testContext));
runBeforeTransactionMethods(testContext);
txContext.startTransaction();
TransactionContextHolder.setCurrentTransactionContext(txContext);
}
}
示例11: detectDefaultScript
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
/**
* Detect a default SQL script by implementing the algorithm defined in
* {@link Sql#scripts}.
*/
private String detectDefaultScript(TestContext testContext, boolean classLevel) {
Class<?> clazz = testContext.getTestClass();
Method method = testContext.getTestMethod();
String elementType = (classLevel ? "class" : "method");
String elementName = (classLevel ? clazz.getName() : method.toString());
String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName());
if (!classLevel) {
resourcePath += "." + method.getName();
}
resourcePath += ".sql";
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
ClassPathResource classPathResource = new ClassPathResource(resourcePath);
if (classPathResource.exists()) {
if (logger.isInfoEnabled()) {
logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]", prefixedResourcePath,
elementType, elementName));
}
return prefixedResourcePath;
}
else {
String msg = String.format("Could not detect default SQL script for test %s [%s]: "
+ "%s does not exist. Either declare statements or scripts via @Sql or make the "
+ "default SQL script available.", elementType, elementName, classPathResource);
logger.error(msg);
throw new IllegalStateException(msg);
}
}
示例12: beforeOrAfterTestMethod
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
/**
* Perform the actual work for {@link #beforeTestMethod} and {@link #afterTestMethod}
* by dirtying the context if appropriate (i.e., according to the required modes).
* @param testContext the test context whose application context should
* potentially be marked as dirty; never {@code null}
* @param requiredMethodMode the method mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @param requiredClassMode the class mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @throws Exception allows any exception to propagate
* @since 4.2
* @see #dirtyContext
*/
protected void beforeOrAfterTestMethod(TestContext testContext, MethodMode requiredMethodMode,
ClassMode requiredClassMode) throws Exception {
Assert.notNull(testContext, "TestContext must not be null");
Assert.notNull(requiredMethodMode, "requiredMethodMode must not be null");
Assert.notNull(requiredClassMode, "requiredClassMode must not be null");
Class<?> testClass = testContext.getTestClass();
Method testMethod = testContext.getTestMethod();
Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
DirtiesContext methodAnn = AnnotatedElementUtils.findMergedAnnotation(testMethod, DirtiesContext.class);
DirtiesContext classAnn = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
boolean methodAnnotated = (methodAnn != null);
boolean classAnnotated = (classAnn != null);
MethodMode methodMode = (methodAnnotated ? methodAnn.methodMode() : null);
ClassMode classMode = (classAnnotated ? classAnn.classMode() : null);
if (logger.isDebugEnabled()) {
String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
logger.debug(String.format("%s test method: context %s, class annotated with @DirtiesContext [%s] "
+ "with mode [%s], method annotated with @DirtiesContext [%s] with mode [%s].", phase, testContext,
classAnnotated, classMode, methodAnnotated, methodMode));
}
if ((methodMode == requiredMethodMode) || (classMode == requiredClassMode)) {
HierarchyMode hierarchyMode = (methodAnnotated ? methodAnn.hierarchyMode() : classAnn.hierarchyMode());
dirtyContext(testContext, hierarchyMode);
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:45,代码来源:AbstractDirtiesContextTestExecutionListener.java
示例13: setUseProxy
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
private void setUseProxy(TestContext context) {
Method testMethod = context.getTestMethod();
if (testMethod != null && testMethod.getAnnotation(BrowserMobProxy.class) != null) {
useProxy.set(true);
}
}
示例14: setNeedToRestart
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
private void setNeedToRestart(TestContext context) {
Method testMethod = context.getTestMethod();
if (testMethod != null && testMethod.getAnnotation(NeedRestartDriver.class) != null) {
isNeedToRestart.set(true);
}
}
示例15: setUseFireBug
import org.springframework.test.context.TestContext; //导入方法依赖的package包/类
private void setUseFireBug(TestContext context) {
Method testMethod = context.getTestMethod();
if (testMethod != null && testMethod.getAnnotation(FireBug.class) != null) {
isUseFireBug.set(true);
}
}