diff --git a/Dockerfile b/Dockerfile index fb893b3..d2e2ce2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,8 @@ #ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] + + ##Maven Build #FROM maven:3.8.3-openjdk-17 AS builder #COPY pom.xml /app/ diff --git a/README.md b/README.md index ca85926..1bee00b 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,3 @@ JWT_SECRET_KEY=jwt_key JWT_EXPIRATION=86400000 # a day JWT_REFRESH_EXPIRATION=2592000000 # 30 day ``` -======= -#datum diff --git a/pom.xml b/pom.xml index 42ead5a..478f179 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,13 @@ springdoc-openapi-starter-webmvc-ui 2.2.0 + + + io.springfox + springfox-boot-starter + 3.0.0 + + org.springframework spring-context-support diff --git a/src/main/java/datum/Main.java b/src/main/java/datum/Main.java index 1c777ad..46b401a 100644 --- a/src/main/java/datum/Main.java +++ b/src/main/java/datum/Main.java @@ -8,12 +8,19 @@ import jakarta.annotation.PostConstruct; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.servlet.function.RouterFunction; +import org.springframework.web.servlet.function.ServerResponse; +import java.net.URI; import java.util.Random; import java.util.TimeZone; import java.util.regex.Pattern; +import static org.springframework.web.servlet.function.RequestPredicates.GET; +import static org.springframework.web.servlet.function.RouterFunctions.route; + @SpringBootApplication public class Main { public static final Random random = new Random(); diff --git a/src/main/java/datum/app/Demo.java b/src/main/java/datum/app/Demo.java index f1ac8bc..805eaeb 100644 --- a/src/main/java/datum/app/Demo.java +++ b/src/main/java/datum/app/Demo.java @@ -20,97 +20,13 @@ @RequestMapping("/TEST") @RequiredArgsConstructor public class Demo { -// private final PersonRepository personRepository; @GetMapping public ResponseEntity get( HttpServletRequest request, HttpServletResponse response ) { -// Map map = new HashMap<>(); -// map.put("getMethod", request.getMethod()); -// map.put("getPathInfo", request.getPathInfo()); -// map.put("getServletPath", request.getServletPath()); -// map.put("getContextPath", request.getContextPath()); -// map.put("getRequestURI", request.getRequestURI()); -// map.put("getRequestURL", request.getRequestURL()); -// map.put("getPathTranslated", request.getPathTranslated()); -// -// return ResponseEntity.ok(map); return ResponseEntity.ok(Map.of(1, "Hello, Get!")); } -// -// @PostMapping -// public ResponseEntity post( -// HttpServletRequest request, -// HttpServletResponse response -// ) { -//// List persons = List.of( -//// Person.builder().firstname("person1").build(), -//// Person.builder().firstname("person2").build() -//// ); -//// personRepository.saveAll(persons); -//// persons.get(0).setDeleted(true); -//// personRepository.save(persons.get(0)); -//// var persons2 = personRepository.findAll(); -//// return ResponseEntity.ok(List.of(persons, persons2)); -// return ResponseEntity.ok("Hello, Post!"); -// } -// -// @PutMapping -// public ResponseEntity put( -// HttpServletRequest request, -// HttpServletResponse response -// ) { -// return ResponseEntity.ok("Hello, Put!"); -// } -// -// @DeleteMapping -// public ResponseEntity delete( -// HttpServletRequest request, -// HttpServletResponse response -// ) { -// return ResponseEntity.ok("Hello, Delete!"); -// } -// -// @PatchMapping("/{var}/{id}") -// public ResponseEntity patch( -// HttpServletRequest request, -// HttpServletResponse response, -// @PathVariable("var") String var, -// @PathVariable("id") String id -// ) { -// return ResponseEntity.ok("Hello, " + var + " " + id); -////// UrlPathHelper -//// Map map = new HashMap<>(); -//// map.put("var", var); -//// map.put("id", id); -//// map.put("getMethod", request.getMethod()); -//// map.put("getPathInfo", request.getPathInfo()); -//// map.put("getServletPath", request.getServletPath()); -//// map.put("getContextPath", request.getContextPath()); -//// map.put("getRequestURI", request.getRequestURI()); -//// map.put("getRequestURL", request.getRequestURL()); -//// map.put("getPathTranslated", request.getPathTranslated()); -//// map.put("getRemoteUser", request.getRemoteUser()); -//// map.put("getHttpServletMapping", request.getHttpServletMapping()); -//// map.put("getQueryString", request.getQueryString()); -//// map.put("getScheme", request.getScheme()); -//// map.put("getTrailerFields", request.getTrailerFields()); -//// map.put("getParameterMap", request.getParameterMap()); -//// map.put("getProtocol", request.getProtocol()); -//// map.put("getAttributeNames", request.getAttributeNames()); -//// map.put("getAttribute", request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE)); -// -// -//// return ResponseEntity.ok(map); -// } -// -// public ResponseEntity test( -// HttpServletRequest request, -// HttpServletResponse response -// ) { -// return ResponseEntity.ok("Hello, Patch!"); -// } } diff --git a/src/main/java/datum/app/admin/dto/PersonDTO.java b/src/main/java/datum/app/admin/dto/PersonDTO.java index 1df3fbf..b2a7890 100644 --- a/src/main/java/datum/app/admin/dto/PersonDTO.java +++ b/src/main/java/datum/app/admin/dto/PersonDTO.java @@ -19,7 +19,6 @@ @NoArgsConstructor @ToString @Jacksonized -//@Schema(description = "Информация о человеке") @Schema public class PersonDTO implements Serializable { diff --git a/src/main/java/datum/authenticate/UserRepository.java b/src/main/java/datum/authenticate/UserRepository.java index 9e3a660..8c1a3b2 100644 --- a/src/main/java/datum/authenticate/UserRepository.java +++ b/src/main/java/datum/authenticate/UserRepository.java @@ -22,27 +22,22 @@ public interface UserRepository extends JpaRepository { // boolean existsByEmailIgnoreCaseAndCodeIsNull(String email); // boolean existsByEmailIgnoreCaseAndCodeIsNullAndLockedFalse(String email); -// @Transactional @Modifying @Query("UPDATE User a SET a.enabled = TRUE, a.locked=FALSE, a.code = NULL WHERE a.email = ?1 AND a.code = ?2") void updateUserByEmailAndCode(String email, Integer code); -// @Transactional @Modifying @Query("UPDATE User a SET a.enabled = TRUE, a.locked=FALSE, a.code = NULL WHERE a.email = ?1") void enableUserByEmail(String email); -//@Transactional @Modifying @Query("UPDATE User u SET u.password = null WHERE u.email = ?1 AND u.code = ?2") boolean updateUserPasswordByEmailIgnoreCaseAndCode(String email, Integer code); -// @Transactional @Modifying @Query("UPDATE User u SET u.password = ?1 WHERE u.email = ?2") boolean updateUserPasswordByEmailIgnoreCase(String password, String email); -// @Transactional @Modifying @Query("UPDATE User u SET u.password = ?1 WHERE u.email = ?2 AND u.password IS NULL") boolean updatePasswordByEmail(String password, String email); diff --git a/src/main/java/datum/config/OpenApiConfig.java b/src/main/java/datum/config/OpenApiConfig.java index 72d42f4..6b1c483 100644 --- a/src/main/java/datum/config/OpenApiConfig.java +++ b/src/main/java/datum/config/OpenApiConfig.java @@ -13,16 +13,16 @@ @OpenAPIDefinition( info = @Info( // contact = @Contact( -// name = "Alibou", -// email = "contact@aliboucoding.com", -// url = "https://aliboucoding.com/course" +// name = "name", +// email = "contact@gmail.com", +// url = "https://example.com/" // ), description = "datum crm system", title = "datum", version = "1.0", // license = @License( // name = "Licence name", -// url = "https://some-url.com" +// url = "https://eaxmple.com" // ), termsOfService = "http://swagger.io/terms/" ), diff --git a/src/main/java/datum/config/SecurityConfiguration.java b/src/main/java/datum/config/SecurityConfiguration.java index c5023e4..94d60b4 100644 --- a/src/main/java/datum/config/SecurityConfiguration.java +++ b/src/main/java/datum/config/SecurityConfiguration.java @@ -42,7 +42,9 @@ public class SecurityConfiguration { "/AUTHENTICATE/**", "/TEST", "/TEST/**", - "/v2/api-docs", + "/api", + "/api/**", + "/doc", "/v3/api-docs", "/v3/api-docs/**", "/swagger-resources", diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8f716f1..6456cf2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -42,4 +42,32 @@ application: secret_key: ${JWT_SECRET_KEY} expiration: ${JWT_EXPIRATION} refresh-token: - expiration: ${JWT_REFRESH_EXPIRATION} \ No newline at end of file + expiration: ${JWT_REFRESH_EXPIRATION} +#springdoc: +# api-docs: +# path: /doc +# swagger-ui: +# path: /api + + +#springfox: +# documentation: +# swaggerUi: +# baseUrl: /api +# openApi: +# v3: +# path: /doc +# swagger: +# v2: +# path: /doc2 + +#springfox: +# documentation: +# swagger-ui: +# base-url: /api +# openapi: +# v3: +# path: /doc +# swagger: +# v2: +# path: /doc2 diff --git a/src/main/resources/json.passport/kg2004.json b/src/main/resources/json.passport/kg2004.json deleted file mode 100644 index 9973168..0000000 --- a/src/main/resources/json.passport/kg2004.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "Authority": "SRS", - "Date of Birth": "1996-02-03", - "Date of Expiry": "2024-03-14", - "Date of Issue": "2014-03-14", - "Document Name": "Kyrgyzstan-Passport", - "Document Number": "AC2349309", - "Full Name": "MAKKAMBAEV DASTAN", - "Given Names": "DASTAN", - "Issuing State Code": "KGZ", - "Issuing State Name": "Kyrgyzstan", - "MRZ": { - "Date of Birth": "1996-02-03", - "Date of Expiry": "2024-03-14", - "Document Class Code": "P", - "Document Number": "AC2349309", - "Full Name": "MAKKAMBAEV DASTAN", - "Given Names": "DASTAN", - "Issuing State Code": "KGZ", - "Issuing State Name": "Kyrgyzstan", - "MRZ Code": "P": "ТП №2 ОУФМС РОССИИ ПО МОСКОВСКОЙ ОБЛАСТИ ПО ЛУХОВИЦКОМУ МУНИЦИПАЛЬНОМУ РАЙОНУ", - "Authority-Russian": "ГУ МВД РОССИИ,ПО МОСКОВСКОЙ ОБЛАСТИ", - "Booklet Number": "662029", - "Date of Birth": "1997-05-21", - "Date of Expiry": "2042-05-21", - "Date of Issue": "2022-07-12", - "Document Name": "Russian Federation-Passport", - "Document Number": "4622662029", - "Document Series": "4622", - "Fathers Name": "TALANTBEKOVICH", - "Fathers Name-Russian": "ТАЛАНТБЕКОВИЧ", - "Full Name": "MAKKAMBAEV BEKZHAN TALANTBEKOVICH", - "Full Name-Russian": "МАККАМБАЕВ БЕКЖАН ТАЛАНТБЕКОВИЧ", - "Given Names": "BEKZHAN", - "Given Names-Russian": "БЕКЖАН", - "MRZ": { - "Authority": "ТП №2 ОУФМС РОССИИ ПО МОСКОВСКОЙ ОБЛАСТИ ПО ЛУХОВИЦКОМУ МУНИЦИПАЛЬНОМУ РАЙОНУ", - "Authority Code": "500071", - "Authority RUS": "Московская область", - "Date of Birth": "1997-05-21", - "Date of Expiry": "2042-05-21", - "Date of Issue": "2022-07-12", - "Document Class Code": "PN", - "Document Number": "4622662029", - "Fathers Name": "ТАЛАНТБЕКОВИЧ", - "Full Name": "МАККАМБАЕВ БЕКЖАН ТАЛАНТБЕКОВИЧ", - "Given Names": "БЕКЖАН", - "Issuing State Code": "RUS", - "Issuing State Name": "Russian Federation", - "MRZ Code": "PNRUSMAKKAMBAEV<": "ОТДЕЛЕНИЕ УФМС РОССИИ ПО ГОР. МОСКВЕ ПО РАЙОНУ ХАМОВНИКИ", - "Authority-Russian": "ОТДЕЛЕНИЕМ,УФМС РОССИИ ПО ГОР. МОСКВЕ,ПО РАЙОНУ ХАМОВНИКИ", - "Booklet Number": "505609", - "Date of Birth": "1991-11-22", - "Date of Expiry": "2036-11-22", - "Date of Issue": "2011-11-29", - "Document Name": "Russian Federation-Passport", - "Document Number": "4511505609", - "Document Series": "4511", - "Fathers Name": "VALEREVICH", - "Fathers Name-Russian": "ВАЛЕРЬЕВИЧ", - "Full Name": "ZAKHAROV VLADISLAV VALEREVICH", - "Full Name-Russian": "ЗАХАРОВ ВЛАДИСЛАВ ВАЛЕРЬЕВИЧ", - "Given Names": "VLADISLAV", - "Given Names-Russian": "ВЛАДИСЛАВ", - "MRZ": { - "Authority": "ОТДЕЛЕНИЕ УФМС РОССИИ ПО ГОР. МОСКВЕ ПО РАЙОНУ ХАМОВНИКИ", - "Authority Code": "770011", - "Authority RUS": "Москва", - "Date of Birth": "1991-11-22", - "Date of Expiry": "2036-11-22", - "Date of Issue": "2011-11-29", - "Document Class Code": "PN", - "Document Number": "4511505609", - "Fathers Name": "ВАЛЕРЬЕВИЧ", - "Full Name": "ЗАХАРОВ ВЛАДИСЛАВ ВАЛЕРЬЕВИЧ", - "Given Names": "ВЛАДИСЛАВ", - "Issuing State Code": "RUS", - "Issuing State Name": "Russian Federation", - "MRZ Code": "PNRUSZAHAROV< - - - - - - - - -
-
- - - - - - -
-
- - - - - - -
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
 
