Skip to content

Commit

Permalink
fix tests + errors
Browse files Browse the repository at this point in the history
  • Loading branch information
piomin committed Jun 7, 2023
1 parent 9775935 commit b9c1f25
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class EmployeeAPITest {

@Container
static MongoDBContainer mongodb = new MongoDBContainer("mongo:4.4");
static MongoDBContainer mongodb = new MongoDBContainer("mongo:5.0");

@DynamicPropertySource
static void registerMongoProperties(DynamicPropertyRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -29,6 +30,7 @@
@EnableKubernetesMockClient(crud = true)
@Testcontainers
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@DirtiesContext
public class EmployeeKubernetesMockTest {

private static final Logger LOG = LoggerFactory.getLogger(EmployeeKubernetesMockTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -26,6 +27,7 @@
"spring.cloud.bootstrap.enabled=true"})
@Testcontainers
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@DirtiesContext
public class EmployeeKubernetesTest {

private static final Logger LOG = LoggerFactory.getLogger(EmployeeKubernetesTest.class);
Expand All @@ -40,10 +42,6 @@ static void setup() {
Config config = Config.fromKubeconfig(k3s.getKubeConfigYaml());
DefaultKubernetesClient client = new DefaultKubernetesClient(config);

ConfigMap cm = client.configMaps().inNamespace("default")
.create(buildConfigMap(mongodb.getMappedPort(27017)));
LOG.info("!!! {}", cm);

System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, client.getConfiguration().getMasterUrl());
System.setProperty(Config.KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY,
client.getConfiguration().getClientCertData());
Expand All @@ -55,6 +53,10 @@ static void setup() {
System.setProperty(Config.KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, "false");
System.setProperty(Config.KUBERNETES_HTTP2_DISABLE, "true");
System.setProperty(Config.KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, "default");

ConfigMap cm = client.configMaps().inNamespace("default")
.create(buildConfigMap(mongodb.getMappedPort(27017)));
LOG.info("!!! {}", cm);
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableDiscoveryClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
package pl.piomin.services.gateway.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import reactor.core.publisher.Flux;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class GatewayApi {

@Autowired
RouteDefinitionLocator locator;

@Primary
@Bean
public SwaggerResourcesProvider swaggerResourcesProvider() {
return () -> {
List<SwaggerResource> resources = new ArrayList<>();
Flux<RouteDefinition> definitions = locator.getRouteDefinitions();
definitions
.filter(routeDefinition -> !routeDefinition.getId().startsWith("ReactiveCompositeDiscoveryClient_"))
.subscribe(routeDefinition -> resources.add(createResource(routeDefinition.getId(), "2.0")));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return resources;
};
}

private SwaggerResource createResource(String location, String version) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(location);
swaggerResource.setLocation("/" + location + "/v2/api-docs");
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}

}
2 changes: 1 addition & 1 deletion skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: skaffold/v4beta5
kind: Config
metadata:
name: employee-service
name: sample-spring-microservices-kubernetes
build:
artifacts:
- image: piomin/admin
Expand Down

0 comments on commit b9c1f25

Please sign in to comment.