-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return enum class for typeChargement and typeNormage
- Loading branch information
Showing
6 changed files
with
108 additions
and
38 deletions.
There are no files selected for viewing
70 changes: 35 additions & 35 deletions
70
arc-core/src/main/java/fr/insee/arc/core/service/p2chargement/factory/TypeChargement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
package fr.insee.arc.core.service.p2chargement.factory; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import fr.insee.arc.utils.exception.ArcException; | ||
import fr.insee.arc.utils.exception.ArcExceptionMessage; | ||
|
||
public enum TypeChargement { | ||
CLEF_VALEUR("clef-valeur"), | ||
XML("xml"), | ||
PLAT("plat"), | ||
XML_COMPLEXE("xml-complexe"); | ||
|
||
private String nom; | ||
|
||
private TypeChargement(String nom) { | ||
this.nom = nom; | ||
} | ||
|
||
public String getNom() { | ||
return nom; | ||
} | ||
|
||
public void setNom(String nom) { | ||
this.nom = nom; | ||
} | ||
|
||
public static TypeChargement getEnum(String code) { | ||
|
||
switch (code) { | ||
case "clef-valeur": | ||
return CLEF_VALEUR; | ||
case "xml": | ||
return XML; | ||
case "plat": | ||
return PLAT; | ||
case "xml-complexe": | ||
return XML_COMPLEXE; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
CLEF_VALEUR("clef-valeur"), XML("xml"), PLAT("plat"), XML_COMPLEXE("xml-complexe"); | ||
|
||
private String nom; | ||
|
||
private TypeChargement(String nom) { | ||
this.nom = nom; | ||
} | ||
|
||
public String getNom() { | ||
return nom; | ||
} | ||
|
||
public void setNom(String nom) { | ||
this.nom = nom; | ||
} | ||
|
||
public static TypeChargement getEnum(String code) throws ArcException { | ||
|
||
List<TypeChargement> filtered = Arrays.asList(TypeChargement.values()).stream() | ||
.filter(t -> t.getNom().equals(code)).collect(Collectors.toList()); | ||
|
||
if (filtered.isEmpty()) { | ||
throw new ArcException(ArcExceptionMessage.LOAD_TYPE_NOT_FOUND, code); | ||
} | ||
|
||
return filtered.get(0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...core/src/test/java/fr/insee/arc/core/service/p2chargement/factory/TypeChargementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package fr.insee.arc.core.service.p2chargement.factory; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
import fr.insee.arc.core.service.p3normage.bo.TypeNormage; | ||
import fr.insee.arc.utils.exception.ArcException; | ||
|
||
public class TypeChargementTest { | ||
|
||
|
||
@Test | ||
public void getEnum_test_ok() throws ArcException { | ||
|
||
assertEquals(TypeChargement.XML_COMPLEXE, TypeChargement.getEnum("xml-complexe")); | ||
} | ||
|
||
@Test(expected = ArcException.class) | ||
public void getEnum_test_ko() throws ArcException { | ||
TypeChargement.getEnum("type de chargement inexistant"); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
arc-core/src/test/java/fr/insee/arc/core/service/p3normage/bo/TypeNormageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.insee.arc.core.service.p3normage.bo; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
import fr.insee.arc.utils.exception.ArcException; | ||
|
||
public class TypeNormageTest { | ||
|
||
@Test | ||
public void getEnum_test_ok() throws ArcException { | ||
|
||
assertEquals(TypeNormage.RELATION, TypeNormage.getEnum("relation")); | ||
} | ||
|
||
@Test(expected = ArcException.class) | ||
public void getEnum_test_ko() throws ArcException { | ||
TypeNormage.getEnum("type de norme inexistant"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters