Refine search
/** * <p>The before class event handler.</p> * * <p>Delegates to the registered {@link ApplicationContextProducer} instances in order to create the application * context.</p> * * @param event the before class event */ public void beforeClass(@Observes BeforeClass event) { createTestApplicationContext(event.getTestClass()); }
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(); }
protected List<Pact> getPacts(BeforeClass test) { final TestClass testClass = test.getTestClass(); final Provider providerInfo = testClass.getAnnotation(Provider.class); if (providerInfo == null) { throw new IllegalArgumentException(String.format("Provider name should be set by using %s",Provider.class.getName())); } final String serviceName = providerInfo.value(); final Consumer consumerInfo = testClass.getAnnotation(Consumer.class); final String consumerName = consumerInfo != null ? consumerInfo.value() : null; List<Pact> pacts = new ArrayList<>(); try { pacts = getPactSource(testClass).load(serviceName).stream() .filter(p -> consumerName == null || p.getConsumer().getName().equals(consumerName)) .collect(toList()); } catch (IOException e) { throw new IllegalArgumentException(e); } return pacts; }
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)); }
protected List<Pact> getPacts(BeforeClass test) { final TestClass testClass = test.getTestClass(); final Provider providerInfo = testClass.getAnnotation(Provider.class); if (providerInfo == null) { throw new IllegalArgumentException( String.format("Provider name should be set by using %s", Provider.class.getName())); } final String serviceName = providerInfo.value(); final Consumer consumerInfo = testClass.getAnnotation(Consumer.class); final String consumerName = consumerInfo != null ? consumerInfo.value() : null; List<Pact> pacts = new ArrayList<>(); try { final ContractsRetriever contractsSource = getContractsSource(testClass, algeronProviderConfigurationInstance.get()); contractsSource.setProviderName(serviceName); final List<URI> contractsDirectory = contractsSource.retrieve(); pacts = loadContractFiles(contractsDirectory, serviceName).stream() .filter(p -> consumerName == null || p.getConsumer().getName().equals(consumerName)) .collect(toList()); } catch (IOException e) { throw new IllegalArgumentException(e); } return pacts; }
@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); }
public void executeBeforeClass(@Observes BeforeClass event, TestClass testClass){ testClass = event.getTestClass(); Field[] fields = testClass.getJavaClass().getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(GetDeployableContainer.class)){ if (field.getType().isAssignableFrom(ContainerManagerTool.class)){ isGetDeployableContainerAnnoPresent = true; deployableContainerFields.add(field); } } } }
@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); }
void connect(@Observes BeforeClass beforeClass) { this.configure(beforeClass.getTestClass()); }
@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); }
void connect(@Observes BeforeClass beforeClass) { this.configure(beforeClass.getTestClass()); }
@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); }
void connect(@Observes BeforeClass beforeClass) { this.configure(beforeClass.getTestClass()); }
@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); }
void connect(@Observes BeforeClass beforeClass) { this.configure(beforeClass.getTestClass()); }
@Test public void shouldStartClassContainers() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(StartClassContainers.class, 1); }
void connect(@Observes BeforeClass beforeClass) { this.configure(beforeClass.getTestClass()); }
@Test public void shouldDeployManagedDeployments() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(DeployManagedDeployments.class, 1); }
public void applyKubernetesResourcesAtClassScope(@Observes(precedence = 10) BeforeClass beforeClass, final KubernetesClient kubernetesClient) { final TestClass testClass = beforeClass.getTestClass(); final KubernetesResource[] kubernetesResources = findAnnotations(testClass); log.info(String.format("Creating environment for %s", testClass.getName())); createResources(testClass.getJavaClass().getName(), kubernetesClient, kubernetesResources); }
@Test public void shouldStartClassContainers() throws Exception { fire(new BeforeClass(testClass())); assertEventFired(StartClassContainers.class, 1); }