org.jboss.arquillian.core.api.annotation.Observes Java Examples
The following examples show how to use
org.jboss.arquillian.core.api.annotation.Observes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppServerTestEnricher.java From keycloak with Apache License 2.0 | 6 votes |
public void startAppServer(@Observes(precedence = -1) BeforeClass event) throws MalformedURLException, InterruptedException, IOException { // if testClass implements SelfManagedAppContainerLifecycle we skip starting container and let the test to manage the lifecycle itself if (SelfManagedAppContainerLifecycle.class.isAssignableFrom(event.getTestClass().getJavaClass())) { log.debug("Skipping starting App server. Server should be started by testClass."); return; } if (testContext.isAdapterContainerEnabled() && !testContext.isRelativeAdapterTest()) { if (isJBossBased()) { prepareServerDir("standalone"); } ContainerController controller = containerConrollerInstance.get(); if (!controller.isStarted(testContext.getAppServerInfo().getQualifier())) { log.info("Starting app server: " + testContext.getAppServerInfo().getQualifier()); controller.start(testContext.getAppServerInfo().getQualifier()); } if (isFuseAppServer()) { FuseUtils.setUpFuse(ContainerConstants.APP_SERVER_PREFIX + CURRENT_APP_SERVER); } } }
Example #2
Source File: RequestContextLifecycle.java From quarkus with Apache License 2.0 | 6 votes |
public void on(@Observes(precedence = DEFAULT_PRECEDENCE) After event) throws Throwable { //we are outside the runtime class loader, so we don't have direct access to the container ClassLoader classLoader = appClassloader.get(); if (classLoader != null) { Class<?> arcClz = classLoader.loadClass(Arc.class.getName()); Object container = arcClz.getMethod("container").invoke(null); if (container != null) { boolean running = (boolean) container.getClass().getMethod("isRunning").invoke(container); if (running) { Object context = container.getClass().getMethod("requestContext").invoke(container); context.getClass().getMethod("terminate").invoke(context); LOGGER.debug("RequestContextLifecycle activating CDI Request context."); } } } }
Example #3
Source File: RequestContextLifecycle.java From quarkus with Apache License 2.0 | 6 votes |
public void on(@Observes(precedence = DEFAULT_PRECEDENCE) Before event) throws Throwable { //we are outside the runtime class loader, so we don't have direct access to the container ClassLoader classLoader = appClassloader.get(); if (classLoader != null) { Class<?> arcClz = classLoader.loadClass(Arc.class.getName()); Object container = arcClz.getMethod("container").invoke(null); if (container != null) { boolean running = (boolean) container.getClass().getMethod("isRunning").invoke(container); if (running) { Object context = container.getClass().getMethod("requestContext").invoke(container); context.getClass().getMethod("activate").invoke(context); LOGGER.debug("RequestContextLifecycle activating CDI Request context."); } } } }
Example #4
Source File: RegistryCreator.java From keycloak with Apache License 2.0 | 6 votes |
public void createRegistry(@Observes ArquillianDescriptor event) { ContainerRegistry reg = new Registry(injector.get()); ServiceLoader serviceLoader = loader.get(); log.info("arquillian.xml: " + System.getProperty("arquillian.xml")); @SuppressWarnings("rawtypes") Collection<DeployableContainer> containers = serviceLoader.all(DeployableContainer.class); if (containers.isEmpty()) { throw new IllegalStateException("There are not any container adapters on the classpath"); } List<ContainerDef> containersDefs = event.getContainers();//arquillian.xml List<GroupDef> groupDefs = event.getGroups();//arquillian.xml addAppServerContainers(containersDefs, groupDefs);//dynamically loaded containers/groups createRegistry(containersDefs, reg, serviceLoader); for (GroupDef group : groupDefs) { createRegistry(group.getGroupContainers(), reg, serviceLoader); } registry.set(reg); }
Example #5
Source File: ClassLoaderExceptionTransformer.java From quarkus with Apache License 2.0 | 6 votes |
public void transform(@Observes(precedence = -1000) Test event) { TestResult testResult = testResultInstance.get(); if (testResult != null) { Throwable res = testResult.getThrowable(); if (res != null) { try { if (res.getClass().getClassLoader() != null && res.getClass().getClassLoader() != getClass().getClassLoader()) { if (res.getClass() == classLoaderInstance.get().loadClass(res.getClass().getName())) { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oo = new ObjectOutputStream(out); oo.writeObject(res); res = (Throwable) new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject(); testResult.setThrowable(res); } } } catch (Exception ignored) { } } } }
Example #6
Source File: ReporterLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 6 votes |
public void observeBeforeTest(@Observes(precedence = Integer.MAX_VALUE) BeforeTestLifecycleEvent event) { Integer c = lifecycleCountRegister.get(event.getTestMethod()); int count = (c != null ? c.intValue() : 0); if (count == 0) { TestMethodReport testMethodReport = new TestMethodReport(); testMethodReport.setName(event.getTestMethod().getName()); if (event.getTestMethod().isAnnotationPresent(OperateOnDeployment.class)) { OperateOnDeployment ood = event.getTestMethod().getAnnotation(OperateOnDeployment.class); testMethodReport.setOperateOnDeployment(ood.value()); } else { testMethodReport.setOperateOnDeployment("_DEFAULT_"); } testMethodReport.setRunAsClient(event.getTestMethod().isAnnotationPresent(RunAsClient.class)); reporter.get().getLastTestClassReport().getTestMethodReports().add(testMethodReport); reporter.get().setTestMethodReport(testMethodReport); } lifecycleCountRegister.put(event.getTestMethod(), ++count); }
Example #7
Source File: SkipperConfigurator.java From arquillian-governor with Apache License 2.0 | 6 votes |
public void onGovernorExtensionConfigured(@Observes GovernorExtensionConfigured event, ArquillianDescriptor arquillianDescriptor) throws Exception { final SkipperConfiguration skipperConfiguration = new SkipperConfiguration(); for (final ExtensionDef extension : arquillianDescriptor.getExtensions()) { if (extension.getExtensionName().equals(EXTENSION_NAME)) { skipperConfiguration.setConfiguration(extension.getExtensionProperties()); skipperConfiguration.validate(); break; } } this.skipperReportHolder.set(new SkipperReportHolder()); this.skipperConfiguration.set(skipperConfiguration); logger.log(Level.CONFIG, "Configuration of Arquillian Skipper extension:"); logger.log(Level.CONFIG, skipperConfiguration.toString()); }
Example #8
Source File: CrossDCTestEnricher.java From keycloak with Apache License 2.0 | 6 votes |
public void afterSuite(@Observes(precedence = 4) AfterSuite event) { if (!suiteContext.isAuthServerCrossDc()) return; // Unfortunately, in AfterSuite, containerController context is already cleaned so stopAuthServerBackendNode() // and stopCacheServer cannot be used. On the other hand, Arquillian by default does not guarantee that cache // servers are terminated only after auth servers were, so the termination has to be done in this enricher. forAllBackendNodesStream() .map(ContainerInfo::getArquillianContainer) .map(StopContainer::new) .forEach(stopContainer::fire); if (!AuthServerTestEnricher.CACHE_SERVER_LIFECYCLE_SKIP) { DC.validDcsStream() .map(CrossDCTestEnricher::getCacheServer) .map(ContainerInfo::getArquillianContainer) .map(StopContainer::new) .forEach(stopContainer::fire); } }
Example #9
Source File: ExporterRegistrationHandler.java From arquillian-recorder with Apache License 2.0 | 6 votes |
public void onCreatedReporterRegister(@Observes ExporterRegisterCreated event) { JAXBContext context = getContext(); exporterRegister.get() .add(new XMLExporter(context)) .add(new JSONExporter(context)) .add(new HTMLExporter(context)) .add(new AsciiDocExporter()); reportTypeRegister.get() .add(new XMLReport()) .add(new JSONReport()) .add(new HTMLReport()) .add(new AsciiDocReport()); }
Example #10
Source File: GovernorConfigurator.java From arquillian-governor with Apache License 2.0 | 6 votes |
public void onArquillianDescriptor(@Observes ArquillianDescriptor arquillianDescriptor) throws GovernorConfigurationException { final GovernorConfiguration governorConfiguration = new GovernorConfiguration(); for (final ExtensionDef extension : arquillianDescriptor.getExtensions()) { if (extension.getExtensionName().equals(EXTENSION_NAME)) { governorConfiguration.setConfiguration(extension.getExtensionProperties()); governorConfiguration.validate(); break; } } this.governorConfiguration.set(governorConfiguration); logger.log(Level.CONFIG, "Configuration of Arquillian Governor extension:"); logger.log(Level.CONFIG, governorConfiguration.toString()); governorExtensionConfiguredEvent.fire(new GovernorExtensionConfigured()); }
Example #11
Source File: ScreenshooterLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 6 votes |
public void beforeTest(@Observes(precedence = -50) Before event) { if (new TakingScreenshotDecider(recorderStrategyRegister.get()).decide(event, null)) { ScreenshotMetaData metaData = getMetaData(event); metaData.setResourceType(getScreenshotType()); DefaultFileNameBuilder nameBuilder = new DefaultFileNameBuilder(); String screenshotName = nameBuilder .withMetaData(metaData) .withStage(When.BEFORE) .build(); beforeScreenshotTaken.fire(new BeforeScreenshotTaken(metaData)); TakeScreenshot takeScreenshooter = new TakeScreenshot(screenshotName, metaData, When.BEFORE, event.getTestMethod().getAnnotation(Screenshot.class)); takeScreenshot.fire(takeScreenshooter); metaData.setBlurLevel(resolveBlurLevel(event)); org.arquillian.extension.recorder.screenshooter.Screenshot screenshot = takeScreenshooter.getScreenshot(); if(screenshot != null) { metaData.setFilename(screenshot.getResource()); } afterScreenshotTaken.fire(new AfterScreenshotTaken(metaData)); } }
Example #12
Source File: TestObserver.java From tomee with Apache License 2.0 | 6 votes |
public void release(@Observes final EventContext<BeforeUnDeploy> event) { if (!SystemInstance.isInitialized()) { event.proceed(); return; } try { event.proceed(); } finally { final BeanContext bc = beanContext(); if (bc != null) { // can be null if deployment exception final CreationalContext<?> cc = bc.get(CreationalContext.class); if (cc != null) { cc.release(); } } } }
Example #13
Source File: GovernorExecutionDecider.java From arquillian-governor with Apache License 2.0 | 6 votes |
public void on(@Observes DecideMethodExecutions decodeMethodExecution) { for (final Map.Entry<Method, List<Annotation>> entry : governorRegistry.get().get().entrySet()) { final Method testMethod = entry.getKey(); executionDecisionProducer.set(ExecutionDecision.execute()); for (final Annotation annotation : entry.getValue()) { executionDecisionEvent.fire(new ExecutionDecisionEvent(annotation)); // we get here after all TestExecutionDeciders which observe above event are treated // and eventually set final execution decision about that annotation ExecutionDecision decision = this.executionDecision.get(); if (decision == null) { decision = ExecutionDecision.execute(); } TestMethodExecutionRegister.put(testMethod.toString(), annotation.annotationType(), decision); } } }
Example #14
Source File: InTestScreenshotResourceReportObserver.java From arquillian-recorder with Apache License 2.0 | 6 votes |
public void onInTestResourceReport(@Observes InTestResourceReport event) { TakenResourceRegister register = takenResourceRegister.get(); for (Screenshot screenshot : register.getTakenScreenshots()) { if (!register.getReportedScreenshots().contains(screenshot)) { PropertyEntry propertyEntry = new ScreenshotReportEntryBuilder() .withWhen(When.IN_TEST) .withMetadata(screenshot.getResourceMetaData()) .withScreenshot(screenshot) .build(); reportEvent.fire(new PropertyReportEvent(propertyEntry)); } } register.invalidateScreenshots(); }
Example #15
Source File: DesktopVideoRecorderConfigurator.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void afterVideoExtensionConfigured(@Observes VideoExtensionConfigured event, ArquillianDescriptor descriptor) { VideoConfiguration configuration = new DesktopVideoConfiguration(reporterConfiguration.get()); for (ExtensionDef extension : descriptor.getExtensions()) { if (extension.getExtensionName().equals(EXTENSION_NAME)) { configuration.setConfiguration(extension.getExtensionProperties()); break; } } configuration.validate(); this.configuration.set(configuration); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Configuration of Arquillian Desktop Video Recorder:"); LOGGER.info(this.configuration.get().toString()); } // there will be 2 strategies in this list at least - SkippingVideoStrategy and DefaultVideoStrategy // if this extension is not on the class path, SkippingVideoStrategy was already produced hence // the extension will work in a "dummy" mode where nothing will be ever recorded. If this is on the class path, // we have recorder implementation hence we will use at least DefaultVideoStrategy if no other strategy is used List<VideoStrategy> strategies = new ArrayList<VideoStrategy>(serviceLoader.get().all(VideoStrategy.class)); strategy.set(resolveVideoStrategy(strategies)); strategy.get().setConfiguration(this.configuration.get()); setup(); }
Example #16
Source File: AsciidoctorTestObserver.java From asciidoctorj with Apache License 2.0 | 5 votes |
public void beforeTestCreateUnsharedAsciidoctorInstance(@Observes(precedence = 5) Before before) { if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), AsciidoctorJRuby.class) || isUnsharedInstanceRequired(before.getTestMethod(), Asciidoctor.class)) { scopedAsciidoctor.get().setUnsharedAsciidoctor( AsciidoctorJRuby.Factory.create()); } else if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), Asciidoctor.class) || isUnsharedInstanceRequired(before.getTestMethod(), Asciidoctor.class)) { scopedAsciidoctor.get().setUnsharedAsciidoctor( Asciidoctor.Factory.create()); } }
Example #17
Source File: AsciidoctorTestObserver.java From asciidoctorj with Apache License 2.0 | 5 votes |
public void beforeTestClassCreateSharedTemporaryFolder(@Observes(precedence = -100) BeforeClass beforeClass) throws IOException { if (isSharedInstanceRequired(beforeClass.getTestClass().getJavaClass(), TemporaryFolder.class)) { TemporaryFolder temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); scopedTemporaryFolder.get().setSharedTemporaryFolder(temporaryFolder); } }
Example #18
Source File: ReporterLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void observeBeforeClass(@Observes(precedence = Integer.MAX_VALUE) BeforeClass event) { TestClassReport testClassReport = new TestClassReport(); testClassReport.setTestClassName(event.getTestClass().getName()); testClassReport.setRunAsClient(event.getTestClass().isAnnotationPresent(RunAsClient.class)); testClassReport.setReportMessage(ReportMessageParser.parseTestClassReportMessage(event.getTestClass().getJavaClass())); reporter.get().getLastTestSuiteReport().getTestClassReports().add(testClassReport); reporter.get().setTestClassReport(testClassReport); }
Example #19
Source File: AuthServerTestEnricher.java From keycloak with Apache License 2.0 | 5 votes |
public void checkServerLogs(@Observes(precedence = -1) BeforeSuite event) throws IOException, InterruptedException { if (! suiteContext.getAuthServerInfo().isJBossBased()) { suiteContext.setServerLogChecker(new TextFileChecker()); // checks nothing return; } if (suiteContext.getServerLogChecker() == null) { setServerLogChecker(); } boolean checkLog = Boolean.parseBoolean(System.getProperty("auth.server.log.check", "true")); if (checkLog) { suiteContext.getServerLogChecker() .checkFiles(true, AuthServerTestEnricher::failOnRecognizedErrorInLog); } }
Example #20
Source File: VideoTaker.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void onStartRecording(@Observes StartRecordVideo event) { VideoMetaData metaData = event.getVideoMetaData(); metaData.setResourceType(event.getVideoType()); String fileName = nb .withMetaData(metaData) .build(); File videoTarget = new File(event.getVideoMetaData().getTestClassName(), fileName); recorder.get().startRecording(videoTarget, event.getVideoType()); }
Example #21
Source File: H2TestEnricher.java From keycloak with Apache License 2.0 | 5 votes |
public void stopH2(@Observes(precedence = -2) AfterSuite event) { if (runH2 && dockerDatabaseSkip && server.isRunning(false)) { log.info("Stopping H2 database."); server.stop(); assert !server.isRunning(false); } }
Example #22
Source File: VideoLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void afterSuite(@Observes AfterSuite event) { if (strategy.get().isTakingAction(event)) { VideoMetaData metaData = getMetaData(); VideoType videoType = getVideoType(); beforeVideoStop.fire(new BeforeVideoStop(videoType, metaData)); stopRecordSuiteVideo.fire(new StopRecordSuiteVideo(videoType, metaData)); afterVideoStop.fire(new AfterVideoStop(videoType, metaData)); } }
Example #23
Source File: VideoLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void afterTest(@Observes AfterTestLifecycleEvent event) { if (strategy.get().isTakingAction(event, testResult.get())) { VideoMetaData metaData = getMetaData(event); metaData.setTestResult(testResult.get()); VideoType videoType = getVideoType(); beforeVideoStop.fire(new BeforeVideoStop(videoType, metaData)); stopRecordVideo.fire(new StopRecordVideo(videoType, metaData)); afterVideoStop.fire(new AfterVideoStop(videoType, metaData)); } }
Example #24
Source File: VideoLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void beforeSuite(@Observes BeforeSuite event) { if (strategy.get().isTakingAction(event)) { VideoMetaData suiteMetaData = getMetaData(); VideoType videoType = getVideoType(); beforeVideoStart.fire(new BeforeVideoStart(videoType, suiteMetaData)); startRecordSuiteVideo.fire(new StartRecordSuiteVideo(videoType, suiteMetaData)); afterVideoStart.fire(new AfterVideoStart(videoType, suiteMetaData)); } }
Example #25
Source File: ScreenshooterLifecycleObserver.java From arquillian-recorder with Apache License 2.0 | 5 votes |
public void afterTest(@Observes(precedence = 50) AfterTestLifecycleEvent event, TestResult result) { if (new TakingScreenshotDecider(recorderStrategyRegister.get()).decide(event, result)) { ScreenshotMetaData metaData = getMetaData(event); metaData.setTestResult(result); metaData.setResourceType(getScreenshotType()); When when = result.getStatus() == TestResult.Status.FAILED ? When.FAILED : When.AFTER; DefaultFileNameBuilder nameBuilder = new DefaultFileNameBuilder(); String screenshotName = nameBuilder .withMetaData(metaData) .withStage(when) .build(); beforeScreenshotTaken.fire(new BeforeScreenshotTaken(metaData)); TakeScreenshot takeScreenshooter = new TakeScreenshot(screenshotName, metaData, when, null); takeScreenshot.fire(takeScreenshooter); metaData.setBlurLevel(resolveBlurLevel(event)); org.arquillian.extension.recorder.screenshooter.Screenshot screenshot = takeScreenshooter.getScreenshot(); if(screenshot != null) { metaData.setFilename(screenshot.getResource()); } afterScreenshotTaken.fire(new AfterScreenshotTaken(metaData)); } }
Example #26
Source File: AsciidoctorTestObserver.java From asciidoctorj with Apache License 2.0 | 5 votes |
public void beforeTestCreateUnsharedTemporaryFolder(@Observes(precedence = 5) Before before) throws IOException { if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), TemporaryFolder.class) || isUnsharedInstanceRequired(before.getTestMethod(), TemporaryFolder.class)) { TemporaryFolder temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); scopedTemporaryFolder.get().setUnsharedTemporaryFolder( temporaryFolder); } }
Example #27
Source File: AuthServerTestEnricher.java From keycloak with Apache License 2.0 | 5 votes |
public void initializeTLS(@Observes(precedence = 3) BeforeClass event) throws Exception { // TLS for Undertow is configured in KeycloakOnUndertow since it requires // SSLContext while initializing HTTPS handlers if (!suiteContext.isAuthServerCrossDc() && !suiteContext.isAuthServerCluster()) { initializeTLS(suiteContext.getAuthServerInfo()); } }
Example #28
Source File: AuthServerTestEnricher.java From keycloak with Apache License 2.0 | 5 votes |
public void initializeTestContext(@Observes(precedence = 2) BeforeClass event) throws Exception { TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass()); testContextProducer.set(testContext); if (!isAuthServerRemote() && !isAuthServerQuarkus() && event.getTestClass().isAnnotationPresent(EnableVault.class)) { VaultUtils.enableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId()); restartAuthServer(); testContext.reconnectAdminClient(); } }
Example #29
Source File: QuarkusBeforeAfterLifecycle.java From quarkus with Apache License 2.0 | 5 votes |
public void on(@Observes(precedence = DEFAULT_PRECEDENCE) org.jboss.arquillian.test.spi.event.suite.Before event) throws Throwable { if (isJunitAvailable()) { invokeCallbacks(JUNIT_INVOKE_BEFORES, JUNIT_CALLBACKS); } if (isTestNGAvailable()) { invokeCallbacks(TESTNG_INVOKE_BEFORE_METHOD, TESTNG_CALLBACKS); } }
Example #30
Source File: SuiteDeployer.java From arquillian-suite-extension with Apache License 2.0 | 5 votes |
/** * Method ignoring DeployManagedDeployments events if already deployed. * * @param eventContext Event to check */ public void blockDeployManagedDeploymentsWhenNeeded(@Observes EventContext<DeployManagedDeployments> eventContext) { if (!extensionEnabled()) { eventContext.proceed(); } else if (deployDeployments) { deployDeployments = false; debug("NOT Blocking DeployManagedDeployments event {0}", eventContext.getEvent().toString()); eventContext.proceed(); } else { // Do nothing with event. debug("Blocking DeployManagedDeployments event {0}", eventContext.getEvent().toString()); } }