public void beforeClass(Class<?> testClass, LifecycleMethodExecutor executor) throws Exception { Validate.notNull(testClass, "TestClass must be specified"); if (testClass.isAnnotationPresent(Observer.class)) { Observer annotation = testClass.getAnnotation(Observer.class); Class<?>[] classes = annotation.value(); for (Class<?> observerClass : classes) { manager.addExtension(observerClass); } } manager.fire(new BeforeClass(testClass, executor)); }
public void beforeTest(@Observes(precedence = 100) EventContext<Before> context) { Object inspectionObject = context.getEvent().getTestInstance(); if (!executedInspections.contains(inspectionObject)) { executedInspections.add(inspectionObject); beforeClass.fire(new BeforeClass(inspectionObject.getClass())); } context.proceed(); }
@Test public void should_delete_registered_istio_resources_and_restore() { // Given final BeforeClass beforeClass = new BeforeClass(TestWithIstioResourceAndRestore.class); final IstioResourcesApplier istioResourceApplier = createIstioResourceApplier(); when(istioClient.registerCustomResources(any(InputStream.class))) .thenReturn(Arrays.asList(istioResource)); istioResourceApplier.applyIstioResourcesAtClassScope(beforeClass, istioClient); // When istioResourceApplier.removeIstioResourcesAtClassScope(new AfterClass(TestWithIstioResourceAndRestore.class), istioClient); // Then verify(istioClient, times(2)).registerCustomResources(any(InputStream.class)); verify(istioClient, times(0)).unregisterCustomResource(istioResource); }
@Test public void should_delete_registered_istio_resources_and_not_restore_if_resource_is_different() { // Given final BeforeClass beforeClass = new BeforeClass(TestWithIstioResourceAndRestore.class); final IstioResourcesApplier istioResourceApplier = createIstioResourceApplier(); when(istioClient.registerCustomResources(any(InputStream.class))) .thenReturn(Arrays.asList(istioResource), Arrays.asList(istioResource2)); istioResourceApplier.applyIstioResourcesAtClassScope(beforeClass, istioClient); // When istioResourceApplier.removeIstioResourcesAtClassScope(new AfterClass(TestWithIstioResourceAndRestore.class), istioClient); // Then verify(istioClient, times(2)).registerCustomResources(any(InputStream.class)); verify(istioClient, times(1)).unregisterCustomResource(istioResource); }
@Test public void should_delete_registered_istio_resources() { // Given final BeforeClass beforeClass = new BeforeClass(TestWithIstioResource.class); final IstioResourcesApplier istioResourceApplier = createIstioResourceApplier(); when(istioClient.registerCustomResources(any(InputStream.class))) .thenReturn(Arrays.asList(istioResource)); istioResourceApplier.applyIstioResourcesAtClassScope(beforeClass, istioClient); // When istioResourceApplier.removeIstioResourcesAtClassScope(new AfterClass(TestWithIstioResource.class), istioClient); // Then verify(istioClient, times(1)).unregisterCustomResource(istioResource); }
@Test public void should_apply_tests_with_istio_resources() { // Given final BeforeClass beforeClass = new BeforeClass(TestWithIstioResource.class); final IstioResourcesApplier istioResourceApplier = createIstioResourceApplier(); when(istioClient.registerCustomResources(any(InputStream.class))) .thenReturn(Arrays.asList(istioResource)); // When istioResourceApplier.applyIstioResourcesAtClassScope(beforeClass, istioClient); // Then verify(istioClient, times(1)).registerCustomResources(any(InputStream.class)); assertThat(istioResourceApplier.getResourcesMap()) .hasSize(1) .containsValue(Arrays.asList(istioResource)); assertThat(istioResourceApplier.getRestoredResourcesMap()) .hasSize(0); }
@Test public void should_apply_tests_with_istio_resources_and_restore() { // Given final BeforeClass beforeClass = new BeforeClass(TestWithIstioResourceAndRestore.class); final IstioResourcesApplier istioResourceApplier = createIstioResourceApplier(); when(istioClient.registerCustomResources(any(InputStream.class))) .thenReturn(Arrays.asList(istioResource)); // When istioResourceApplier.applyIstioResourcesAtClassScope(beforeClass, istioClient); // Then verify(istioClient, times(1)).registerCustomResources(any(InputStream.class)); assertThat(istioResourceApplier.getResourcesMap()) .hasSize(1) .containsValue(Arrays.asList(istioResource)); assertThat(istioResourceApplier.getRestoredResourcesMap()) .hasSize(0); }
@Test public void shouldStartClassContainers() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(StartClassContainers.class, 1); }
@Test public void shouldStartClassContainers() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(StartClassContainers.class, 1); }
@Test public void shouldDeployManagedDeployments() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(DeployManagedDeployments.class, 1); }
@Test public void shouldDeployManagedDeployments() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(DeployManagedDeployments.class, 1); }
@Test public void shouldNotForceRestartIfMaxDeploymentsNotSet() throws Exception { ArquillianDescriptor desc = Descriptors.create(ArquillianDescriptor.class) .engine(); bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); for (int i = 0; i < 10; i++) { fire(new BeforeClass(getClass())); } assertEventFired(StartSuiteContainers.class, 0); assertEventFired(StopSuiteContainers.class, 0); } }
@Test public void shouldNotForceRestartIfMaxDeploymentsNotSet() throws Exception { ArquillianDescriptor desc = Descriptors.create(ArquillianDescriptor.class) .engine(); bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); for (int i = 0; i < 10; i++) { fire(new BeforeClass(getClass())); } assertEventFired(StartSuiteContainers.class, 0); assertEventFired(StopSuiteContainers.class, 0); } }
@Test public void shouldRestartContainerForEveryX() throws Exception { ArquillianDescriptor desc = Descriptors.create(ArquillianDescriptor.class) .engine().maxTestClassesBeforeRestart(5); bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); for (int i = 0; i < 6; i++) { fire(new BeforeClass(getClass())); } assertEventFired(StartSuiteContainers.class, 1); assertEventFired(StopSuiteContainers.class, 1); }
@Test public void shouldNotRestartContainerOnStartOfSequence() throws Exception { ArquillianDescriptor desc = Descriptors.create(ArquillianDescriptor.class) .engine().maxTestClassesBeforeRestart(5); bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); for (int i = 0; i < 5; i++) { fire(new BeforeClass(getClass())); } assertEventFired(StartSuiteContainers.class, 0); assertEventFired(StopSuiteContainers.class, 0); }
@Test public void shouldRestartContainerForEveryX() throws Exception { ArquillianDescriptor desc = Descriptors.create(ArquillianDescriptor.class) .engine().maxTestClassesBeforeRestart(5); bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); for (int i = 0; i < 6; i++) { fire(new BeforeClass(getClass())); } assertEventFired(StartSuiteContainers.class, 1); assertEventFired(StopSuiteContainers.class, 1); }
@Test public void shouldNotRestartContainerOnStartOfSequence() throws Exception { ArquillianDescriptor desc = Descriptors.create(ArquillianDescriptor.class) .engine().maxTestClassesBeforeRestart(5); bind(ApplicationScoped.class, ArquillianDescriptor.class, desc); for (int i = 0; i < 5; i++) { fire(new BeforeClass(getClass())); } assertEventFired(StartSuiteContainers.class, 0); assertEventFired(StopSuiteContainers.class, 0); }
@Test public void testConfigurationViaDescriptor() { getManager().bind(SuiteScoped.class, ArquillianDescriptor.class, descriptor); fire(new BeforeClass(Object.class)); assertEventFired(GrapheneConfigured.class); GrapheneConfiguration configuration = getManager().resolve(GrapheneConfiguration.class); assertNotNull("Configuration instance has to be available.", configuration); configuration.validate(); assertEquals("'waitGuiInterval' should be 5", 5, configuration.getWaitGuiInterval()); assertEquals("'waitAjaxInterval' should be 25", 25, configuration.getWaitAjaxInterval()); assertEquals("'waitModelInterval' should be 125", 125, configuration.getWaitModelInterval()); fire(new AfterClass(Object.class)); assertEventFired(GrapheneUnconfigured.class); }