Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/eKeiran #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -66,6 +71,11 @@
<version>7.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
</dependency>

<!-- <dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -98,7 +108,27 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<excludes>
<exclude>**/*Config.*</exclude>
<exclude>**/*Dev.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
Expand All @@ -11,6 +12,7 @@
@SpringBootApplication(scanBasePackages = {"com.gamedoora.model.*" , "com.gamedoora.backend.*"} , exclude = {DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})
@EntityScan(basePackages = "com.gamedoora.model.dao") //added since Not a managed type: class com.gamedoora.model.dao.Studios
public class GamedooraStudioServicesApplication {

public static void main(String[] args) {
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain this change made in the assembler class, think of it this way: when I request findById() from the repository, Ids are unique so using a single object of Studio seems better than using list as there always going to be one object, it might be the case that I have missed out something so please update me if I missed out on anything

Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ public List<StudiosDTO> getAllStudiosByUsersFirstName(String name){
}
return (studiosDto.isEmpty() ? null : studiosDto);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public interface StudioRepository extends JpaRepository<Studios , Long> {
//List User is registered by a particular Studio or not, param-Studio ID

//Hang-On till we reach aggregator part
}
}
5 changes: 2 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
debug=false
configserver.port=8082
spring.application.name=studioservice
spring.application.name=studioservices
spring.config.import=configserver:${CONFIG_SERVER}
spring.jpa.open-in-view=false
spring.flyway.baseline-on-migrate = true

spring.flyway.baseline-on-migrate = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.gamedoora.backend.studioservices.repository;
import com.gamedoora.model.dao.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@DataJpaTest(properties = {"spring.cloud.config.enabled=false"})
public class StudioRepositoryTest {

@Autowired
public StudioRepository studioRepository;

@Test
public void testFindByRegistration() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test looks good, just one addition, since it is a list, the recommended way is adding more than one object into the repository and then fetching them into the list and verify the size and properties of those studio object using assertEquals.

Studios studio1 = Studios.builder().id(42).name("keera").registration(true).build();
Studios studio2 = Studios.builder().id(43).name("john").registration(true).build();
studioRepository.saveAll(List.of(studio1, studio2));

List<Studios> registeredStudios = studioRepository.findByRegistration(true);
assertThat(registeredStudios).isNotEmpty();
assertEquals(2, registeredStudios.size());
}

@Test
public void testFindByVisibility() {
Studios studio1 = Studios.builder().id(14).name("hd").visibility(true).build();
Studios studio2 = Studios.builder().id(15).name("smith").visibility(true).build();
studioRepository.saveAll(List.of(studio1, studio2));

List<Studios> visibleStudios = studioRepository.findByVisibility(true);
assertThat(visibleStudios).isNotEmpty();
assertEquals(2, visibleStudios.size());
}

}
15 changes: 15 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
db.primary.url=jdbc:h2:mem:testdb1;MODE=PostgreSQL
db.primary.password=pass
db.primary.driver=org.h2.Driver
db.primary.hbm2ddl.auto=create-drop
db.primary.user=dh
db.primary.hibernate.dialect=org.hibernate.dialect.H2Dialect

spring.h2.console.enabled=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.flyway.enabled=false
keycloak.server.url=http://127.0.0.1:8082/u/auth
keycloak.server.username=admin
keycloak.server.password=admin
keycloak.server.clientid=
keycloak.server.realm=master