Search in sources :

Example 1 with TigerRoute

use of de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute in project app-Tiger by gematik.

the class TigerProxyServer method getDestinationUrlFromProxiedServer.

private void getDestinationUrlFromProxiedServer(TigerProxyConfiguration cfg) {
    final String destUrl = getTigerTestEnvMgr().getServers().keySet().stream().filter(srvid -> srvid.equals(cfg.getProxiedServer())).findAny().map(srvid -> getTigerTestEnvMgr().getServers().get(srvid)).map(srv -> srv.getDestinationUrl(cfg.getProxiedServerProtocol())).orElseThrow(() -> new TigerTestEnvException("Proxied server '" + cfg.getProxiedServer() + "' not found in list!"));
    TigerRoute tigerRoute = new TigerRoute();
    tigerRoute.setFrom("/");
    tigerRoute.setTo(destUrl);
    cfg.getProxyRoutes().add(tigerRoute);
}
Also used : TigerRoute(de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute) TigerSerializationUtil(de.gematik.test.tiger.common.util.TigerSerializationUtil) TigerServerStatusUpdate(de.gematik.test.tiger.testenvmgr.env.TigerServerStatusUpdate) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) CfgServer(de.gematik.test.tiger.testenvmgr.config.CfgServer) HashMap(java.util.HashMap) Mode(org.springframework.boot.Banner.Mode) TigerProxyApplication(de.gematik.test.tiger.proxy.TigerProxyApplication) TigerProxyConfiguration(de.gematik.test.tiger.common.data.config.tigerProxy.TigerProxyConfiguration) ArrayList(java.util.ArrayList) ServerType(de.gematik.test.tiger.common.config.ServerType) Slf4j(lombok.extern.slf4j.Slf4j) TigerTestEnvMgr(de.gematik.test.tiger.testenvmgr.TigerTestEnvMgr) TigerTestEnvException(de.gematik.test.tiger.testenvmgr.util.TigerTestEnvException) Map(java.util.Map) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) WebApplicationType(org.springframework.boot.WebApplicationType) CfgStandaloneProxy(de.gematik.test.tiger.testenvmgr.config.tigerProxyStandalone.CfgStandaloneProxy) TigerTestEnvException(de.gematik.test.tiger.testenvmgr.util.TigerTestEnvException) TigerRoute(de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute)

Example 2 with TigerRoute

use of de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute in project app-Tiger by gematik.

the class TigerProxy method addRoute.

@Override
public TigerRoute addRoute(final TigerRoute tigerRoute) {
    tigerRouteMap.values().stream().filter(existingRoute -> uriTwoIsBelowUriOne(existingRoute.getFrom(), tigerRoute.getFrom()) || uriTwoIsBelowUriOne(tigerRoute.getFrom(), existingRoute.getFrom())).findAny().ifPresent(existingRoute -> {
        throw new TigerProxyRouteConflictException(existingRoute);
    });
    log.info("Adding route {} -> {}", tigerRoute.getFrom(), tigerRoute.getTo());
    final Expectation[] expectations = buildRouteAndReturnExpectation(tigerRoute);
    if (expectations.length > 1) {
        log.warn("Unexpected number of expectations created! Got {}, expected 1", expectations.length);
    }
    if (expectations.length == 0) {
        throw new TigerProxyConfigurationException("Error while adding route from '{}' to '{}': Got 0 new expectations");
    }
    final TigerRoute createdTigerRoute = tigerRoute.withId(expectations[0].getId());
    tigerRouteMap.put(expectations[0].getId(), createdTigerRoute);
    log.info("Created route {} with expectation {}", createdTigerRoute, expectations[0]);
    return createdTigerRoute;
}
Also used : TigerProxyConfigurationException(de.gematik.test.tiger.proxy.exceptions.TigerProxyConfigurationException) TigerRoute(de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute) TigerProxyRouteConflictException(de.gematik.test.tiger.proxy.exceptions.TigerProxyRouteConflictException) Expectation(org.mockserver.mock.Expectation)

Example 3 with TigerRoute

use of de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute in project app-Tiger by gematik.

the class TigerConfigurationController method addRoute.

