Skip to content
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
14 changes: 14 additions & 0 deletions .run/Unit tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unit tests" type="JUnit" factoryName="JUnit">
<module name="bpm" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="ALTERNATIVE_JRE_PATH" value="temurin-21" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="directory" />
<dir value="$PROJECT_DIR$/src/test/java" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
10 changes: 7 additions & 3 deletions src/main/java/fr/insee/bpm/metadata/model/MetadataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import java.util.stream.Collectors;

@Slf4j
@Getter @Setter
@Getter
@Setter
public class MetadataModel {

private VariablesMap variables = new VariablesMap();
Expand Down Expand Up @@ -74,11 +75,14 @@ public List<String> getSubGroupNames() {
public int getGroupsCount() {
return groups.size();
}

/** Identifiers are not represented by Variable objects, they are:
* - the root identifier (fixed value),
* - each subgroup name is also an identifier name.
* @return The list of all identifiers associated to the variables map. */
* @return The list of all identifiers associated to the variables map.
* DEPRECATED : Same logic as getGroupNames
* */
@Deprecated(forRemoval = true)
public List<String> getIdentifierNames() {
List<String> res = new ArrayList<>(List.of(Constants.ROOT_IDENTIFIER_NAME));
res.addAll(getSubGroupNames());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fr/insee/bpm/metadata/model/VariableType.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static VariableType getTypeFromJavaClass(Class<?> clazz){
return STRING;
} else if (clazz.isAssignableFrom(Boolean.class)){
return BOOLEAN;
} else if (clazz.isAssignableFrom(Date.class)||clazz.isAssignableFrom(Instant.class)){
} else if (clazz.isAssignableFrom(Date.class)
||clazz.isAssignableFrom(Instant.class)){
return DATE;
} else {
log.warn(String.format("Unrecognized type for class %s ", clazz));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fr.insee.bpm.metadata.model;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;

class CalculatedVariablesTest {

private CalculatedVariables calculatedVariables;

public static final String VARIABLE_NAME = "test";


@BeforeEach
void setUp() {
calculatedVariables = new CalculatedVariables();
}

@Test
void putVariable() {
//GIVEN
CalculatedVariables.CalculatedVariable calculatedVariable = new CalculatedVariables.CalculatedVariable(VARIABLE_NAME, "");

//WHEN
calculatedVariables.putVariable(calculatedVariable);

//THEN
Assertions.assertThat(calculatedVariables).containsEntry(VARIABLE_NAME, calculatedVariable);
}

@Test
void getVtlExpression() {
//GIVEN
String expectedVtlExpression = "testVtl";
CalculatedVariables.CalculatedVariable calculatedVariable = new CalculatedVariables.CalculatedVariable(VARIABLE_NAME, expectedVtlExpression);
calculatedVariables.put(VARIABLE_NAME, calculatedVariable);

//WHEN
String vtlExpression = calculatedVariables.getVtlExpression(VARIABLE_NAME);

//THEN
Assertions.assertThat(vtlExpression).isEqualTo(expectedVtlExpression);
}

@Test
void getDependantVariables() {
//GIVEN
String dependantVariableName = "testDependant";
CalculatedVariables.CalculatedVariable calculatedVariable = new CalculatedVariables.CalculatedVariable(VARIABLE_NAME, "");
calculatedVariable.dependantVariables.add(dependantVariableName);
calculatedVariables.put(VARIABLE_NAME, calculatedVariable);

//WHEN
List<String> actualDependantVariables = calculatedVariables.getDependantVariables(VARIABLE_NAME);

//THEN
Assertions.assertThat(actualDependantVariables).containsExactly(dependantVariableName);
}
}
43 changes: 37 additions & 6 deletions src/test/java/fr/insee/bpm/metadata/model/GroupTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
package fr.insee.bpm.metadata.model;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertThrows;

class GroupTest {
class GroupTest {

private Group group;

@BeforeEach
void setUp() {
group = new Group();
}

@Test
// @SuppressWarnings({"null", "ConstantConditions"})
void nullParentName() {
assertThrows(NullPointerException.class, () -> new Group("TEST", null));
@SuppressWarnings({"null", "ConstantConditions"})
void constructorNullParentNameTest() {
assertThrows(NullPointerException.class,
() -> new Group("TEST", null)
);
}

@Test
void emptyParentName() {
assertThrows(IllegalArgumentException.class, () -> new Group("TEST", ""));
void constructorEmptyParentNameTest() {
assertThrows(IllegalArgumentException.class,
() -> new Group("TEST", "")
);
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
void isRootTest(boolean expectedBool) {
//GIVEN
if(!expectedBool){
group.parentName = "parentName";
}

//WHEN
boolean result = group.isRoot();

//THEN
Assertions.assertThat(result).isEqualTo(expectedBool);

}
}
Loading
Loading