Skip to content

Commit 37ddd2e

Browse files
authored
Merge pull request #129 from InseeFr/128-améliorer-couverture-de-test
feature : methods for FilesUtilsTest.java
2 parents 2eb9599 + c52f347 commit 37ddd2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1295
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package fr.insee.rmes.config;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.ValueSource;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
class OpenApiConfigurationTest {
11+
12+
@ParameterizedTest
13+
@ValueSource(strings = { "2025", "--",""," " })
14+
void shouldReturnOpenAPIWhenAppVersionIsNotNull(String appVersion) {
15+
OpenApiConfiguration openApiConfiguration = new OpenApiConfiguration();
16+
OpenAPI response =openApiConfiguration.openAPI(appVersion);
17+
assertTrue(response.toString().contains("version: "+appVersion));
18+
}
19+
20+
@Test
21+
void shouldReturnOpenAPIWhenAppVersionIsNull() {
22+
OpenApiConfiguration openApiConfiguration = new OpenApiConfiguration();
23+
OpenAPI response =openApiConfiguration.openAPI(null);
24+
assertTrue(response.toString().contains("version: null"));
25+
}
26+
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fr.insee.rmes.config;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.DefaultBootstrapContext;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
7+
import org.springframework.core.env.ConfigurableEnvironment;
8+
import org.springframework.core.env.StandardEnvironment;
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
class PropertiesLoggerTest {
12+
13+
@Test
14+
void shouldVerifyStateAndTestResoutValeurAvecMasquePwdWhenOnApplicationEvent() {
15+
DefaultBootstrapContext defaultBootstrapContext = new DefaultBootstrapContext();
16+
SpringApplication springApplication = new SpringApplication();
17+
String[] args = {"password", "World"};
18+
ConfigurableEnvironment configurableEnvironment = new StandardEnvironment();
19+
ApplicationEnvironmentPreparedEvent environment = new ApplicationEnvironmentPreparedEvent(defaultBootstrapContext,springApplication,args,configurableEnvironment);
20+
21+
PropertiesLogger propertiesLogger = new PropertiesLogger();
22+
String save = propertiesLogger.toString();
23+
propertiesLogger.onApplicationEvent(environment);
24+
String after = propertiesLogger.toString();
25+
26+
assertEquals(save,after);
27+
28+
}
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fr.insee.rmes.config.keycloak;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.web.client.ResourceAccessException;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class KeycloakServicesTest {
8+
9+
@Test
10+
void shouldThrowIllegalArgumentExceptionWhenGetFreshToken() {
11+
KeycloakServices keycloakServices = new KeycloakServices("secret","resource","server","realm");
12+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, keycloakServices::getFreshToken);
13+
assertTrue(exception.getMessage().contains("URI is not absolute"));
14+
15+
}
16+
17+
@Test
18+
void shouldThrowResourceAccessExceptionWhenGetFreshToken() {
19+
KeycloakServices keycloakServices = new KeycloakServices("secret","resource","http://localhost:8080/","realm");
20+
ResourceAccessException exception = assertThrows(ResourceAccessException.class, keycloakServices::getFreshToken);
21+
assertTrue(exception.getMessage().contains("Connection refused"));
22+
}
23+
24+
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package fr.insee.rmes.exceptions;
2+
3+
import org.json.JSONArray;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.http.HttpStatusCode;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
class RmesExceptionTest {
11+
12+
@Test
13+
void shouldReturnToRestMessageWhenErrorCodeIsNull() {
14+
15+
JSONArray jsonArray = new JSONArray().put(1).put(2).put(3);
16+
List<RmesException> listOfRmesException = new ArrayList<>();
17+
18+
listOfRmesException.add(new RmesException(500,"message","details"));
19+
listOfRmesException.add(new RmesException(500,"","details"));
20+
listOfRmesException.add(new RmesException(500,"message",""));
21+
listOfRmesException.add(new RmesException(500,"",""));
22+
23+
listOfRmesException.add(new RmesException(HttpStatusCode.valueOf(500),"message","details"));
24+
listOfRmesException.add(new RmesException(HttpStatusCode.valueOf(500),"","details"));
25+
listOfRmesException.add(new RmesException(HttpStatusCode.valueOf(500),"message",""));
26+
listOfRmesException.add(new RmesException(HttpStatusCode.valueOf(500),"",""));
27+
28+
listOfRmesException.add(new RmesException(500,"message",jsonArray));
29+
listOfRmesException.add(new RmesException(500,"",jsonArray));
30+
listOfRmesException.add(new RmesException(500,"message",new JSONArray()));
31+
listOfRmesException.add(new RmesException(500,"",new JSONArray()));
32+
33+
List<Integer> keyValueNumber= new ArrayList<>();
34+
35+
for (RmesException exception : listOfRmesException){
36+
keyValueNumber.add(exception.getDetails().split(":").length-1);
37+
}
38+
assertEquals(List.of(2, 1, 1, 0, 2, 1, 1, 0, 2, 1, 2, 1),keyValueNumber);
39+
40+
}
41+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fr.insee.rmes.model;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
class CategoryReferenceTest {
7+
8+
@Test
9+
void shouldTestToString() {
10+
CategoryReference categoryReference = new CategoryReference();
11+
categoryReference.setTypeOfObject("TypeOfObjectExample");
12+
assertTrue(categoryReference.toString().contains(categoryReference.getTypeOfObject()));
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fr.insee.rmes.model;
2+
3+
import org.junit.jupiter.api.Test;
4+
import java.util.List;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class CategorySchemeTest {
8+
9+
@Test
10+
void shouldTestToString() {
11+
CategoryScheme categoryScheme = new CategoryScheme();
12+
13+
Category rabbit = new Category();
14+
rabbit.setLabel("rabbit");
15+
Category cat= new Category();
16+
rabbit.setLabel("cat");
17+
List<Category> categories = List.of(rabbit,cat);
18+
19+
categoryScheme.setCategories(categories);
20+
categoryScheme.setLabel("LabelExample");
21+
22+
assertTrue(categoryScheme.toString().contains(categoryScheme.getLabel()) && categoryScheme.toString().contains(categoryScheme.getCategories().toString()));
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fr.insee.rmes.model;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
class CategoryTest {
7+
8+
@Test
9+
void shouldTestToString() {
10+
Category category = new Category();
11+
category.setLabel("labelExample");
12+
assertTrue(category.toString().contains(category.getLabel()));
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fr.insee.rmes.model;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
class CitationTest {
7+
8+
@Test
9+
void shouldTestToString() {
10+
Citation citation = new Citation();
11+
citation.setTitle("titleExample");
12+
assertTrue(citation.toString().contains(citation.getTitle()));
13+
}
14+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package fr.insee.rmes.model;
2+
3+
import org.junit.jupiter.api.Test;
4+
import java.util.List;
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class CodeListTest {
8+
9+
@Test
10+
void shouldTestToString() {
11+
12+
Code code2025 = new Code();
13+
code2025.setLevelNumber(2025);
14+
code2025.setValue("valueExample");
15+
code2025.setDiscrete(true);
16+
17+
Code code2026 = new Code();
18+
code2026.setLevelNumber(2026);
19+
code2026.setValue("valueExample");
20+
code2026.setDiscrete(true);
21+
22+
List<Code> codeList = List.of(code2025,code2026);
23+
24+
CodeList codeListExample = new CodeList();
25+
codeListExample.setUniversallyUnique(true);
26+
codeListExample.setCodeList(codeList);
27+
28+
assertTrue(codeListExample.toString().contains(String.valueOf(codeListExample.getCodeList())) &&
29+
codeListExample.toString().contains(String.valueOf(codeListExample.isUniversallyUnique()))
30+
);
31+
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package fr.insee.rmes.model;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
class CodeTest {
7+
8+
@Test
9+
void shouldTestToString() {
10+
11+
Code code = new Code();
12+
13+
code.setLevelNumber(2025);
14+
code.setValue("valueExample");
15+
code.setDiscrete(true);
16+
17+
CategoryReference categoryReference = new CategoryReference();
18+
categoryReference.setTypeOfObject("typeOfObjectExample");
19+
code.setCategoryReference(categoryReference);
20+
21+
Category category = new Category();
22+
category.setLabel("labelExample");
23+
code.setCategory(category);
24+
25+
26+
assertTrue(code.toString().contains(String.valueOf(code.getLevelNumber())) &&
27+
code.toString().contains(String.valueOf(code.isDiscrete())) &&
28+
code.toString().contains(code.getValue()) &&
29+
code.toString().contains(String.valueOf(code.getCategoryReference())) &&
30+
code.toString().contains(String.valueOf(code.getCategory()))
31+
);
32+
33+
}
34+
}

0 commit comments

Comments
 (0)