- - Datum - -
 
-
- - - - - - - - - -
- - - - - - -
-
- - - - - - -
- - - - - - - - - - - - - -
- - - - - - -
- Подтвердите свой email -
-
- - - - - - -
- Просто нажмите на кнопку ниже и подтвердите адрес электронной почты. -
-
- - - - - - - - - -
-   -
- - - - - - -
- - - - - Подтвердить email - - - - -
-
-
-
-
-
-
- - - - - - -
-
- - - - - - -
- - - - - - - - - -
- - - - - - -
- - Если вы считаете, что это письмо было отправлено вам по ошибке, просто проигнорируйте его. - -
-
- - - - - - -
-
-
-
-
-
-
-
-
-
-
-
- - \ No newline at end of file diff --git a/src/test/java/datum/app/admin/implement/EndpointServiceImplTest.java b/src/test/java/datum/app/admin/implement/EndpointServiceImplTest.java index b20ece0..3f9cb9a 100644 --- a/src/test/java/datum/app/admin/implement/EndpointServiceImplTest.java +++ b/src/test/java/datum/app/admin/implement/EndpointServiceImplTest.java @@ -1,65 +1,66 @@ -//package datum.app.admin.implement; -// -//import datum.app.admin.model.Endpoint; -//import datum.app.admin.repository.EndpointRepository; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.util.List; -// -//import static org.junit.jupiter.api.Assertions.*; -// -//@ExtendWith(MockitoExtension.class) -//class EndpointServiceImplTest { -// @Mock -// private EndpointRepository endpointRepository; -// @InjectMocks -// private EndpointServiceImpl endpointService; -// Endpoint endpoint1= Endpoint.builder() -// .endpoint("/CLINIC/{clinicId}/employee/{employeeId}") -// .method("GET") -// .name("/CLINIC/{clinicId}/employee/{employeeId}") -// .build(); -// Endpoint endpoint2= Endpoint.builder() -// .endpoint("/CLINIC/{clinicId}") -// .method("GET") -// .name("/CLINIC/{clinicId}") -// .build(); -// List endpoints = List.of( endpoint1, endpoint2 ); -// +package datum.app.admin.implement; + +import datum.app.admin.model.Endpoint; +import datum.app.admin.repository.EndpointRepository; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class EndpointServiceImplTest { + @Mock + private EndpointRepository endpointRepository; + @InjectMocks + private EndpointServiceImpl endpointService; + Endpoint endpoint1 = Endpoint.builder() + .endpoint("/CLINIC/{clinicId}/employee/{employeeId}") + .method("GET") + .name("/CLINIC/{clinicId}/employee/{employeeId}") + .build(); + Endpoint endpoint2 = Endpoint.builder() + .endpoint("/CLINIC/{clinicId}") + .method("GET") + .name("/CLINIC/{clinicId}") + .build(); + List endpoints = List.of(endpoint1, endpoint2); + + @Test + void test_get() { + Mockito.when(endpointRepository.findAll()).thenReturn(endpoints); + List result = endpointService.get(); + assertEquals(2, result.size()); + assertTrue(result.get(0).getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); + } + + @Test + void test_Create() { + Mockito.when(endpointRepository.save(endpoint1)).thenReturn(endpoint1); + Endpoint result = endpointService.create(endpoint1); + assertTrue(result.getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); + } + + @Test + void test_Update() { + Mockito.when(endpointRepository.save(endpoint1)).thenReturn(endpoint1); + Endpoint result = endpointService.update(endpoint1); + assertTrue(result.getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); + } // @Test -// void test_get() { -// Mockito.when(endpointRepository.findAll()).thenReturn(endpoints); -// List result = endpointService.get(); -// assertEquals(2, result.size()); -// assertTrue(result.get(0).getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); +// void test_Delete() { +//EndpointId endpointId = EndpointId.builder() +// .endpoint(endpoint2.getEndpoint()) +// .method(endpoint2.getMethod()) +// .build(); +// Mockito.when(endpointRepository.deleteById(endpointId)); +//// Endpoint result = endpointService.update(endpoint1); +//// assertTrue(result.getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); // } -// -// @Test -// void test_Create() { -// Mockito.when(endpointRepository.saveAll(endpoints)).thenReturn(endpoints); -// Endpoint result = endpointService.create(endpoint1); -// assertTrue(result.getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); -// } -// @Test -// void test_Update() { -// Mockito.when(endpointRepository.save(endpoint1)).thenReturn(endpoint1); -// Endpoint result = endpointService.update(endpoint1); -// assertTrue(result.getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); -// } -//// @Test -//// void test_Delete() { -////EndpointId endpointId = EndpointId.builder() -//// .endpoint(endpoint2.getEndpoint()) -//// .method(endpoint2.getMethod()) -//// .build(); -//// Mockito.when(endpointRepository.deleteById(endpointId)); -////// Endpoint result = endpointService.update(endpoint1); -////// assertTrue(result.getEndpoint().contains("/CLINIC/{clinicId}/employee/{employeeId}")); -//// } -// -//} \ No newline at end of file + +} \ No newline at end of file diff --git a/src/test/java/datum/app/admin/implement/ICD10ServiceImplTest.java b/src/test/java/datum/app/admin/implement/ICD10ServiceImplTest.java index c8cd60d..737eec4 100644 --- a/src/test/java/datum/app/admin/implement/ICD10ServiceImplTest.java +++ b/src/test/java/datum/app/admin/implement/ICD10ServiceImplTest.java @@ -1,166 +1,166 @@ -//package datum.app.admin.implement; -// -//import datum.app.admin.dto.ICD10DTO; -//import datum.app.admin.mapping.ICD10Mapper; -//import datum.app.admin.model.ICD10; -//import datum.app.admin.repository.ICD10Repository; -//import datum.config.exception.ExceptionApp; -//import datum.config.exception.Message; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.util.List; -//import java.util.Optional; -// -//import static org.junit.jupiter.api.Assertions.*; -// -//@ExtendWith(MockitoExtension.class) -//class ICD10ServiceImplTest { -// @Mock -// private ICD10Repository icd10Repository; -// -// @InjectMocks -// private ICD10ServiceImpl icd10Service; -// ICD10 mockICD10 = ICD10.builder() -// .id(1L) -// .code("K00-K14") -// .chapter("XI") -// .block("K") -// .category(null) -// .subcategory(null) -// .item(null) -// .name("Diseases of oral cavity, salivary glands and jaws") -// .description("description") -// .dent(true) -// .build(); -// ICD10DTO icd10DTO1= ICD10DTO.builder() -// .name("K00.19 Сверхкомплектные зубы неуточненные") // K latin -// .dent(true) -// .build(); -// ICD10DTO icd10DTO2=ICD10DTO.builder() -// .name("К00.20 Макродентия") // К кириллица -// .dent(true) -// .build(); -// ICD10DTO icd10DTO3_error= ICD10DTO.builder() -// .name("К00.2 Макродентия") -// .dent(true) -// .build(); -// ICD10 icd10_dental = ICD10.builder() -// .code("K00.20") -// .chapter("XI") -// .block("K") -// .category(0) -// .subcategory(2) -// .item(0) -// .name("Макродентия") -// .description("description") -// .dent(true) -// .build(); -// List icd10DTOs = List.of(icd10DTO1, icd10DTO2); -// List icd10DTOs_err = List.of(icd10DTO3_error); -// Optional> icd10_dentals = Optional.of(List.of(icd10_dental)); -// @Test -// void test_GetDental() { -// Mockito.when(icd10Repository.findAllByBlockAndCategoryBetween("K", 0, 14)) -// .thenReturn(icd10_dentals); -// List result = icd10Service.getDental(); -// assertEquals(1, result.size()); -// assertEquals("XI", result.get(0).getChapter()); -// assertEquals("Макродентия", result.get(0).getName()); -// } -// @Test -// void test_GetDentalThrow() { -// Mockito.when(icd10Repository.findAllByBlockAndCategoryBetween("K", 0, 14)) -// .thenReturn(Optional.empty()); -// ExceptionApp exception = assertThrows( -// ExceptionApp.class, -// () -> icd10Service.getDental() -// ); -// assertEquals(404, exception.getCode()); -// assertEquals(Message.NOT_FOUND, exception.getMessage()); -// } -// @Test -// void test_Get() { -// Mockito.when(icd10Repository.findAll()).thenReturn(List.of(mockICD10)); -// List result = icd10Service.get(); -// assertEquals(1, result.size()); -// assertEquals(("K00-K14"), result.get(0).getCode()); -// } -// @Test -// void test_GetById() { -// Long id = mockICD10.getId(); -// Mockito.when(icd10Repository.findById(id)).thenReturn(Optional.of(mockICD10)); -// ICD10 result = icd10Service.get(id); -// assertEquals(("K00-K14"), result.getCode()); -// } -// @Test -// void test_GetByIdThrow() { -// Long id = mockICD10.getId(); -// Mockito.when(icd10Repository.findById(id)).thenReturn(Optional.empty()); -// ExceptionApp exception = assertThrows( -// ExceptionApp.class, -// () -> icd10Service.get(id) -// ); -// assertEquals(404, exception.getCode()); -// assertEquals(Message.NOT_FOUND, exception.getMessage()); -// } -// @Test -// void test_Create() { -// -// Mockito.when(icd10Repository.findFirstByBlock("K")).thenReturn(mockICD10); -// -// -// List testICD10 = ICD10Mapper.INSTANCE.convert(icd10DTOs); -// -// List result = icd10Service.create(testICD10); -// -// assertEquals(2, result.size()); -// -// ICD10 icd10 = result.get(0); -// assertEquals("K00.19", icd10.getCode()); -// assertEquals("XI", icd10.getChapter()); -// assertEquals("K", icd10.getBlock()); -// assertEquals(0, icd10.getCategory()); -// assertEquals(1, icd10.getSubcategory()); -// assertEquals(9, icd10.getItem()); -// assertEquals("Сверхкомплектные зубы неуточненные", icd10.getName()); -// assertTrue(icd10.isDent()); -// assertNull(icd10.getDescription()); -// -// ICD10 icd101 = result.get(1); -// assertEquals("K00.20", icd101.getCode()); -// assertEquals("XI", icd101.getChapter()); -// assertEquals("K", icd101.getBlock()); -// assertEquals(0, icd101.getCategory()); -// assertEquals(2, icd101.getSubcategory()); -// assertEquals(0, icd101.getItem()); -// assertEquals("Макродентия", icd101.getName()); -// assertTrue(icd101.isDent()); -// assertNull(icd101.getDescription()); -// } -// -// @Test -// void test_CreateThrow() { -// -// List testICD10 = ICD10Mapper.INSTANCE.convert(icd10DTOs_err); -// -// ExceptionApp exception = assertThrows( -// ExceptionApp.class, -// () -> icd10Service.create(testICD10) -// ); -// assertEquals(400, exception.getCode()); -// assertEquals("Не правильный код MKБ-10: К00.2", exception.getMessage()); -// -// } -// @Test -// void test_Update() { -// Mockito.when(icd10Repository.saveAll(List.of(mockICD10))).thenReturn(List.of(mockICD10)); -// List result = icd10Service.update(List.of(mockICD10)); -// assertEquals(1, result.size()); -// assertEquals(("K00-K14"), result.get(0).getCode()); -// } -//} \ No newline at end of file +package datum.app.admin.implement; + +import datum.app.admin.dto.ICD10DTO; +import datum.app.admin.mapping.ICD10Mapper; +import datum.app.admin.model.ICD10; +import datum.app.admin.repository.ICD10Repository; +import datum.config.exception.ExceptionApp; +import datum.config.exception.Message; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class ICD10ServiceImplTest { + @Mock + private ICD10Repository icd10Repository; + + @InjectMocks + private ICD10ServiceImpl icd10Service; + ICD10 mockICD10 = ICD10.builder() + .id(1L) + .code("K00-K14") + .chapter("XI") + .block("K") + .category(null) + .subcategory(null) + .item(null) + .name("Diseases of oral cavity, salivary glands and jaws") + .description("description") + .dent(true) + .build(); + ICD10DTO icd10DTO1= ICD10DTO.builder() + .name("K00.19 Сверхкомплектные зубы неуточненные") // K latin + .dent(true) + .build(); + ICD10DTO icd10DTO2=ICD10DTO.builder() + .name("К00.20 Макродентия") // К кириллица + .dent(true) + .build(); + ICD10DTO icd10DTO3_error= ICD10DTO.builder() + .name("К00.2 Макродентия") + .dent(true) + .build(); + ICD10 icd10_dental = ICD10.builder() + .code("K00.20") + .chapter("XI") + .block("K") + .category(0) + .subcategory(2) + .item(0) + .name("Макродентия") + .description("description") + .dent(true) + .build(); + List icd10DTOs = List.of(icd10DTO1, icd10DTO2); + List icd10DTOs_err = List.of(icd10DTO3_error); + Optional> icd10_dentals = Optional.of(List.of(icd10_dental)); + @Test + void test_GetDental() { + Mockito.when(icd10Repository.findAllByBlockAndCategoryBetween("K", 0, 14)) + .thenReturn(icd10_dentals); + List result = icd10Service.getDental(); + assertEquals(1, result.size()); + assertEquals("XI", result.get(0).getChapter()); + assertEquals("Макродентия", result.get(0).getName()); + } + @Test + void test_GetDentalThrow() { + Mockito.when(icd10Repository.findAllByBlockAndCategoryBetween("K", 0, 14)) + .thenReturn(Optional.empty()); + ExceptionApp exception = assertThrows( + ExceptionApp.class, + () -> icd10Service.getDental() + ); + assertEquals(404, exception.getCode()); + assertEquals(Message.NOT_FOUND, exception.getMessage()); + } + @Test + void test_Get() { + Mockito.when(icd10Repository.findAll()).thenReturn(List.of(mockICD10)); + List result = icd10Service.get(); + assertEquals(1, result.size()); + assertEquals(("K00-K14"), result.get(0).getCode()); + } + @Test + void test_GetById() { + Long id = mockICD10.getId(); + Mockito.when(icd10Repository.findById(id)).thenReturn(Optional.of(mockICD10)); + ICD10 result = icd10Service.get(id); + assertEquals(("K00-K14"), result.getCode()); + } + @Test + void test_GetByIdThrow() { + Long id = mockICD10.getId(); + Mockito.when(icd10Repository.findById(id)).thenReturn(Optional.empty()); + ExceptionApp exception = assertThrows( + ExceptionApp.class, + () -> icd10Service.get(id) + ); + assertEquals(404, exception.getCode()); + assertEquals(Message.NOT_FOUND, exception.getMessage()); + } + @Test + void test_Create() { + + Mockito.when(icd10Repository.findFirstByBlock("K")).thenReturn(mockICD10); + + + List testICD10 = ICD10Mapper.INSTANCE.convert(icd10DTOs); + + List result = icd10Service.create(testICD10); + + assertEquals(2, result.size()); + + ICD10 icd10 = result.get(0); + assertEquals("K00.19", icd10.getCode()); + assertEquals("XI", icd10.getChapter()); + assertEquals("K", icd10.getBlock()); + assertEquals(0, icd10.getCategory()); + assertEquals(1, icd10.getSubcategory()); + assertEquals(9, icd10.getItem()); + assertEquals("Сверхкомплектные зубы неуточненные", icd10.getName()); + assertTrue(icd10.isDent()); + assertNull(icd10.getDescription()); + + ICD10 icd101 = result.get(1); + assertEquals("K00.20", icd101.getCode()); + assertEquals("XI", icd101.getChapter()); + assertEquals("K", icd101.getBlock()); + assertEquals(0, icd101.getCategory()); + assertEquals(2, icd101.getSubcategory()); + assertEquals(0, icd101.getItem()); + assertEquals("Макродентия", icd101.getName()); + assertTrue(icd101.isDent()); + assertNull(icd101.getDescription()); + } + + @Test + void test_CreateThrow() { + + List testICD10 = ICD10Mapper.INSTANCE.convert(icd10DTOs_err); + + ExceptionApp exception = assertThrows( + ExceptionApp.class, + () -> icd10Service.create(testICD10) + ); + assertEquals(400, exception.getCode()); + assertEquals("Не правильный код MKБ-10: К00.2", exception.getMessage()); + + } + @Test + void test_Update() { + Mockito.when(icd10Repository.saveAll(List.of(mockICD10))).thenReturn(List.of(mockICD10)); + List result = icd10Service.update(List.of(mockICD10)); + assertEquals(1, result.size()); + assertEquals(("K00-K14"), result.get(0).getCode()); + } +} \ No newline at end of file diff --git a/src/test/java/datum/app/admin/implement/PersonServiceImplTest.java b/src/test/java/datum/app/admin/implement/PersonServiceImplTest.java index fab0459..36b4033 100644 --- a/src/test/java/datum/app/admin/implement/PersonServiceImplTest.java +++ b/src/test/java/datum/app/admin/implement/PersonServiceImplTest.java @@ -1,69 +1,69 @@ -//package datum.app.admin.implement; -// -//import datum.app.admin.model.Person; -//import datum.app.admin.repository.PersonRepository; -//import datum.app.clinic.model.Clinic; -//import datum.app.clinic.repositoy.ClinicRepository; -//import datum.config.exception.ExceptionApp; -//import datum.config.exception.Message; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.mockito.InjectMocks; -//import org.mockito.Mock; -//import org.mockito.Mockito; -//import org.mockito.junit.jupiter.MockitoExtension; -// -//import java.util.ArrayList; -//import java.util.Optional; -// -//import static org.junit.jupiter.api.Assertions.*; -//@ExtendWith(MockitoExtension.class) -//class PersonServiceImplTest { -// @Mock -// private PersonRepository personRepository; -// @Mock -// private ClinicRepository clinicRepository; -// -// @InjectMocks -// private PersonServiceImpl personService; -// Person person = Person.builder() -// .id(1L) -// .firstname("Dastan") -// -// .build(); -//Clinic clinic = Clinic.builder() -// .id(1L) -// .name("Datum") -// .persons(new ArrayList<>()) -// .build(); -// @Test -// void test_Get() { -// Mockito.when(personRepository.findById(1L)).thenReturn(Optional.of(person)); -// Person result = personService.get(1L); -// assertEquals("Dastan", result.getFirstname()); -// } -// @Test -// void test_GetThrow() { -// Mockito.when(personRepository.findById(10L)).thenReturn(Optional.empty()); -// ExceptionApp exception = assertThrows( -// ExceptionApp.class, -// () -> personService.get(10L) -// ); -// assertEquals(404, exception.getCode()); -// assertEquals(Message.NOT_FOUND, exception.getMessage()); -// } -// @Test -// void test_Create() { -// Mockito.when(personRepository.save(person)).thenReturn(person); -// Person result = personService.create(person); -// assertEquals("Dastan", result.getFirstname()); -// } -// @Test -// void test_CreateByClinic() { -// Mockito.when(clinicRepository.findById(1L)).thenReturn(Optional.ofNullable(clinic)); -// Person result = personService.createByClinic(1L, person); -// assertEquals("Dastan", result.getFirstname()); -// } -// -// -//} \ No newline at end of file +package datum.app.admin.implement; + +import datum.app.admin.model.Person; +import datum.app.admin.repository.PersonRepository; +import datum.app.clinic.model.Clinic; +import datum.app.clinic.repositoy.ClinicRepository; +import datum.config.exception.ExceptionApp; +import datum.config.exception.Message; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.ArrayList; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +@ExtendWith(MockitoExtension.class) +class PersonServiceImplTest { + @Mock + private PersonRepository personRepository; + @Mock + private ClinicRepository clinicRepository; + + @InjectMocks + private PersonServiceImpl personService; + Person person = Person.builder() + .id(1L) + .firstname("Dastan") + + .build(); +Clinic clinic = Clinic.builder() + .id(1L) + .name("Datum") + .persons(new ArrayList<>()) + .build(); + @Test + void test_Get() { + Mockito.when(personRepository.findById(1L)).thenReturn(Optional.of(person)); + Person result = personService.get(1L); + assertEquals("Dastan", result.getFirstname()); + } + @Test + void test_GetThrow() { + Mockito.when(personRepository.findById(10L)).thenReturn(Optional.empty()); + ExceptionApp exception = assertThrows( + ExceptionApp.class, + () -> personService.get(10L) + ); + assertEquals(404, exception.getCode()); + assertEquals(Message.NOT_FOUND, exception.getMessage()); + } + @Test + void test_Create() { + Mockito.when(personRepository.save(person)).thenReturn(person); + Person result = personService.create(person); + assertEquals("Dastan", result.getFirstname()); + } + @Test + void test_CreateByClinic() { + Mockito.when(clinicRepository.findById(1L)).thenReturn(Optional.ofNullable(clinic)); + Person result = personService.createByClinic(1L, person); + assertEquals("Dastan", result.getFirstname()); + } + + +} \ No newline at end of file