diff --git a/build.gradle b/build.gradle index c3791c1..027efda 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,8 @@ dependencies { compile 'org.springframework.boot:spring-boot-starter-webflux' compile 'org.springframework.boot:spring-boot-starter-web' compile 'org.springframework.boot:spring-boot-starter-data-jpa' - compile 'mysql:mysql-connector-java' + compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5' + compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1' @@ -50,5 +51,7 @@ dependencies { annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Final' testCompile 'org.springframework.boot:spring-boot-starter-test' - testCompile group: 'com.h2database', name: 'h2', version: '1.4.197' + testCompile group: 'org.testcontainers', name: 'postgresql', version: '1.11.1' + testCompile "org.testcontainers:junit-jupiter:1.11.1" + testCompile group: 'io.rest-assured', name: 'rest-assured', version: '3.3.0' } \ No newline at end of file diff --git a/devops/docker-compose.yml b/devops/docker-compose.yml index a405c12..5e63b1e 100644 --- a/devops/docker-compose.yml +++ b/devops/docker-compose.yml @@ -9,40 +9,20 @@ services: environment: - MYSQL_ROOT_PASSWORD=admin - MYSQL_DATABASE=timecoder + postgresql: + image: postgres volumes: - - "./mycustom.cnf:/etc/mysql/conf.d/custom.cnf" - timecoder-api: - image: spirogov/timecoder:1.3 - container_name: timecoder - depends_on: - - mysql + - "db-data:/var/lib/postgresql/data" + - "./init.sql:/docker-entrypoint-initdb.d/init.sql" environment: - - SPRING_PROFILES_ACTIVE=prod - links: - - mysql - timecoder-patrons: - image: spirogov/timecoder-patrons:1.4.0 - container_name: timecoder-patrons - environment: - - accessToken=9rhhc4gNwwP6paXH2VPiO81VB0HoIKjjzKozvuRunXI - timecoder-gateway: - image: spirogov/timecoder-gateway:1.5.3 - container_name: timecoder-gateway - depends_on: - - mysql - ports: - - 8086:5000 - environment: - - SPRING_PROFILES_ACTIVE=prod - links: - - timecoder-api - ui: - image: spirogov/timecoder-ui:1.3.4 - container_name: timecoder-ui + POSTGRES_PASSWORD: admin ports: - - 80:80 - volumes: - - "./nginx.conf:/etc/nginx/conf.d/default.conf" - links: - - timecoder-gateway + - 5432:5432 + adminer: + image: adminer + restart: always + ports: + - 8088:8080 +volumes: + db-data: \ No newline at end of file diff --git a/devops/init.sql b/devops/init.sql new file mode 100644 index 0000000..3e1dd0b --- /dev/null +++ b/devops/init.sql @@ -0,0 +1 @@ +CREATE DATABASE timecoder; \ No newline at end of file diff --git a/devops/mycustom.cnf b/devops/mycustom.cnf deleted file mode 100644 index 991d2b9..0000000 --- a/devops/mycustom.cnf +++ /dev/null @@ -1,4 +0,0 @@ -[mysqld] -character-set-server = utf8 -collation-server = utf8_unicode_ci -skip-character-set-client-handshake \ No newline at end of file diff --git a/devops/nginx.conf b/devops/nginx.conf deleted file mode 100644 index 9f72893..0000000 --- a/devops/nginx.conf +++ /dev/null @@ -1,46 +0,0 @@ -server { - - listen 80; - - sendfile on; - - default_type application/octet-stream; - - - gzip on; - gzip_http_version 1.1; - gzip_disable "MSIE [1-6]\."; - gzip_min_length 256; - gzip_vary on; - gzip_proxied expired no-cache no-store private auth; - gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; - gzip_comp_level 9; - - - root /usr/share/nginx/html; - - - location / { - try_files $uri $uri/ /index.html =404; - } - - location /api { - rewrite ^/api/(.*) /$1 break; - # proxy_redirect off; - # proxy_buffering off; - # proxy_cache off; - # chunked_transfer_encoding off; - proxy_pass http://timecoder-gateway:5000; - # proxy_set_header X-Real-IP $remote_addr; - # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - # proxy_set_header X-Forwarded-Proto https; - # proxy_set_header Authorization $http_authorization; - # proxy_set_header Connection ''; - # proxy_http_version 1.1; - proxy_set_header Connection ''; - proxy_http_version 1.1; - chunked_transfer_encoding off; - proxy_buffering off; - proxy_cache off; - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e9bae9d..c997070 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,22 +6,32 @@ spring: spring: profiles: dev datasource: - username: root + username: postgres password: admin - url: jdbc:mysql://localhost:3306/timecoder?useUnicode=yes&characterEncoding=UTF-8 + url: jdbc:postgresql://localhost:5432/timecoder jpa: + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQL9Dialect + jdbc: + lob: + non_contextual_creation: true hibernate: ddl-auto: update - database: mysql --- spring: profiles: prod datasource: - username: root + username: postgres password: admin - url: jdbc:mysql://mysql:3306/timecoder?useUnicode=yes&characterEncoding=UTF-8 + url: jdbc:postgresql://postgresql:5432/timecoder jpa: + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQL9Dialect + jdbc: + lob: + non_contextual_creation: true hibernate: - ddl-auto: update - database: mysql \ No newline at end of file + ddl-auto: update \ No newline at end of file diff --git a/src/test/java/com/timecoder/test/EpisodeControllerTest.java b/src/test/java/com/timecoder/test/EpisodeControllerTest.java new file mode 100644 index 0000000..c45b9e7 --- /dev/null +++ b/src/test/java/com/timecoder/test/EpisodeControllerTest.java @@ -0,0 +1,53 @@ +package com.timecoder.test; + +import com.timecoder.TimecoderApplication; +import com.timecoder.dto.EpisodeDto; +import io.restassured.RestAssured; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +@ContextConfiguration(classes = TimecoderApplication.class) +@Testcontainers +@TestPropertySource(value={"classpath:application.properties"}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class EpisodeControllerTest { + + @Value("${server.port}") + int port; + + @Container + private final PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer() + .withDatabaseName("timecoder") + .withUsername("root") + .withPassword("admin"); + + @BeforeEach + void setUp() { + int port = postgreSQLContainer.getFirstMappedPort(); + System.setProperty("spring.datasource.url", String.format("jdbc:postgresql://loca:%d/postgres", postgreSQLContainer.getFirstMappedPort())); + RestAssured.port = port; + } + + @Test + void testCanCreateEpisode() { + EpisodeDto episodeDto = new EpisodeDto(); + episodeDto.setName("#1"); + + RestAssured.given() + .body(episodeDto) + .when() + .post("/episodes") + .then() + .statusCode(200) + .body("status", Matchers.equalTo("")); + } +}