Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new Test while sync old workstation #174

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.JsonNode;

import javax.xml.soap.SAAJResult;
import java.util.HashMap;
Expand Down Expand Up @@ -176,27 +177,35 @@ private void getStructureComponents(String id, JSONObject structure) throws Rmes
component.put(ORDRE, componentSpecification.getString(ORDRE));
}
if(componentSpecification.has("attachement")){
component.put("attachement", componentSpecification.getString("attachment").replace(QB.NAMESPACE, ""));
component.put("attachement", componentSpecification.getString("attachement").replace(QB.NAMESPACE, ""));
}
if(componentSpecification.has(OBLIGATOIRE)){
component.put(OBLIGATOIRE, componentSpecification.getString(OBLIGATOIRE).equalsIgnoreCase("true") ? "oui": "non");
}

if(idComponent.startsWith("a")){
attributes.put(component);
extracted(attributes, component);
}
if(idComponent.startsWith("m")){
measures.put(component);
extracted(measures, component);
}
if(idComponent.startsWith("d")){
dimensions.put(component);
extracted(dimensions, component);
}
}
structure.put("attributs", attributes);
structure.put("mesures", measures);
structure.put("dimensions", dimensions);
}

private void extracted(JSONArray sortie, JSONObject component) {
JSONObject entree = component;
entree.remove("label");
entree.remove("uri");
entree.remove("concept");
sortie.put(entree);
}

private static final String STATUT_VALIDATION = "statutValidation";

