public DbTestAnnotationHandler(Method method, Description description) { this.annoInfo = getDbTestAnnotationInfo(method); this.dataSetConfigInfo = getDataSetConfigInfo(this.annoInfo); this.testClassName = method.getDeclaringClass().getName(); this.testMethodName = method.getName(); this.testMethodReadableName = description.getMethodName(); }
String targetFileName = getExportFileName(dataSetExport); URL tablesDataSestUrl = JuUrl.resource().relativeTo(this.getTestClass()).get(dataSetExport.tablesDataSet()); if (tablesDataSestUrl == null) tablesDataSestUrl = JuUrl.resource(dataSetExport.tablesDataSet()); XmlOutputConverter xmlOutput = this.getDbDataUtil(emUtil).buildExport() .addTablesByDataSet(tablesDataSestUrl, true) .writeToXml(); Path targetDirPath = Paths.get(this.getLocalRoot(), targetDirName); Files.createDirectories(targetDirPath); if (verifyInfo.getAnnotation().value() == DataVerify.DEFAULT_DATA_VERIFIER.class) { String verifierName = StringUtils.capitalize(JuStringUtils.removeNonAlphabeticalLeadingCharacters(this.testMethodName)); Class<?> defaultVerifier = ReflectUtils.getInnerClass(this.getTestClass(), verifierName); AssertUtil.assertNotNull( String.format("Couldn't find Verifier %s as inner class of %s. Make sure it exists and is public static." , verifierName, this.getTestClass()) , defaultVerifier); verifiers.add(this.createVerifier(verifierClass, emUtil.getEm(), doc));
public void gatherDataSetInfos(Method m, Description desc) { logger.debug("Gathering DataSetInfos for method " + m); DbTestAnnotationInfo annoInfo = DbTestAnnotationHandler.getDbTestAnnotationInfo(m); DataSetConfigInfo configInfo = DbTestAnnotationHandler.getDataSetConfigInfo(annoInfo); // Imports for (ReflectUtils.AnnotationInfo<DataSet> dsImport : annoInfo.getDataSetAnnos()) { // Clean insert this.dataSetImports.add(this.getResourceString("", dsImport.getAnnotation().value())); // Inserts for (String insert : dsImport.getAnnotation().inserts()) { this.dataSetImports.add(this.getResourceString(configInfo.getResourcePrefix(), insert)); } } // Export for (ReflectUtils.AnnotationInfo<DataSetExport> dsExport : annoInfo.getDataSetExportAnnos()) { // Export this.dataSetExports.add(this.getResourceString(configInfo.getResourcePrefix() , new DbTestAnnotationHandler(m, desc).getExportFileName(dsExport.getAnnotation()))); } }
@Override public void evaluate() throws Throwable { // Run dbInitializationScripts dbTest.runDbInitializationScripts(dbTest.emfUtil); DbTestAnnotationHandler annotationHandler = new DbTestAnnotationHandler(method, description); // Run preAnnotations in own transaction try (EmfWork ew = dbTest.emfUtil.startWork()) { annotationHandler.executePreTestAnnotations(ew.getEmUtil()); } // Initialize protected fields of test class dbTest.emfWork = dbTest.emfUtil.startWork(); dbTest.em = dbTest.emfWork.getEm(); dbTest.emUtil = new JuEmUtil(dbTest.em); // Run test method base.evaluate(); // Run post server code in own transaction try (EmfWork ew = dbTest.emfUtil.startWork()) { annotationHandler.executePostServerCode(ew.getEmUtil()); } // Run postAnnotations in own transaction try (EmfWork ew = dbTest.emfUtil.startWork()) { annotationHandler.executePostTestAnnotations(ew.getEmUtil()); } } };
String parameterizedTestName = this.getParameterizedTestName(); AssertUtil.assertNotNull("Doesn't seem to be parameterized test: " + this.testMethodReadableName, parameterizedTestName); && this.dataSetConfigInfo.isLoadImportResourcesFromFileSystem() && !StringUtils.isEmpty(resourceDir)) { Path p = Paths.get(this.getLocalRoot(), resourceDir, actualResource); url = JuUrl.toUrl(p); } else { url = JuUrl.resource().relativeTo(this.getTestClass()).get(actualResource); if (url == null) url = JuUrl.resource(actualResource); throw new JuRuntimeException(String.format("Couldn't find resource %s, relative to class %s" , actualResource , this.getTestClass()));
public final void executePreTestAnnotations(JuEmUtil emUtil) throws Exception { DbDataUtil du = this.getDbDataUtil(emUtil); Integer sequenceValue = null; for (AnnotationInfo<DataSet> dataSetInfo : this.annoInfo.dataSetAnnos) { this.runInitializer(dataSetInfo.getAnnotation().preInitializer(), emUtil.getEm()); .resourceToUrl(dataSetInfo.getAnnotation().value(), this.dataSetConfigInfo.getResourceDirectory()); du.buildImport() .from(resourceUrl) URL resourceUrl = this.resourceToUrl(insertResource, this.dataSetConfigInfo.getResourceDirectory()); du.buildImport() .from(resourceUrl) this.runInitializer(dataSetInfo.getAnnotation().postInitializer(), emUtil.getEm());