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

com.turbospaces.boot.test.AbstractServerResource Maven / Gradle / Ivy

package com.turbospaces.boot.test;

import java.util.Objects;

import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;

import com.turbospaces.boot.AbstractBootstrap;
import com.turbospaces.boot.Bootstrap;
import com.turbospaces.cfg.ApplicationProperties;

import lombok.Getter;
import okhttp3.HttpUrl;

public abstract class AbstractServerResource

> implements BeforeAllCallback, ExtensionContext.Store.CloseableResource { protected final Logger logger = LoggerFactory.getLogger(getClass()); protected T bootstrap; @Getter protected ConfigurableApplicationContext ctx; @Override public void close() throws Exception { if (Objects.nonNull(bootstrap)) { try { bootstrap.shutdown(); } catch (Throwable err) { logger.error(err.getMessage(), err); } finally { } } } @SuppressWarnings("unchecked") public void setBootstrap(Bootstrap bootstrap) { this.bootstrap = (T) bootstrap; } public int port() { return bootstrap.port(); } public int secondaryPort() { return bootstrap.secondaryPort(); } public int tertiaryPort() { return bootstrap.tertiaryPort(); } public Bootstrap bootstrap() { return bootstrap; } public HttpUrl toHttpUrl() { return HttpUrl.parse("http://localhost:" + port()); } public HttpUrl toSecondaryHttpUrl() { return HttpUrl.parse("http://localhost:" + secondaryPort()); } public HttpUrl toTertiaryHttpUrl() { return HttpUrl.parse("http://localhost:" + tertiaryPort()); } public static HttpUrl.Builder toHttpUrl(int port) { return new HttpUrl.Builder().scheme("http").host("localhost").port(port); } public static HttpUrl.Builder toHttpUrl(String host, int port) { return new HttpUrl.Builder().scheme("http").host(host).port(port); } public static HttpUrl.Builder toHttpsUrl(int port) { return new HttpUrl.Builder().scheme("https").host("localhost").port(port); } public static HttpUrl.Builder toHttpsUrl(String host, int port) { return new HttpUrl.Builder().scheme("https").host(host).port(port); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy