Skip to content

Commit

Permalink
feat: add cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
osopromadze committed Feb 12, 2024
1 parent 655b996 commit 225ec06
Show file tree
Hide file tree
Showing 52 changed files with 419 additions and 250 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assignees: ''

---

**Is your feature request related to a problem? Please describe.**
**Is your karate request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
Expand All @@ -17,4 +17,4 @@ A clear and concise description of what you want to happen.
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
Add any other context or screenshots about the karate request here.
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Fixes # (issue)
Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] New karate (non-breaking change which adds functionality)
- [ ] Breaking change (fix or karate that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

#### How Has This Been Tested?
Expand Down
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ a computer network, with no transfer of a copy, is not conveying.

An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
karate that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
Expand Down
35 changes: 9 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
version: '3.8'
services:
db:
image: mysql
container_name: blogapi-db
restart: always
environment:
MYSQL_DATABASE: 'blogapi'
MYSQL_PASSWORD: 'root'
MYSQL_ROOT_PASSWORD: 'root'
postgres:
image: postgres:14-alpine
container_name: blogapi-postgres
ports:
- '3306:3306'
networks:
- blogapi-network
healthcheck:
test: "/usr/bin/mysql --user=root --password=root --execute \"SHOW DATABASES;\""
interval: 2s
timeout: 20s
retries: 10
- "5432:5432"
volumes:
- ./data:/docker-entrypoint-initdb.d
application:
container_name: blogapi-application
build:
context: ./
dockerfile: Dockerfile
ports:
- "8080:8080"
- ~/apps/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_USER=root
- POSTGRES_DB=blogapi
networks:
- blogapi-network
depends_on:
- "db"
networks:
blogapi-network:
name: blogapi-network
Expand Down
66 changes: 59 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
<org.projectlombok.version>1.18.28</org.projectlombok.version>
<org.projectlombok.version>1.18.30</org.projectlombok.version>
<cucumber.version>7.15.0</cucumber.version>
<testcontainers.version>1.19.5</testcontainers.version>
<jacoco.version>0.8.10</jacoco.version>
<sonar.organization>coma123</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand All @@ -43,9 +45,8 @@
</dependency>

<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.1.0</version>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -156,6 +157,57 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>1.10.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
Expand All @@ -165,8 +217,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
Expand Down
18 changes: 1 addition & 17 deletions src/main/java/com/sopromadze/blogapi/BlogApiApplication.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.sopromadze.blogapi;

import com.sopromadze.blogapi.security.JwtAuthenticationFilter;
import jakarta.annotation.PostConstruct;
import org.modelmapper.ModelMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.data.convert.Jsr310Converters;

import java.util.TimeZone;

@SpringBootApplication
@EntityScan(basePackageClasses = {BlogApiApplication.class, Jsr310Converters.class})

//@EntityScan(basePackageClasses = {BlogApiApplication.class, Jsr310Converters.class})
public class BlogApiApplication {

public static void main(String[] args) {
Expand All @@ -25,14 +19,4 @@ void init() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}

@Bean
public JwtAuthenticationFilter jwtAuthenticationFilter() {
return new JwtAuthenticationFilter();
}

@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/sopromadze/blogapi/config/ConfigBeans.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.sopromadze.blogapi.config;

import com.sopromadze.blogapi.security.JwtAuthenticationFilter;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfigBeans {
@Bean
public JwtAuthenticationFilter jwtAuthenticationFilter() {
return new JwtAuthenticationFilter();
}

@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
}
14 changes: 10 additions & 4 deletions src/main/java/com/sopromadze/blogapi/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.authentication.AuthenticationManagerFactoryBean;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
Expand Down Expand Up @@ -51,9 +51,15 @@ public SecurityFilterChain configure(HttpSecurity http) throws Exception {
return http.build();
}

@Bean(BeanIds.AUTHENTICATION_MANAGER)
@Bean()
public AuthenticationManager authenticationManagerBean() throws Exception {
return new AuthenticationManagerFactoryBean().getObject();
return new AuthenticationManager() {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
return null;
}
};
// return new AuthenticationManagerFactoryBean().getObject();
}

@Bean
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/sopromadze/blogapi/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

@Value("cors.allowedOrings")
private String allowedOrigins;
@Value("${cors.allowed_origins:}")
private String allowedOrigins;

public void addCorsMappings(CorsRegistry registry) {
final long MAX_AGE_SECS = 3600;
@Override
public void addCorsMappings(CorsRegistry registry) {
final long MAX_AGE_SECS = 3600;

registry.addMapping("/**")
.allowedOrigins(allowedOrigins)
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.maxAge(MAX_AGE_SECS);
}

registry.addMapping("/**")
.allowedOrigins(allowedOrigins)
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.maxAge(MAX_AGE_SECS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public class AuthController {
@Autowired
private AuthenticationManager authenticationManager;

@Autowired
// @Autowired
private UserRepository userRepository;

@Autowired
// @Autowired
private RoleRepository roleRepository;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import com.sopromadze.blogapi.infrastructure.persistence.mysql.entity.TagEntity;
import com.sopromadze.blogapi.infrastructure.persistence.mysql.mapper.TagEntityMapper;
import com.sopromadze.blogapi.infrastructure.persistence.mysql.repository.TagMysqlRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
//@RequiredArgsConstructor
@Service
public class TagPersistenceMysqlAdapter implements TagPersistencePort {

private final TagMysqlRepository tagMysqlRepository;
private final TagEntityMapper tagEntityMapper;
private TagMysqlRepository tagMysqlRepository;
private TagEntityMapper tagEntityMapper;

@Override
public Tag createTag(Tag tag) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.sopromadze.blogapi.infrastructure.persistence.mysql.entity;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.sopromadze.blogapi.model.Post;
import com.sopromadze.blogapi.model.audit.UserDateAudit;
import jakarta.persistence.*;
import lombok.*;

import java.util.List;
Expand All @@ -15,21 +12,21 @@
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "tags")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
//@Entity
//@Table(name = "tags")
//@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class TagEntity extends UserDateAudit {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "name")
// @Column(name = "name")
private String name;

@JsonIgnore
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "post_tag", joinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "post_id", referencedColumnName = "id"))
// @ManyToMany(fetch = FetchType.EAGER)
// @JoinTable(name = "post_tag", joinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "post_id", referencedColumnName = "id"))
private List<Post> posts;

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package com.sopromadze.blogapi.infrastructure.persistence.mysql.repository;

import com.sopromadze.blogapi.infrastructure.persistence.mysql.entity.TagEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

@Repository
public interface TagMysqlRepository extends JpaRepository<TagEntity, Long> {
import java.util.Optional;

//@Repository
public interface TagMysqlRepository {
TagEntity findByName(String name);

TagEntity save(TagEntity entity);

Page<TagEntity> findAll(Pageable pageable);

Optional<TagEntity> findById(Long id);

void deleteById(Long id);

}
Loading

0 comments on commit 225ec06

Please sign in to comment.