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);
}
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;
}
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);
}
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);
}
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("");
}
Aggregations