com.gtcgroup.justify.rest.testing.extension.ConfigureTestingRestExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of justify-rest Show documentation
Show all versions of justify-rest Show documentation
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.
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 extends JstConfigureTestingRestPO> configureTestRestClassPO = initializePropertiesFromAnnotation(
extensionContext);
final JstConfigureTestingRestPO configureTestRestInstancePO = configureTestRestClassPO.newInstance();
this.testContainer = JstRestUtilHelper.initializeTestContainer(configureTestRestInstancePO);
} catch (final RuntimeException runtimeException) {
handleBeforeAllException(extensionContext, runtimeException); // Tested
}
}
@Override
protected Class extends JstConfigureTestingRestPO> initializePropertiesFromAnnotation(
final ExtensionContext extensionContext) {
final JstConfigureTestingREST configureTestREST = (JstConfigureTestingREST) retrieveAnnotation(
extensionContext.getRequiredTestClass(), JstConfigureTestingREST.class);
// Retrieve values from annotation.
return configureTestREST.configureTestRestPO();
}
}