Skip to content

Commit

Permalink
Add integration tests for loadArticles
Browse files Browse the repository at this point in the history
RISDEV-0000
  • Loading branch information
VictorDelCampo committed Mar 2, 2024
1 parent e6c09e0 commit 707ed47
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public List<AmendingLaw> loadAllAmendingLaws() {
}

@Override
@Transactional
public List<Article> loadArticlesByAmendingLaw(LoadArticlesPort.Command command) {
final Optional<AmendingLawDto> amendingLawDtoOptional =
amendingLawRepository.findByEli(command.eli());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import de.bund.digitalservice.ris.norms.adapter.output.database.mapper.AmendingLawMapper;
import de.bund.digitalservice.ris.norms.adapter.output.database.repository.AmendingLawRepository;
import de.bund.digitalservice.ris.norms.domain.entity.AmendingLaw;
import de.bund.digitalservice.ris.norms.domain.entity.Article;
import de.bund.digitalservice.ris.norms.domain.entity.TargetLaw;
import de.bund.digitalservice.ris.norms.integration.BaseIntegrationTest;
import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -128,4 +130,60 @@ void itLoadsAllAmendingLawsAndReturnsSuccessfully() throws Exception {
.andExpect(jsonPath("$[0].eli", equalTo(amendingLaw1.getEli())))
.andExpect(jsonPath("$[1].eli", equalTo(amendingLaw2.getEli())));
}

@Test
void itCallsAmendingLawServiceAndReturnsArticles() throws Exception {
// Given
final String eli = "eli/bund/bgbl-1/1953/s225/2017-03-15/1/deu/regelungstext-1";
final String printAnnouncementGazette = "someGazette";
final LocalDate publicationDate = LocalDate.now();
final String printAnnouncementPage = "page123";
final String digitalAnnouncementMedium = "medium123";
final String digitalAnnouncementEdition = "edition123";
final String title = "title";
final String xml = "<test></test>";

final TargetLaw targetLaw =
TargetLaw.builder()
.eli("target law eli")
.title("target law title")
.xml("<target></target>")
.build();
final Article article =
Article.builder()
.eid("eid")
.title("article title")
.enumeration("1")
.targetLaw(targetLaw)
.build();

// When
final AmendingLaw amendingLaw =
AmendingLaw.builder()
.eli(eli)
.printAnnouncementGazette(printAnnouncementGazette)
.publicationDate(publicationDate)
.printAnnouncementPage(printAnnouncementPage)
.digitalAnnouncementMedium(digitalAnnouncementMedium)
.digitalAnnouncementEdition(digitalAnnouncementEdition)
.title(title)
.xml(xml)
.articles(List.of(article))
.build();
amendingLawRepository.save(AmendingLawMapper.mapToDto(amendingLaw));

final String encodedEli =
UriComponentsBuilder.fromPath(amendingLaw.getEli()).build().encode().toUriString();

// When // Then
mockMvc
.perform(get("/api/v1/amending-laws/{eli}/articles", encodedEli))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0]").exists())
.andExpect(jsonPath("$[1]").doesNotExist())
.andExpect(jsonPath("$[0].eid", equalTo(article.getEid())))
.andExpect(jsonPath("$[0].enumeration", equalTo(article.getEnumeration())))
.andExpect(jsonPath("$[0].affectedDocumentEli", equalTo(targetLaw.getEli())))
.andExpect(jsonPath("$[0].title", equalTo(article.getTitle())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.bund.digitalservice.ris.norms.adapter.output.database.repository.AmendingLawRepository;
import de.bund.digitalservice.ris.norms.adapter.output.database.service.DBService;
import de.bund.digitalservice.ris.norms.application.port.output.LoadAmendingLawPort;
import de.bund.digitalservice.ris.norms.application.port.output.LoadArticlesPort;
import de.bund.digitalservice.ris.norms.domain.entity.AmendingLaw;
import de.bund.digitalservice.ris.norms.domain.entity.Article;
import de.bund.digitalservice.ris.norms.domain.entity.TargetLaw;
Expand Down Expand Up @@ -153,4 +154,76 @@ void itLoadsAllAmendingLawsFromDB() {
.extracting(AmendingLaw::getEli)
.containsExactly(amendingLaw2.getEli(), amendingLaw1.getEli());
}

@Test
void itFindsArticleOnDB() {
// Given
final String eli = "eli/bgbl-1/2024/123/2017-03-15/1/deu/regelungstext-1";
final String printAnnouncementGazette = "someGazette";
final LocalDate publicationDate = LocalDate.now();
final String printAnnouncementPage = "page123";
final String digitalAnnouncementMedium = "medium123";
final String digitalAnnouncementEdition = "edition123";
final String title = "title";
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

// When
final AmendingLaw amendingLaw =
AmendingLaw.builder()
.eli(eli)
.printAnnouncementGazette(printAnnouncementGazette)
.publicationDate(publicationDate)
.printAnnouncementPage(printAnnouncementPage)
.digitalAnnouncementMedium(digitalAnnouncementMedium)
.digitalAnnouncementEdition(digitalAnnouncementEdition)
.title(title)
.articles(List.of(article1, article2))
.xml(xml)
.build();
amendingLawRepository.save(AmendingLawMapper.mapToDto(amendingLaw));

// When
final List<Article> articles =
dbService.loadArticlesByAmendingLaw(new LoadArticlesPort.Command(eli));

// Then
assertThat(articles).hasSize(2);
assertThat(articles)
.extracting(Article::getTitle)
.containsExactly(article1.getTitle(), article2.getTitle());
}

@Test
void itDoesNotFindArticlesOfAmendingLaw() {
// Given
final String eli = "eli/bgbl-1/2024/123/2017-03-15/1/deu/regelungstext-1";
final String printAnnouncementGazette = "someGazette";
final LocalDate publicationDate = LocalDate.now();
final String printAnnouncementPage = "page123";
final String digitalAnnouncementMedium = "medium123";
final String digitalAnnouncementEdition = "edition123";
final String title = "title";
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

// When
final AmendingLaw amendingLaw =
AmendingLaw.builder()
.eli(eli)
.printAnnouncementGazette(printAnnouncementGazette)
.publicationDate(publicationDate)
.printAnnouncementPage(printAnnouncementPage)
.digitalAnnouncementMedium(digitalAnnouncementMedium)
.digitalAnnouncementEdition(digitalAnnouncementEdition)
.title(title)
.xml(xml)
.build();
amendingLawRepository.save(AmendingLawMapper.mapToDto(amendingLaw));

// When
final List<Article> articles =
dbService.loadArticlesByAmendingLaw(new LoadArticlesPort.Command(eli));

// Then
assertThat(articles).isEmpty();
}
}

0 comments on commit 707ed47

Please sign in to comment.