diff --git a/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java b/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java index 73d4f2f..8e40cc2 100644 --- a/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java +++ b/src/main/java/fr/abes/sudoc/component/BaseXmlFunctionsCaller.java @@ -3,11 +3,13 @@ import fr.abes.sudoc.utils.ExecutionTime; import lombok.extern.slf4j.Slf4j; import org.hibernate.annotations.ColumnTransformer; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; import java.sql.SQLRecoverableException; +import java.util.List; @Slf4j @Component @@ -19,25 +21,22 @@ public BaseXmlFunctionsCaller(JdbcTemplate baseXmlJdbcTemplate) { } @ExecutionTime - @ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)") - public String issnToPpn(String issn) throws SQLRecoverableException, UncategorizedSQLException { - StringBuilder request = new StringBuilder("SELECT AUTORITES.ISSN2PPNJSON('"); + public List issnToPpn(String issn) throws UncategorizedSQLException { + StringBuilder request = new StringBuilder("SELECT distinct ppn from AUTORITES.biblio_table_fouretout where cle1='ISSN' and cle2='"); request.append(issn); - request.append("') as data_xml from DUAL"); - return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class); + request.append("'"); + return baseXmlJdbcTemplate.queryForList(request.toString(), String.class); } @ExecutionTime - @ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)") - public String isbnToPpn(String isbn) throws SQLRecoverableException, UncategorizedSQLException { - StringBuilder request = new StringBuilder("SELECT AUTORITES.ISBN2PPNJSON('"); - request.append(isbn); - request.append("') as data_xml from DUAL"); - return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class); + public List isbnToPpn(String isbn) throws UncategorizedSQLException { + StringBuilder request = new StringBuilder("SELECT distinct ppn from AUTORITES.biblio_table_fouretout where cle1='ISBN' and cle2='"); + request.append(isbn); + request.append("'"); + return baseXmlJdbcTemplate.queryForList(request.toString(), String.class); } @ExecutionTime - @ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)") public String baconProvider035(Integer provider) throws SQLRecoverableException, UncategorizedSQLException { StringBuilder request = new StringBuilder("SELECT AUTORITES.BACON_PROVIDER_035_JSON("); request.append(provider); @@ -46,11 +45,14 @@ public String baconProvider035(Integer provider) throws SQLRecoverableException, } @ExecutionTime - @ColumnTransformer(read = "XMLSERIALIZE (CONTENT data_xml as CLOB)", write = "NULLSAFE_XMLTYPE(?)") - public String doiToPpn(String doi) throws SQLRecoverableException, UncategorizedSQLException { - StringBuilder request = new StringBuilder("select XMLTRANSFORM(XMLROOT(XMLElement(\"sudoc\",AUTORITES.DOI2PNN('"); - request.append(doi); - request.append("')),version '1.0\" encoding=\"UTF-8'),lexsl) from xsl_html where idxsl='JSON'"); + public String doiToPpn(String doi) throws UncategorizedSQLException, EmptyResultDataAccessException { + StringBuilder request = new StringBuilder("select a.ppn from autorites.biblio_table_FRBR_0xx a where "); + request.append("upper(SUBSTR(a.datas,1,50)) = '"); + request.append(doi.toUpperCase()); + request.append("' and a.tag='017$a' "); + request.append("and a.id in (select /*+ no_index(b BIBLIO_TABLE_FRBR_0XX_IDX_DATA) */ id from autorites.biblio_table_FRBR_0xx b where "); + request.append("a.id=b.id and "); + request.append("b.tag='017$2' and SUBSTR(b.datas,1,50)='DOI' and a.POSFIELD=b.POSFIELD and b.POSSUBFIELD='2')"); return baseXmlJdbcTemplate.queryForObject(request.toString(), String.class); } } diff --git a/src/main/java/fr/abes/sudoc/configuration/BaseXMLOracleConfig.java b/src/main/java/fr/abes/sudoc/configuration/BaseXMLOracleConfig.java index bc5b599..5be1eb6 100644 --- a/src/main/java/fr/abes/sudoc/configuration/BaseXMLOracleConfig.java +++ b/src/main/java/fr/abes/sudoc/configuration/BaseXMLOracleConfig.java @@ -19,69 +19,8 @@ @Configuration @EnableCaching -@EnableJpaRepositories(transactionManagerRef = "baseXmlTransactionManager", - entityManagerFactoryRef = "baseXmlEntityManager", - basePackages = "fr.abes.sudoc.repository") +@EnableJpaRepositories( + basePackages = {"fr.abes.sudoc.repository", "fr.abes.sudoc.entity"}) public class BaseXMLOracleConfig { - @Value("${spring.jpa.basexml.database-platform}") - protected String platform; - @Value("${spring.jpa.basexml.hibernate.ddl-auto}") - protected String ddlAuto; - @Value("${spring.jpa.basexml.generate-ddl}") - protected boolean generateDdl; - @Value("${spring.jpa.basexml.properties.hibernate.dialect}") - protected String dialect; - @Value("${spring.jpa.basexml.show-sql}") - private boolean showsql; - @Value("${spring.sql.basexml.init.mode}") - private String initMode; - - @Bean - @ConfigurationProperties(prefix = "spring.datasource.basexml") - public DataSource baseXmlDataSource() { - return DataSourceBuilder.create().build(); - } - - @Bean - public LocalContainerEntityManagerFactoryBean baseXmlEntityManager() { - LocalContainerEntityManagerFactoryBean em - = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(baseXmlDataSource()); - em.setPackagesToScan( - new String[] { "fr.abes.sudoc.entity" }); - configHibernate(em, platform, showsql, dialect, ddlAuto, generateDdl, initMode); - return em; - } - - private void configHibernate(LocalContainerEntityManagerFactoryBean em, String platform, boolean showsql, String dialect, String ddlAuto, boolean generateDdl, String initMode) { - HibernateJpaVendorAdapter vendorAdapter - = new HibernateJpaVendorAdapter(); - vendorAdapter.setGenerateDdl(generateDdl); - vendorAdapter.setShowSql(showsql); - vendorAdapter.setDatabasePlatform(platform); - em.setJpaVendorAdapter(vendorAdapter); - HashMap properties = new HashMap<>(); - properties.put("hibernate.format_sql", true); - properties.put("hibernate.hbm2ddl.auto", ddlAuto); - properties.put("hibernate.dialect", dialect); - properties.put("logging.level.org.hibernate", "DEBUG"); - properties.put("hibernate.type", "trace"); - properties.put("spring.sql.init.mode", initMode); - em.setJpaPropertyMap(properties); - } - - @Bean - public PlatformTransactionManager baseXmlTransactionManager() { - JpaTransactionManager transactionManager - = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory( - baseXmlEntityManager().getObject()); - return transactionManager; - } - - @Bean - public JdbcTemplate baseXmlJdbcTemplate() { - return new JdbcTemplate(baseXmlDataSource()); - } } diff --git a/src/main/java/fr/abes/sudoc/controller/SudocController.java b/src/main/java/fr/abes/sudoc/controller/SudocController.java index 32694e8..fdbcd52 100644 --- a/src/main/java/fr/abes/sudoc/controller/SudocController.java +++ b/src/main/java/fr/abes/sudoc/controller/SudocController.java @@ -40,7 +40,7 @@ public class SudocController { @ExecutionTime @GetMapping(value = {"/online_identifier_2_ppn/{type}/{onlineIdentifier}", "/online_identifier_2_ppn/{type}/{onlineIdentifier}/{provider}"}, produces = MediaType.APPLICATION_JSON_VALUE) - public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable String onlineIdentifier, @PathVariable(required = false) Optional provider) throws IOException, ZoneNotFoundException { + public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable String onlineIdentifier, @PathVariable(required = false) Optional provider) throws IOException, ZoneNotFoundException, IllegalPpnException { log.debug("-----------------------------------------------------------"); log.debug("ONLINE IDENTIFIER 2 PPN"); ResultWsDto resultat = new ResultWsDto(); @@ -64,16 +64,13 @@ public ResultWsDto onlineIdentifier2Ppn(@PathVariable String type, @PathVariable } catch (IOException ex) { log.error("erreur dans la récupération de la notice correspondant à l'identifiant " + onlineIdentifier); throw new IOException(ex); - } catch (IllegalPpnException ex) { - log.warn("Impossible de retrouver une notice correspondant à l'identifiant " + onlineIdentifier); -// throw new IOException(ex); // Pas besoin de throw, il y a juste pas de ppn assosier à cet onlineId } return resultat; } @ExecutionTime @GetMapping(value = {"/print_identifier_2_ppn/{type}/{printIdentifier}","/print_identifier_2_ppn/{type}/{printIdentifier}/{provider}"}, produces = MediaType.APPLICATION_JSON_VALUE) - public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable String printIdentifier, @PathVariable Optional provider) throws IOException, ZoneNotFoundException { + public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable String printIdentifier, @PathVariable Optional provider) throws IOException, ZoneNotFoundException, IllegalPpnException { log.debug("-----------------------------------------------------------"); log.debug("PRINT IDENTIFIER 2 PPN"); ResultWsDto resultat = new ResultWsDto(); @@ -127,16 +124,12 @@ public ResultWsDto printIdentifier2Ppn(@PathVariable String type, @PathVariable } catch (IOException ex) { log.error("erreur dans la récupération de la notice correspondant à l'identifiant " + printIdentifier); throw new IOException(ex); - } catch (IllegalPpnException ex){ - log.warn("Impossible de retrouver une notice correspondant à l'identifiant " + printIdentifier); } - return resultat; } @ExecutionTime @GetMapping(value = {"/doi_identifier_2_ppn"}, produces = MediaType.APPLICATION_JSON_VALUE) - public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_identifier, @RequestParam(name = "provider") Optional provider) throws IOException { - log.debug("-----------------------------------------------------------"); + public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_identifier, @RequestParam(name = "provider") Optional provider) throws IOException, IllegalPpnException { log.debug("DOI IDENTIFIER 2 PPN"); ResultWsDto resultat = new ResultWsDto(); Optional providerDto = this.providerService.getProviderDisplayName(provider); @@ -154,8 +147,6 @@ public ResultWsDto doiIdentifier2Ppn(@RequestParam(name = "doi") String doi_iden } catch (IOException ex) { log.error("Erreur dans la récupération de la notice correspondant à l'identifiant"); throw new IOException(ex); - } catch (IllegalPpnException e) { - throw new IOException("Aucun identifiant ne correspond à la notice"); } catch (ZoneNotFoundException e) { throw new IOException(e.getMessage()); } diff --git a/src/main/java/fr/abes/sudoc/exception/ExceptionControllerHandler.java b/src/main/java/fr/abes/sudoc/exception/ExceptionControllerHandler.java index b86dff0..aca0f88 100644 --- a/src/main/java/fr/abes/sudoc/exception/ExceptionControllerHandler.java +++ b/src/main/java/fr/abes/sudoc/exception/ExceptionControllerHandler.java @@ -63,6 +63,12 @@ protected ResponseEntity handleZoneNotFoundException(ZoneNotFoundExcepti return buildResponseEntity(new ApiReturnError(HttpStatus.BAD_REQUEST, error, ex)); } + @ExceptionHandler(IllegalPpnException.class) + protected ResponseEntity handleIllegalPpnException(IllegalPpnException ex) { + String warn = ex.getMessage(); + log.warn(warn); + return buildResponseEntity(new ApiReturnError(HttpStatus.NO_CONTENT, warn, ex)); + } @ExceptionHandler(IOException.class) protected ResponseEntity handleIOException(IOException ex) { diff --git a/src/main/java/fr/abes/sudoc/exception/IllegalPpnException.java b/src/main/java/fr/abes/sudoc/exception/IllegalPpnException.java index 5faee3d..6015e08 100644 --- a/src/main/java/fr/abes/sudoc/exception/IllegalPpnException.java +++ b/src/main/java/fr/abes/sudoc/exception/IllegalPpnException.java @@ -1,6 +1,6 @@ package fr.abes.sudoc.exception; -public class IllegalPpnException extends Throwable { +public class IllegalPpnException extends Exception { public IllegalPpnException(String s) { super(s); } diff --git a/src/main/java/fr/abes/sudoc/service/DoiService.java b/src/main/java/fr/abes/sudoc/service/DoiService.java index 7fc5d47..e16c342 100644 --- a/src/main/java/fr/abes/sudoc/service/DoiService.java +++ b/src/main/java/fr/abes/sudoc/service/DoiService.java @@ -4,11 +4,15 @@ import fr.abes.sudoc.component.BaseXmlFunctionsCaller; import fr.abes.sudoc.exception.IllegalPpnException; import fr.abes.sudoc.utils.Utilitaire; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.stereotype.Service; import java.io.IOException; import java.sql.SQLRecoverableException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; @Service @@ -25,15 +29,15 @@ public boolean checkFormat(String doi) { return doi != null && doi.matches(doiPattern); } - public List getPpnFromIdentifiant(String doi) throws IllegalPpnException, IOException { - try{ - return Utilitaire.parseJsonDoi(caller.doiToPpn(doi)); - } catch (UncategorizedSQLException ex){ - throw new IllegalPpnException("Aucune notice ne correspond à la recherche"); - } catch (JsonProcessingException ex) { - throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant"); - } catch (SQLRecoverableException ex) { + @Override + public List getPpnFromIdentifiant(String doi) throws IOException, IllegalPpnException { + try { + + return Collections.singletonList(caller.doiToPpn(doi)); + } catch (UncategorizedSQLException ex) { throw new IOException("Incident technique lors de l'accès à la base de données"); + } catch (EmptyResultDataAccessException ex) { + throw new IllegalPpnException("Aucune notice ne correspond à la recherche"); } } diff --git a/src/main/java/fr/abes/sudoc/service/IsbnService.java b/src/main/java/fr/abes/sudoc/service/IsbnService.java index ba9b182..4092857 100644 --- a/src/main/java/fr/abes/sudoc/service/IsbnService.java +++ b/src/main/java/fr/abes/sudoc/service/IsbnService.java @@ -25,14 +25,10 @@ public boolean checkFormat(String isbn) { } @Override - public List getPpnFromIdentifiant(String isbn) throws IllegalPpnException, IOException { + public List getPpnFromIdentifiant(String isbn) throws IOException { try{ - return Utilitaire.parseJson(caller.isbnToPpn(isbn)); - } catch (UncategorizedSQLException ex){ - throw new IllegalPpnException("Aucune notice ne correspond à la recherche"); - } catch (JsonProcessingException ex) { - throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant"); - } catch (SQLRecoverableException ex) { + return caller.isbnToPpn(isbn.replace("-", "")); + } catch (UncategorizedSQLException ex) { throw new IOException("Incident technique lors de l'accès à la base de données"); } } diff --git a/src/main/java/fr/abes/sudoc/service/IssnService.java b/src/main/java/fr/abes/sudoc/service/IssnService.java index d8472d6..6449e08 100644 --- a/src/main/java/fr/abes/sudoc/service/IssnService.java +++ b/src/main/java/fr/abes/sudoc/service/IssnService.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.sql.SQLRecoverableException; +import java.util.Collections; import java.util.List; @Service @@ -25,14 +26,10 @@ public boolean checkFormat(String issn) { } @Override - public List getPpnFromIdentifiant(String issn) throws IllegalPpnException, IOException { + public List getPpnFromIdentifiant(String issn) throws IOException { try{ - return Utilitaire.parseJson(caller.issnToPpn(issn)); - } catch (UncategorizedSQLException ex){ - throw new IllegalPpnException("Aucune notice ne correspond à la recherche"); - } catch (JsonProcessingException ex) { - throw new IOException("Impossible de récupérer les ppns correspondant à cet identifiant"); - } catch (SQLRecoverableException ex) { + return caller.issnToPpn(issn.replace("-", "")); + } catch (UncategorizedSQLException ex) { throw new IOException("Incident technique lors de l'accès à la base de données"); } } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 4be6f3a..4d0f464 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -1,14 +1,18 @@ -spring.datasource.basexml.jdbcurl= -spring.datasource.basexml.username= -spring.datasource.basexml.password= -spring.datasource.basexml.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.url= +spring.datasource.username= +spring.datasource.password= +spring.datasource.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.hikari.maximum-pool-size=100 +spring.datasource.hikari.minimum-idle=10 +spring.datasource.hikari.connection-timeout=30000 +spring.datasource.hikari.idle-timeout=60000 -spring.jpa.basexml.generate-ddl=false -spring.jpa.basexml.show-sql=false -spring.jpa.basexml.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect -spring.jpa.basexml.hibernate.ddl-auto=none -spring.jpa.basexml.database-platform=org.hibernate.dialect.OracleDialect -spring.sql.basexml.init.mode=never +spring.jpa.generate-ddl=false +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect +spring.jpa.hibernate.ddl-auto=none +spring.jpa.database-platform=org.hibernate.dialect.OracleDialect +spring.sql.init.mode=never # Access CBS sudoc.serveur= diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 91425dc..47dbc0d 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,14 +1,18 @@ -spring.datasource.basexml.jdbcurl= -spring.datasource.basexml.username= -spring.datasource.basexml.password= -spring.datasource.basexml.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.url= +spring.datasource.username= +spring.datasource.password= +spring.datasource.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.hikari.maximum-pool-size=100 +spring.datasource.hikari.minimum-idle=10 +spring.datasource.hikari.connection-timeout=30000 +spring.datasource.hikari.idle-timeout=60000 -spring.jpa.basexml.generate-ddl=false -spring.jpa.basexml.show-sql=false -spring.jpa.basexml.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect -spring.jpa.basexml.hibernate.ddl-auto=none -spring.jpa.basexml.database-platform=org.hibernate.dialect.OracleDialect -spring.sql.basexml.init.mode=never +spring.jpa.generate-ddl=false +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect +spring.jpa.hibernate.ddl-auto=none +spring.jpa.database-platform=org.hibernate.dialect.OracleDialect +spring.sql.init.mode=never # Access CBS sudoc.serveur= diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index aa5a82a..678cfd1 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1,14 +1,18 @@ -spring.datasource.basexml.jdbcurl= -spring.datasource.basexml.username= -spring.datasource.basexml.password= -spring.datasource.basexml.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.url= +spring.datasource.username= +spring.datasource.password= +spring.datasource.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.hikari.maximum-pool-size=100 +spring.datasource.hikari.minimum-idle=10 +spring.datasource.hikari.connection-timeout=30000 +spring.datasource.hikari.idle-timeout=60000 -spring.jpa.basexml.generate-ddl=false -spring.jpa.basexml.show-sql=false -spring.jpa.basexml.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect -spring.jpa.basexml.hibernate.ddl-auto=none -spring.jpa.basexml.database-platform=org.hibernate.dialect.OracleDialect -spring.sql.basexml.init.mode=never +spring.jpa.generate-ddl=false +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect +spring.jpa.hibernate.ddl-auto=none +spring.jpa.database-platform=org.hibernate.dialect.OracleDialect +spring.sql.init.mode=never # Access CBS sudoc.serveur= diff --git a/src/test/java/fr/abes/sudoc/controller/SudocControllerTest.java b/src/test/java/fr/abes/sudoc/controller/SudocControllerTest.java index 9ead125..008f3cc 100644 --- a/src/test/java/fr/abes/sudoc/controller/SudocControllerTest.java +++ b/src/test/java/fr/abes/sudoc/controller/SudocControllerTest.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; @@ -106,7 +105,7 @@ void datToPpnTitreIsNull() throws Exception { @Test @DisplayName("datToPpn tryCatchWorks") - void datToPpnTryCatchWorks() throws Exception, IllegalPpnException { + void datToPpnTryCatchWorks() throws Exception { SearchDatWebDto searchDatRequest = new SearchDatWebDto(); searchDatRequest.setDate(2008); @@ -169,7 +168,7 @@ void datToPpnTryCatchNotWorks() throws Exception { @Test @DisplayName("test WS online_identifier_2_ppn : serial + ISSN ok + 1 PPN non supprimé de doc élec") - void onlineIdentifier2PpnCas1() throws Exception, IllegalPpnException { + void onlineIdentifier2PpnCas1() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; @@ -197,7 +196,7 @@ void onlineIdentifier2PpnCas1() throws Exception, IllegalPpnException { @Test @DisplayName("test WS online_identifier_2_ppn : serial + ISSN ok + 2 PPN non supprimés dont un ppn qui n'est pas une notice electronique") - void onlineIdentifier2PpnCas2() throws Exception, IllegalPpnException { + void onlineIdentifier2PpnCas2() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; @@ -239,7 +238,7 @@ void onlineIdentifier2PpnCas2() throws Exception, IllegalPpnException { @Test @DisplayName("test WS online_identifier_2_ppn : serial + ISSN ok + exception erreur SQL") - void onlineIdentifier2PpnCas3() throws Exception, IllegalPpnException { + void onlineIdentifier2PpnCas3() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; @@ -259,7 +258,7 @@ void onlineIdentifier2PpnCas3() throws Exception, IllegalPpnException { Mockito.doThrow(IOException.class).when(noticeService).getNoticeByPpn(Mockito.any()); this.mockMvc.perform(get("/api/v1/online_identifier_2_ppn/" + type + "/" + onlineIdentifier)) - .andExpect(status().isNoContent()) + .andExpect(status().isBadRequest()) .andExpect(result -> Assertions.assertTrue((result.getResolvedException() instanceof IOException))); } @@ -278,7 +277,7 @@ void onlineIdentifier2PpnCas4() throws Exception { @Test @DisplayName("test WS online_identifier_2_ppn : check provider non ok") - void onlineIdentifierCheckProviderNonOk() throws Exception, IllegalPpnException { + void onlineIdentifierCheckProviderNonOk() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; String provider = "CAIRN"; @@ -309,7 +308,7 @@ void onlineIdentifierCheckProviderNonOk() throws Exception, IllegalPpnException @Test @DisplayName("test WS online_identifier_2_ppn : check provider diacritics") - void onlineIdentifierCheckProviderDiacritics() throws Exception, IllegalPpnException { + void onlineIdentifierCheckProviderDiacritics() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; String provider = "CAèRN"; @@ -347,7 +346,7 @@ void onlineIdentifierCheckProviderDiacritics() throws Exception, IllegalPpnExcep @Test @DisplayName("test WS online_identifier_2_ppn : erreur appel ws provider") - void onlineIdentifer2PpnErreurAppelWs() throws Exception, IllegalPpnException { + void onlineIdentifer2PpnErreurAppelWs() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; String provider = "CAIRN"; @@ -386,7 +385,7 @@ void onlineIdentifer2PpnErreurAppelWs() throws Exception, IllegalPpnException { @Test @DisplayName("test WS print_identifier_2_ppn : serial + ISSN ok + 1 PPN non supprimé de doc imprimé") - void printIdentifier2PpnCas1() throws Exception, IllegalPpnException { + void printIdentifier2PpnCas1() throws Exception { String type = "serial"; String printIdentifier = "1234-1234"; @@ -427,7 +426,7 @@ void printIdentifier2PpnCas0Ppn() throws Exception, IllegalPpnException { } @Test @DisplayName("test WS print_identifier_2_ppn : serial + ISSN ok + 1 PPN supprimé de doc imprimé") - void printIdentifier2PpnCas1Supprime() throws Exception, IllegalPpnException { + void printIdentifier2PpnCas1Supprime() throws Exception { String type = "serial"; String printIdentifier = "1234-1234"; @@ -453,7 +452,7 @@ void printIdentifier2PpnCas1Supprime() throws Exception, IllegalPpnException { @Test @DisplayName("test WS print_identifier_2_ppn : serial + ISSN ok + 2 PPN non supprimés dont un ppn qui n'est pas une notice imprimée") - void printIdentifier2PpnCas2() throws Exception, IllegalPpnException { + void printIdentifier2PpnCas2() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; @@ -498,7 +497,7 @@ void printIdentifier2PpnCas2() throws Exception, IllegalPpnException { @Test @DisplayName("test WS print_identifier_2_ppn : serial + ISSN ok + exception erreur SQL") - void printIdentifier2PpnCas3() throws Exception, IllegalPpnException { + void printIdentifier2PpnCas3() throws Exception { String type = "serial"; String onlineIdentifier = "1234-1234"; @@ -518,7 +517,7 @@ void printIdentifier2PpnCas3() throws Exception, IllegalPpnException { Mockito.doThrow(IOException.class).when(noticeService).getNoticeByPpn(Mockito.any()); this.mockMvc.perform(get("/api/v1/print_identifier_2_ppn/" + type + "/" + onlineIdentifier)) - .andExpect(status().isNoContent()) + .andExpect(status().isBadRequest()) .andExpect(result -> Assertions.assertTrue((result.getResolvedException() instanceof IOException))); } @@ -548,7 +547,7 @@ void printIdentifier2PpnCas5() throws Exception { @Test @DisplayName("test WS print_identifer_2_ppn : erreur récupération provider") - void printIdentifer2PpnErreurAppelWs() throws Exception, IllegalPpnException { + void printIdentifer2PpnErreurAppelWs() throws Exception { String provider = "CAIRN"; String type = "serial"; String printIdentifier = "1234-1234"; @@ -592,7 +591,7 @@ void printIdentifer2PpnErreurAppelWs() throws Exception, IllegalPpnException { } @Test - void doiIdentifier2ppnCasOk() throws Exception, IllegalPpnException { + void doiIdentifier2ppnCasOk() throws Exception { String doi = "10.1006/jmbi.1998.2354"; String provider = "CAIRN"; @@ -641,7 +640,7 @@ void doiIdentifier2ppnErreurFormat() throws Exception { } @Test - void doiIdentifier2ppnNoPpnFound() throws Exception, IllegalPpnException { + void doiIdentifier2ppnNoPpnFound() throws Exception { String doi = "10.1006/jmbi.1998.2354"; String provider = "CAIRN"; @@ -654,12 +653,12 @@ void doiIdentifier2ppnNoPpnFound() throws Exception, IllegalPpnException { this.mockMvc.perform(get("/api/v1/doi_identifier_2_ppn/?doi=" + doi + "&provider=" + provider)) .andExpect(status().isNoContent()) - .andExpect(result -> Assertions.assertTrue((result.getResolvedException() instanceof IOException))) - .andExpect(result -> Assertions.assertEquals("Aucun identifiant ne correspond à la notice", Objects.requireNonNull(result.getResolvedException()).getMessage())); + .andExpect(result -> Assertions.assertTrue((result.getResolvedException() instanceof IllegalPpnException))) + .andExpect(result -> Assertions.assertEquals("Aucune notice ne correspond à la recherche", Objects.requireNonNull(result.getResolvedException()).getMessage())); } @Test - void doiIdentifier2ppnErreurProvider() throws Exception, IllegalPpnException { + void doiIdentifier2ppnErreurProvider() throws Exception { String doi = "10.1006/jmbi.1998.2354"; String provider = "CAIRN"; @@ -692,7 +691,7 @@ void doiIdentifier2ppnErreurProvider() throws Exception, IllegalPpnException { } @Test - void doiIdentifier2ppnErreurTypeSupportNotice() throws Exception, IllegalPpnException { + void doiIdentifier2ppnErreurTypeSupportNotice() throws Exception { String doi = "10.1006/jmbi.1998.2354"; String provider = "CAIRN"; diff --git a/src/test/java/fr/abes/sudoc/service/IsbnServiceTest.java b/src/test/java/fr/abes/sudoc/service/IsbnServiceTest.java index 40f8b6a..425aa6e 100644 --- a/src/test/java/fr/abes/sudoc/service/IsbnServiceTest.java +++ b/src/test/java/fr/abes/sudoc/service/IsbnServiceTest.java @@ -13,6 +13,7 @@ import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.io.IOException; import java.sql.SQLRecoverableException; @ExtendWith(SpringExtension.class) @@ -99,9 +100,9 @@ void checkFormatIsbn13Characters() { @Test @DisplayName("getPpnFromIdentifiant with UncategorizedSQLException") - void testgetPpnUncategorizedException() throws SQLRecoverableException { + void testgetPpnUncategorizedException() { Mockito.doThrow(UncategorizedSQLException.class).when(caller).isbnToPpn(Mockito.anyString()); - Assertions.assertThrows(IllegalPpnException.class, () -> isbnService.getPpnFromIdentifiant("1111111111")); + Assertions.assertThrows(IOException.class, () -> isbnService.getPpnFromIdentifiant("1111111111")); } } diff --git a/src/test/java/fr/abes/sudoc/service/IssnServiceTest.java b/src/test/java/fr/abes/sudoc/service/IssnServiceTest.java index 73416af..08628e8 100644 --- a/src/test/java/fr/abes/sudoc/service/IssnServiceTest.java +++ b/src/test/java/fr/abes/sudoc/service/IssnServiceTest.java @@ -14,6 +14,7 @@ import org.springframework.jdbc.UncategorizedSQLException; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.io.IOException; import java.sql.SQLRecoverableException; @ExtendWith(SpringExtension.class) @@ -94,8 +95,8 @@ void checkFormatIssn9Characters() { @Test @DisplayName("getPpnFromIdentifiant with UncategorizedSQLException") - void testgetPpnUncategorizedException() throws SQLRecoverableException { + void testgetPpnUncategorizedException() { Mockito.doThrow(UncategorizedSQLException.class).when(caller).issnToPpn(Mockito.anyString()); - Assertions.assertThrows(IllegalPpnException.class, () -> issnService.getPpnFromIdentifiant("11111111")); + Assertions.assertThrows(IOException.class, () -> issnService.getPpnFromIdentifiant("11111111")); } }