All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gtcgroup.justify.rest.testing.extension.ConfigureTestingRestExtension Maven / Gradle / Ivy

Go to download

REST MODULE: PED Central is the home for the open-source �Justify� suite of software engineering modules. Justify seeks API alignment between Java 1.8+ application code and JUnit 5 test code.

There is a newer version: 8.5.0-alpha5
Show newest version
package com.gtcgroup.justify.rest.testing.extension;

import org.glassfish.jersey.test.spi.TestContainer;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import com.gtcgroup.justify.core.testing.extension.JstBaseExtension;
import com.gtcgroup.justify.rest.testing.helper.JstRestUtilHelper;

public class ConfigureTestingRestExtension extends JstBaseExtension implements BeforeAllCallback, AfterAllCallback {

	private TestContainer testContainer;

	@Override
	public void afterAll(final ExtensionContext context) throws Exception {

		this.testContainer.stop();
	}

	@Override
	public void beforeAll(final ExtensionContext extensionContext) throws Exception {

		try {
			final Class configureTestRestClassPO = initializePropertiesFromAnnotation(
					extensionContext);

			final JstConfigureTestingRestPO configureTestRestInstancePO = configureTestRestClassPO.newInstance();

			this.testContainer = JstRestUtilHelper.initializeTestContainer(configureTestRestInstancePO);

		} catch (final RuntimeException runtimeException) {
			handleBeforeAllException(extensionContext, runtimeException); // Tested
		}
	}

	@Override
	protected Class initializePropertiesFromAnnotation(
			final ExtensionContext extensionContext) {

		final JstConfigureTestingREST configureTestREST = (JstConfigureTestingREST) retrieveAnnotation(
				extensionContext.getRequiredTestClass(), JstConfigureTestingREST.class);

		// Retrieve values from annotation.
		return configureTestREST.configureTestRestPO();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy