com.gtcgroup.justify.rest.testing.helper.JstRestUtilHelper 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.
/*
* [Licensed per the Open Source "MIT License".]
*
* Copyright (c) 2006 - 2018 by
* Global Technology Consulting Group, Inc. at
* http://gtcGroup.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.gtcgroup.justify.rest.testing.helper;
import java.net.URI;
import org.glassfish.jersey.internal.ServiceFinder;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestContainer;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import com.gtcgroup.justify.rest.testing.extension.JstConfigureTestingRestPO;
/**
* This Helper class starts the {@link TestContainer}.
*
*
* Copyright (c) 2006 - 2018 by Global Technology Consulting Group, Inc. at
* gtcGroup.com .
*
*
* @author Marvin Toll
* @since v3.0
*/
public enum JstRestUtilHelper {
/** Instance */
INSTANCE;
public static final String DEFAULT_TARGET_URI = "http://localhost:9998/";
/**
* @return {@link TestContainer}
*/
public static TestContainer initializeTestContainer(final JstConfigureTestingRestPO configureTestRestPO) {
final DeploymentContext deploymentContext = DeploymentContext.builder(configureTestRestPO.getResourceConfig())
.build();
final TestContainerFactory testContainerFactory = findDefaultTestContainerFactory();
final TestContainer testContainer = testContainerFactory.create(URI.create(DEFAULT_TARGET_URI),
deploymentContext);
testContainer.start();
return testContainer;
}
private static synchronized TestContainerFactory findDefaultTestContainerFactory() {
final TestContainerFactory[] factories = ServiceFinder.find(TestContainerFactory.class).toArray();
TestContainerFactory testContainerFactory = null;
for (final TestContainerFactory containerFactory : factories) {
if (TestProperties.DEFAULT_CONTAINER_FACTORY.equals(containerFactory.getClass().getName())) {
testContainerFactory = containerFactory;
break;
}
}
return testContainerFactory;
}
}