@PutMapping(value = "/route", consumes = MediaType.APPLICATION_JSON_VALUE)
public TigerRouteDto addRoute(@RequestBody TigerRouteDto addRouteDto) {
    log.info("Adding route from '{}' to '{}'", addRouteDto.getFrom(), addRouteDto.getTo());
    final TigerRoute tigerRoute = tigerProxy.addRoute(TigerRoute.builder().from(addRouteDto.getFrom()).to(addRouteDto.getTo()).build());
    return TigerRouteDto.from(tigerRoute);
}
Also used : TigerRoute(de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute)

Example 4 with TigerRoute

use of de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute in project app-Tiger by gematik.

the class TigerProxy method removeRoute.

@Override
public void removeRoute(final String routeId) {
    if (!mockServer.isRunning()) {
        return;
    }
    mockServerClient.clear(new ExpectationId().withId(routeId));
    final TigerRoute route = tigerRouteMap.remove(routeId);
    log.info("Deleted route {}. Current # expectations {}", route, mockServerClient.retrieveActiveExpectations(request()).length);
}
Also used : ExpectationId(org.mockserver.model.ExpectationId) TigerRoute(de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute)

Example 5 with TigerRoute

use of de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute in project app-Tiger by gematik.

the class TigerProxyRoutingTest method beforeEachLifecyleMethod.

@BeforeEach
public void beforeEachLifecyleMethod(WireMockRuntimeInfo wmRuntimeInfo) {
    tigerProxy.getRoutes().stream().filter(route -> !route.getFrom().contains("tiger")).forEach(tigerRoute -> tigerProxy.removeRoute(tigerRoute.getId()));
    tigerProxy.addRoute(TigerRoute.builder().from("http://myserv.er").to("http://localhost:" + wmRuntimeInfo.getHttpPort()).build());
    wmRuntimeInfo.getWireMock().register(get("/foo").willReturn(aResponse().withBody("bar")));
    backendServerPort = wmRuntimeInfo.getHttpPort();
    unirestInstance = new UnirestInstance(new Config().proxy("localhost", tigerProxy.getProxyPort()));
    unirestInstance.get("");
}
Also used : WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) BeforeEach(org.junit.jupiter.api.BeforeEach) TigerRoute(de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute) HttpResponse(kong.unirest.HttpResponse) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) WireMockRuntimeInfo(com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo) Autowired(org.springframework.beans.factory.annotation.Autowired) GenericType(kong.unirest.GenericType) AssertionsForClassTypes.fail(org.assertj.core.api.AssertionsForClassTypes.fail) Config(kong.unirest.Config) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest) UnirestInstance(kong.unirest.UnirestInstance) TigerRouteDto(de.gematik.test.tiger.proxy.data.TigerRouteDto) UnirestInstance(kong.unirest.UnirestInstance) Config(kong.unirest.Config) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TigerRoute (de.gematik.test.tiger.common.data.config.tigerProxy.TigerRoute)5 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)1 WireMockRuntimeInfo (com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo)1 WireMockTest (com.github.tomakehurst.wiremock.junit5.WireMockTest)1 ServerType (de.gematik.test.tiger.common.config.ServerType)1 TigerProxyConfiguration (de.gematik.test.tiger.common.data.config.tigerProxy.TigerProxyConfiguration)1 TigerSerializationUtil (de.gematik.test.tiger.common.util.TigerSerializationUtil)1 TigerProxyApplication (de.gematik.test.tiger.proxy.TigerProxyApplication)1 TigerRouteDto (de.gematik.test.tiger.proxy.data.TigerRouteDto)1 TigerProxyConfigurationException (de.gematik.test.tiger.proxy.exceptions.TigerProxyConfigurationException)1 TigerProxyRouteConflictException (de.gematik.test.tiger.proxy.exceptions.TigerProxyRouteConflictException)1 TigerTestEnvMgr (de.gematik.test.tiger.testenvmgr.TigerTestEnvMgr)1 CfgServer (de.gematik.test.tiger.testenvmgr.config.CfgServer)1 CfgStandaloneProxy (de.gematik.test.tiger.testenvmgr.config.tigerProxyStandalone.CfgStandaloneProxy)1 TigerServerStatusUpdate (de.gematik.test.tiger.testenvmgr.env.TigerServerStatusUpdate)1 TigerTestEnvException (de.gematik.test.tiger.testenvmgr.util.TigerTestEnvException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1