Skip to content

Commit

Permalink
Add test when not generating PDF. And fix test when generating PDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr72 committed Nov 3, 2023
1 parent f38d941 commit c15e7ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.charset.StandardCharsets;
import java.util.UUID;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -100,7 +101,7 @@ private void loadFile(Element sampleMetadataXml) throws Exception {
}

@Test
public void nominal() throws Exception {
public void whenGeneratingPdfWithPropertySetTriggersValidContent() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
MockHttpSession mockHttpSession = loginAsAdmin();
settingManager.setValue("metadata/pdfReport/headerLogoFileName", "pdf_test_banner_to_use.png");
Expand All @@ -116,4 +117,22 @@ public void nominal() throws Exception {
Mockito.verify(responseWriterSpy).writeOutResponse(any(ServiceContext.class), any(String.class), any(String.class), any(HttpServletResponse.class), any(FormatType.class), captor.capture());
assertTrue(new String(captor.getValue(), StandardCharsets.UTF_8).contains("pdf_test_banner_to_use.png"));
}

@Test
public void whenNotGeneratingPdfWithPropertySetTriggersValidContent() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
MockHttpSession mockHttpSession = loginAsAdmin();
settingManager.setValue("metadata/pdfReport/headerLogoFileName", "pdf_test_banner_to_use.png");

String url = "/srv/api/records/" + metadata.getUuid() + "/formatters/xsl-view?language=fre";
mockMvc.perform(get(url)
.session(mockHttpSession)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andReturn();

ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
Mockito.verify(responseWriterSpy).writeOutResponse(any(ServiceContext.class), any(String.class), any(String.class), any(HttpServletResponse.class), any(FormatType.class), captor.capture());
assertFalse(new String(captor.getValue(), StandardCharsets.UTF_8).contains("pdf_test_banner_to_use.png"));
}
}
2 changes: 1 addition & 1 deletion web/src/main/webapp/xslt/skin/default/skin.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
@@@@@@@@@@@@@@<xsl:value-of select="$output"></xsl:value-of>@@@@@@@@@@@@@
<img class="gn-logo"
alt="{$i18n/siteLogo}"
src="{/root/gui/nodeUrl}../images/logos/{$env//system/site/siteId}.png"/>
src="{/root/gui/nodeUrl}../images/logos/pdf_test_banner_to_use.png"/>
</xsl:if>
<xsl:if test="$isShowGNName">
<xsl:value-of select="$env//system/site/name"/>
Expand Down

0 comments on commit c15e7ea

Please sign in to comment.