Skip to content

Commit

Permalink
fix: solve unit test for IndicatorUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Feb 10, 2024
1 parent ba4a513 commit 826dbfe
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 89 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
package fr.insee.rmes.bauhaus_services.operations.indicators;

import fr.insee.rmes.bauhaus_services.operations.famopeserind_utils.FamOpeSerIndUtils;
import fr.insee.rmes.bauhaus_services.rdf_utils.RepositoryGestion;
import fr.insee.rmes.exceptions.RmesException;
import fr.insee.rmes.model.links.OperationsLink;
import fr.insee.rmes.model.operations.Family;
import fr.insee.rmes.model.operations.Indicator;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
import org.json.JSONObject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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 java.util.ArrayList;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@SpringBootTest
@ExtendWith(MockitoExtension.class)
class IndicatorsUtilsTest {
@Mock
private RepositoryGestion repositoryGestion;

@Autowired
private FamOpeSerIndUtils famOpeSerIndUtils;

@Test
void shouldAddAbstractPropertyWithNewSyntaxIfFeatureFlagTrue() throws RmesException {
doNothing().when(repositoryGestion).deleteObject(any(), any());
IndicatorsUtils indicatorsUtils = new IndicatorsUtils(true, repositoryGestion, null, null, null, null, null, null, null, null, "fr", "en");
IndicatorsUtils indicatorsUtils = new IndicatorsUtils(true, repositoryGestion, null, null, null, famOpeSerIndUtils, null, null, null, null, "fr", "en");

var family = new Family();
family.setId("1");
Expand All @@ -46,7 +60,7 @@ void shouldAddAbstractPropertyWithNewSyntaxIfFeatureFlagTrue() throws RmesExcept

@Test
void shouldAddAbstractPropertyWithOldSyntaxIfFeatureFlagFalse() throws RmesException {
IndicatorsUtils indicatorsUtils = new IndicatorsUtils(false, repositoryGestion, null, null, null, null, null, null, null, null, "fr", "en");
IndicatorsUtils indicatorsUtils = new IndicatorsUtils(false, repositoryGestion, null, null, null, famOpeSerIndUtils, null, null, null, null, "fr", "en");

var family = new Family();
family.setId("1");
Expand All @@ -68,4 +82,45 @@ void shouldAddAbstractPropertyWithOldSyntaxIfFeatureFlagFalse() throws RmesExcep
Assertions.assertEquals(model.objects().toArray()[1].toString(), "\"<p>en</p>\"@en");
}

@Test
void givenBuildIndicatorFromJson_whenCorrectRequest_thenResponseIsOk() throws RmesException {
String json = "{\"idSims\":\"1779\",\"wasGeneratedBy\":[{\"labelLg2\":\"Other indexes\",\"labelLg1\":\"Autres indicateurs\",\"id\":\"s1034\"}],\"abstractLg1\":\"Le nombre d'immatriculations de voitures particulières neuves permet de suivre l'évolution du marché automobile français et constitue l'un des indicateurs permettant de calculer la consommation des ménages en automobile.\",\"prefLabelLg1\":\"Immatriculations de voitures particulières neuves\",\"abstractLg2\":\"The number of new private car registrations is used to monitor the trends on the French automobile market and constitutes one of the indicators used to calculate household automobile consumption.\",\"prefLabelLg2\":\"New private car registrations\",\"creators\":[],\"publishers\":[],\"id\":\"p1638\",\"contributors\":[]} ";
JSONObject jsonIndicator = new JSONObject(json);
Indicator indicator = initIndicator();

IndicatorsUtils indicatorsUtils = new IndicatorsUtils(true, repositoryGestion, null, null, null, famOpeSerIndUtils, null, null, null, null, "fr", "en");


Indicator indicatorByApp = indicatorsUtils.buildIndicatorFromJson(jsonIndicator);
org.assertj.core.api.Assertions.assertThat(indicator).usingRecursiveComparison().isEqualTo(indicatorByApp);

}


public Indicator initIndicator() throws RmesException {
Indicator indicator = new Indicator();
indicator.setId("p1638");
indicator.setIdSims("1779");

indicator.setAbstractLg1("Le nombre d'immatriculations de voitures particulières neuves permet de suivre l'évolution du marché automobile français et constitue l'un des indicateurs permettant de calculer la consommation des ménages en automobile.");
indicator.setAbstractLg2("The number of new private car registrations is used to monitor the trends on the French automobile market and constitutes one of the indicators used to calculate household automobile consumption.");
indicator.setPrefLabelLg1("Immatriculations de voitures particulières neuves");
indicator.setPrefLabelLg2("New private car registrations");

List<String> creators = new ArrayList<>();
indicator.setCreators(creators);

List<OperationsLink> pubList = new ArrayList<>();
indicator.setPublishers(pubList);

List<OperationsLink> contrList = new ArrayList<>();
indicator.setContributors(contrList);

OperationsLink wgb = new OperationsLink("s1034",null,"Autres indicateurs","Other indexes");
List<OperationsLink> wgbList = new ArrayList<>();
wgbList.add(wgb);
indicator.setWasGeneratedBy(wgbList);
return indicator;
}

}

0 comments on commit 826dbfe

Please sign in to comment.