From 8f78dddf734834e005e50479c2a293086a11b8c5 Mon Sep 17 00:00:00 2001 From: tillias Date: Wed, 28 Oct 2020 12:20:16 +0100 Subject: [PATCH] Name for target node in release path is not displayed #70 --- src/main/docker/postgresql.yml | 20 ++--- .../custom/ReleasePathCustomService.java | 9 ++- .../resources/config/application-postgres.yml | 80 +++++++++++++++++++ .../custom/ReleasePathAdviceTraitTest.java | 77 ++++++++++++++++++ 4 files changed, 174 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/config/application-postgres.yml create mode 100644 src/test/java/com/github/microcatalog/web/rest/errors/custom/ReleasePathAdviceTraitTest.java diff --git a/src/main/docker/postgresql.yml b/src/main/docker/postgresql.yml index e370945..ea55e75 100644 --- a/src/main/docker/postgresql.yml +++ b/src/main/docker/postgresql.yml @@ -1,12 +1,14 @@ -version: '2' +version: '3.1' services: - microcatalog-postgresql: - image: postgres:12.3 - # volumes: - # - ~/volumes/jhipster/microcatalog/postgresql/:/var/lib/postgresql/data/ - environment: - - POSTGRES_USER=microcatalog - - POSTGRES_PASSWORD= - - POSTGRES_HOST_AUTH_METHOD=trust + db: + image: postgres + restart: always ports: - 5432:5432 + environment: + POSTGRES_PASSWORD: kEt#uR6M + adminer: + image: adminer + restart: always + ports: + - 9080:8080 diff --git a/src/main/java/com/github/microcatalog/service/custom/ReleasePathCustomService.java b/src/main/java/com/github/microcatalog/service/custom/ReleasePathCustomService.java index 6d96e9b..501c15f 100644 --- a/src/main/java/com/github/microcatalog/service/custom/ReleasePathCustomService.java +++ b/src/main/java/com/github/microcatalog/service/custom/ReleasePathCustomService.java @@ -39,14 +39,17 @@ public ReleasePathCustomService(GraphLoaderService graphLoaderService) { public Optional getReleasePath(final Long microserviceId) { final Graph graph = graphLoaderService.loadGraph(); - final Microservice target = new Microservice(); - target.setId(microserviceId); + + final Optional maybeTarget = graph.vertexSet() + .stream().filter(v -> Objects.equals(v.getId(), microserviceId)).findFirst(); // can't build release path, cause microservice with given id is not present in graph - if (!graph.containsVertex(target)) { + if (!maybeTarget.isPresent()) { return Optional.empty(); } + final Microservice target = maybeTarget.get(); + final ConnectivityInspector inspector = new ConnectivityInspector<>(graph); final Set connectedSet = inspector.connectedSetOf(target); diff --git a/src/main/resources/config/application-postgres.yml b/src/main/resources/config/application-postgres.yml new file mode 100644 index 0000000..ff431a6 --- /dev/null +++ b/src/main/resources/config/application-postgres.yml @@ -0,0 +1,80 @@ +# =================================================================== +# Spring Boot configuration for the "heroku" profile. +# +# This configuration overrides the application.yml file. +# =================================================================== + +# =================================================================== +# Standard Spring Boot properties. +# Full reference is available at: +# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html +# =================================================================== + +spring: + liquibase: + enabled: true + datasource: + type: com.zaxxer.hikari.HikariDataSource + driver-class-name: org.postgresql.Driver + url: ${JDBC_DATABASE_URL} + username: ${JDBC_DATABASE_USERNAME} + password: ${JDBC_DATABASE_PASSWORD} + hikari: + poolName: Hikari + auto-commit: false + jpa: + database-platform: io.github.jhipster.domain.util.FixedPostgreSQL10Dialect + show-sql: false + h2: + console: + enabled: false + mail: + host: localhost + port: 25 + username: + password: + thymeleaf: + cache: true + +server: + port: 8080 + compression: + enabled: true + mime-types: text/html,text/xml,text/plain,text/css, application/javascript, application/json + min-response-size: 1024 + +jhipster: + http: + cache: # Used by the CachingHttpHeadersFilter + timeToLiveInDays: 1461 + cache: # Cache configuration + ehcache: # Ehcache configuration + time-to-live-seconds: 3600 # By default objects stay 1 hour in the cache + max-entries: 1000 # Number of objects in each cache entry + security: + authentication: + jwt: + # This token must be encoded using Base64 and be at least 256 bits long (you can type `openssl rand -base64 64` on your command line to generate a 512 bits one) + # As this is the PRODUCTION configuration, you MUST change the default key, and store it securely: + # - In the JHipster Registry (which includes a Spring Cloud Config server) + # - In a separate `application-prod.yml` file, in the same folder as your executable JAR file + # - In the `JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET` environment variable + base64-secret: YzljOTRhYTYwMDkwM2RhYjIxOGU2MTNjMDRjMDIyMjJjNjUyMzlmNzM5MjU1MzY3ZDI4NWFkY2YxNTM1YmI3N2EyZjRiNGE3OGZlYzcxNjJkYmRiNDNlNGFjYzI2YWZjMWNiYzI3NjE1NmVlMWJhMWVjNzZhNzhhNDY4Yzg0MzA= + # Token is valid 24 hours + token-validity-in-seconds: 86400 + token-validity-in-seconds-for-remember-me: 2592000 + mail: # specific JHipster mail property, for standard properties see MailProperties + base-url: http://my-server-url-to-change # Modify according to your server's URL + metrics: + logs: # Reports metrics in the logs + enabled: false + report-frequency: 60 # in seconds + logging: + use-json-format: false # By default, logs are not in Json format + logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration + enabled: false + host: localhost + port: 5000 + queue-size: 512 + audit-events: + retention-period: 30 # Number of days before audit events are deleted. diff --git a/src/test/java/com/github/microcatalog/web/rest/errors/custom/ReleasePathAdviceTraitTest.java b/src/test/java/com/github/microcatalog/web/rest/errors/custom/ReleasePathAdviceTraitTest.java new file mode 100644 index 0000000..9b71515 --- /dev/null +++ b/src/test/java/com/github/microcatalog/web/rest/errors/custom/ReleasePathAdviceTraitTest.java @@ -0,0 +1,77 @@ +package com.github.microcatalog.web.rest.errors.custom; + +import com.github.microcatalog.service.custom.exceptions.CircularDependenciesException; +import com.github.microcatalog.service.custom.exceptions.SelfCircularException; +import com.github.microcatalog.utils.MicroserviceBuilder; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; +import org.zalando.problem.Problem; + +import java.util.Arrays; +import java.util.HashSet; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; +import static org.mockito.Mockito.spy; + +@ExtendWith(MockitoExtension.class) +class ReleasePathAdviceTraitTest { + + private final ReleasePathAdviceTrait cut = spy(ReleasePathAdviceTrait.class); + + @Mock + private NativeWebRequest webRequest; + + @Test + void handleSelfCircularException() { + + final SelfCircularException exception = + new SelfCircularException("Test message", new MicroserviceBuilder().withId(1L).build()); + ResponseEntity response = cut.handleSelfCircularException(exception, webRequest); + + assertThat(response).isNotNull() + .extracting(HttpEntity::getBody).isNotNull(); + + assertThat(response.getStatusCodeValue()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY.value()); + + assertThat(response.getBody()).isNotNull() + .extracting(Problem::getParameters, InstanceOfAssertFactories.map(String.class, Object.class)) + .contains( + entry(ReleasePathAdviceTrait.HEADER_KEY, exception.getClass().getName()), + entry(ReleasePathAdviceTrait.MESSAGE_KEY, "Test message"), + entry(ReleasePathAdviceTrait.PAYLOAD_KEY, "id = 1, name = null") + ); + } + + @Test + void handleCircularDependenciesException() { + final CircularDependenciesException exception = + new CircularDependenciesException("Test message", new HashSet<>(Arrays.asList( + new MicroserviceBuilder().withId(1L).build(), + new MicroserviceBuilder().withId(2L).build(), + new MicroserviceBuilder().withId(3L).build() + ))); + + ResponseEntity response = cut.handleCircularDependenciesException(exception, webRequest); + + assertThat(response).isNotNull() + .extracting(HttpEntity::getBody).isNotNull(); + + assertThat(response.getStatusCodeValue()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY.value()); + + assertThat(response.getBody()).isNotNull() + .extracting(Problem::getParameters, InstanceOfAssertFactories.map(String.class, Object.class)) + .contains( + entry(ReleasePathAdviceTrait.HEADER_KEY, exception.getClass().getName()), + entry(ReleasePathAdviceTrait.MESSAGE_KEY, "Test message"), + entry(ReleasePathAdviceTrait.PAYLOAD_KEY, "1,2,3") + ); + } +}