Skip to content

Commit

Permalink
fix: solve test
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Jun 28, 2024
1 parent 0dcc123 commit a8c8816
Showing 1 changed file with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.insee.rmes.bauhaus_services.Constants;
import fr.insee.rmes.bauhaus_services.OrganizationsService;
import fr.insee.rmes.bauhaus_services.operations.ParentUtils;
import fr.insee.rmes.bauhaus_services.operations.documentations.documents.DocumentsUtils;
import fr.insee.rmes.exceptions.RmesBadRequestException;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.model.operations.documentations.Documentation;
Expand All @@ -14,6 +15,9 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
Expand All @@ -26,46 +30,27 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
@SpringBootTest(properties = { "fr.insee.rmes.bauhaus.filenames.maxlength=50"})
class DocumentationExportTest {
@Mock
@MockBean
private ExportUtils exportUtils;

@Mock
@MockBean
private ParentUtils parentUtils;

@Mock
@MockBean
private DocumentationsUtils documentationsUtils;

@Mock
@MockBean
private OrganizationsService organizationsService;

@InjectMocks
@Autowired
private DocumentationExport documentationExport;

@MockBean
private DocumentsUtils documentsUtils;
@Test
public void testExportMetadataReport_Success_WithDocuments_RMES() throws RmesException {
String id = "1234";
boolean includeEmptyMas = true;
boolean lg1 = true;
boolean lg2 = false;
boolean document = true;
String goal = Constants.GOAL_RMES;
String targetType = "someTargetType";

Resource resource = new ByteArrayResource("Mocked Document Content".getBytes());

when(parentUtils.getDocumentationTargetTypeAndId(id)).thenReturn(new String[]{targetType, "someId"});
when(documentationsUtils.getDocumentationByIdSims(id)).thenReturn(new JSONObject());
when(documentationsUtils.getFullSimsForXml(id)).thenReturn(new Documentation());
when(exportUtils.exportAsZip(any(), any(), any(), any(), any(), any())).thenReturn(ResponseEntity.ok().body(resource));

ResponseEntity<Resource> response = documentationExport.exportMetadataReport(id, includeEmptyMas, lg1, lg2, document, goal);
assertEquals(ResponseEntity.ok().body(resource), response);
}

@Test
public void testExportMetadataReport_Success_WithoutDocuments_Label() throws RmesException {
public void testExportMetadataReport_Success_WithoutDocuments_Label() throws RmesException {
String id = "1234";
boolean includeEmptyMas = true;
boolean lg1 = true;
Expand Down

0 comments on commit a8c8816

Please sign in to comment.