@Override
Expand Down Expand Up @@ -226,6 +235,7 @@ public JSONObject getComponent(String id) throws RmesException {

JSONObject component = repoGestion.getResponseAsObject(buildRequest("getComponent.ftlh", params));


component.put(LABEL, this.formatLabel(component));
component.put(NOM,this.formatNom(component));
component.remove("altLabelLg1");
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/fr/insee/rmes/persistence/RepositoryGestionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.insee.rmes.persistence;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class RepositoryGestionTest {

@Test
void getResponseAsArrayTest(){

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package fr.insee.rmes.services;

import com.fasterxml.jackson.core.JsonProcessingException;
import fr.insee.rmes.persistence.RepositoryGestion;
import fr.insee.rmes.services.structures.StructuresImpl;
import fr.insee.rmes.services.structures.stub.StructuresImplMockBuildRequest;
import fr.insee.rmes.utils.config.Config;
import fr.insee.rmes.utils.exceptions.RmesException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;

import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;

@JsonTest(properties = {"spring.profiles.active=test"})
@Import({Config.class, StructuresImplMockBuildRequest.class, RepositoryGestion.class})
class StructuresImplIntegrationIntegrationTest {

@Autowired
StructuresImpl structuresImplMockBuildRequest;

@MockBean
RepositoryGestion repositoryGestion;

@Test
void getStructureTest() throws RmesException, JsonProcessingException {

Mockito.when(repositoryGestion.getResponseAsArray("getStructure.ftlh")).thenReturn(new JSONArray("[{\"dateMiseAJour\":\"2023-02-10T14:37:14.691014\",\"dateCreation\":\"2022-10-28T13:53:59.228157\",\"prefLabelLg1\":\"set\",\"notation\":\"est\",\"prefLabelLg2\":\"set\",\"statutValidation\":\"Unpublished\",\"id\":\"dsd1001\",\"uri\":\"http://bauhaus/structuresDeDonnees/structure/dsd1001\"}]"));
Mockito.when(repositoryGestion.getResponseAsArray("getStructureComponents.ftlh")).thenReturn(new JSONArray("[{\"ordre\":\"1\",\"id\":\"d1001\"}]"));
Mockito.when(repositoryGestion.getResponseAsObject("getComponent.ftlh")).thenReturn(new JSONObject("{\"dateMiseAJour\":\"2022-10-28T13:53:24.204248\",\"dateCreation\":\"2022-10-28T13:53:24.204248\",\"prefLabelLg1\":\"test_list_part-fr\",\"notation\":\"test_list_part\",\"prefLabelLg2\":\"test_list_part-en\",\"statutValidation\":\"Unpublished\",\"id\":\"d1001\",\"type\":\"Dimension\",\"uri\":\"http://bauhaus/structuresDeDonnees/composants/dimension/d1001\",\"representation\":\"http://bauhaus/codes/concept/CodeTestSuppressionCasAvecListePartielle\"}"));
Mockito.when(repositoryGestion.getResponseAsArray("getComponentChildren.ftlh")).thenReturn(new JSONArray("[]"));

String expected = "{\"dateMiseAJour\":\"2023-02-10T14:37:14.691014\",\"dateCreation\":\"2022-10-28T13:53:59.228157\",\"notation\":\"est\",\"statutValidation\":\"Provisoire, jamais publiée\",\"mesures\":[],\"id\":\"dsd1001\",\"label\":[{\"langue\":\"fr\",\"contenu\":\"set\"},{\"langue\":\"en\",\"contenu\":\"set\"}],\"uri\":\"http://bauhaus/structuresDeDonnees/structure/dsd1001\",\"attributs\":[],\"dimensions\":[{\"ordre\":\"1\",\"notation\":\"test_list_part\",\"label\":[{\"langue\":\"fr\",\"contenu\":\"test_list_part-fr\"},{\"langue\":\"en\",\"contenu\":\"test_list_part-en\"}],\"uri\":\"http://bauhaus/structuresDeDonnees/composants/dimension/d1001\",\"representation\":\"http://bauhaus/codes/concept/CodeTestSuppressionCasAvecListePartielle\",\"dateMiseAJour\":\"2022-10-28T13:53:24.204248\",\"dateCreation\":\"2022-10-28T13:53:24.204248\",\"statutValidation\":\"Provisoire, jamais publiée\",\"id\":\"d1001\",\"type\":\"Dimension\"}]}";
assertEquals(expected,structuresImplMockBuildRequest.getStructure("dsd1001"),true);
}


@Test
void getStructureComponentsTest(){
String structure="{\"dateMiseAJour\":\"2023-02-10T14:37:14.691014\",\"dateCreation\":\"2022-10-28T13:53:59.228157\",\"notation\":\"est\",\"statutValidation\":\"Provisoire, jamais publiée\",\"id\":\"dsd1001\",\"label\":[{\"langue\":\"fr\",\"contenu\":\"set\"},{\"langue\":\"en\",\"contenu\":\"set\"}],\"uri\":\"http://bauhaus/structuresDeDonnees/structure/dsd1001\"}";
String id="dsd1001";
String result="{\"dateMiseAJour\":\"2023-02-10T14:37:14.691014\",\"dateCreation\":\"2022-10-28T13:53:59.228157\",\"notation\":\"est\",\"statutValidation\":\"Provisoire, jamais publiée\",\"mesures\":[],\"id\":\"dsd1001\",\"label\":[{\"langue\":\"fr\",\"contenu\":\"set\"},{\"langue\":\"en\",\"contenu\":\"set\"}],\"uri\":\"http://bauhaus/structuresDeDonnees/structure/dsd1001\",\"attributs\":[],\"dimensions\":[{\"dateMiseAJour\":\"2022-10-28T13:53:24.204248\",\"dateCreation\":\"2022-10-28T13:53:24.204248\",\"ordre\":\"1\",\"notation\":\"test_list_part\",\"statutValidation\":\"Provisoire, jamais publiée\",\"id\":\"d1001\",\"label\":[{\"langue\":\"fr\",\"contenu\":\"test_list_part-fr\"},{\"langue\":\"en\",\"contenu\":\"test_list_part-en\"}],\"type\":\"Dimension\",\"uri\":\"http://bauhaus/structuresDeDonnees/composants/dimension/d1001\",\"representation\":\"http://bauhaus/codes/concept/CodeTestSuppressionCasAvecListePartielle\"}]}";
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fr.insee.rmes.services.structures.stub;

import fr.insee.rmes.services.structures.StructuresImpl;
import fr.insee.rmes.utils.exceptions.RmesException;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class StructuresImplMockBuildRequest extends StructuresImpl {

@Override
protected String buildRequest(String path, String fileName, Map<String, Object> params) throws RmesException {
switch (fileName) {
case "getStructure.ftlh":
case "getStructureComponents.ftlh":
case "getComponent.ftlh":
case "getComponentChildren.ftlh":
return fileName;

default:
throw new RuntimeException("Not implemented " + fileName);
}

}
}
8 changes: 8 additions & 0 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fr:
insee:
rmes:
magma:
envir: QF
force:
ssl: false