Skip to content

Commit 72904e0

Browse files
authored
Merge pull request #734 from ELIXIR-NO/fix/camel-and-upper-snake-case
fix(proxy): [ExportRequestType] support camelCase and upper SNAKE_CASE
2 parents 5a6d31d + 6112c0b commit 72904e0

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

services/localega-tsd-proxy/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
testImplementation("org.springframework.security:spring-security-test")
4040
testImplementation("org.springframework.amqp:spring-rabbit-test")
4141
testImplementation("org.springframework.boot:spring-boot-starter-test")
42-
testImplementation("org.junit.jupiter:junit-jupiter-api")
42+
testImplementation("org.junit.jupiter:junit-jupiter")
4343
testImplementation("org.junit.jupiter:junit-jupiter-engine")
4444
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
4545
runtimeOnly("org.postgresql:postgresql")

services/localega-tsd-proxy/src/main/java/no/elixir/fega/ltp/dto/ExportRequestType.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
11
package no.elixir.fega.ltp.dto;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
54
import com.fasterxml.jackson.annotation.JsonValue;
65
import lombok.Getter;
76
import lombok.ToString;
87

8+
/**
9+
* Represents the type of identifier used in an export request.
10+
*
11+
* <p>Supports deserialization from both camelCase ({@code "fileId"}, {@code "datasetId"}) and upper
12+
* snake case ({@code "FILE_ID"}, {@code "DATASET_ID"}) formats.
13+
*/
914
@Getter
1015
@ToString
1116
public enum ExportRequestType {
17+
18+
/** Indicates the export request targets a specific file. */
1219
FILE_ID("fileId"),
20+
21+
/** Indicates the export request targets an entire dataset. */
1322
DATASET_ID("datasetId");
23+
24+
/** The camelCase JSON representation of this type. */
1425
@JsonValue private final String value;
1526

27+
/**
28+
* @param value the camelCase string used for JSON serialization
29+
*/
1630
ExportRequestType(String value) {
1731
this.value = value;
1832
}
1933

34+
/**
35+
* Deserializes a string into an {@link ExportRequestType}.
36+
*
37+
* <p>Accepts both camelCase values ({@code "fileId"}, {@code "datasetId"}) and enum constant
38+
* names ({@code "FILE_ID"}, {@code "DATASET_ID"}).
39+
*
40+
* @param value the string to deserialize
41+
* @return the matching {@link ExportRequestType}
42+
* @throws IllegalArgumentException if the value does not match any known type
43+
*/
2044
@JsonCreator
21-
public static ExportRequestType fromValue(@JsonProperty String value) {
45+
public static ExportRequestType fromValue(String value) {
2246
for (ExportRequestType type : ExportRequestType.values()) {
23-
if (type.value.equals(value)) {
47+
if (type.value.equals(value) || type.name().equals(value)) {
2448
return type;
2549
}
2650
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package no.elixir.fega.ltp.dto;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class ExportRequestTypeTest {
9+
10+
@Test
11+
void fromValueWithCamelCaseFileId() {
12+
assertEquals(ExportRequestType.FILE_ID, ExportRequestType.fromValue("fileId"));
13+
}
14+
15+
@Test
16+
void fromValueWithCamelCaseDatasetId() {
17+
assertEquals(ExportRequestType.DATASET_ID, ExportRequestType.fromValue("datasetId"));
18+
}
19+
20+
@Test
21+
void fromValueWithUpperSnakeCaseFileId() {
22+
assertEquals(ExportRequestType.FILE_ID, ExportRequestType.fromValue("FILE_ID"));
23+
}
24+
25+
@Test
26+
void fromValueWithUpperSnakeCaseDatasetId() {
27+
assertEquals(ExportRequestType.DATASET_ID, ExportRequestType.fromValue("DATASET_ID"));
28+
}
29+
30+
@Test
31+
void fromValueWithUnknownValueThrowsException() {
32+
IllegalArgumentException ex =
33+
assertThrows(IllegalArgumentException.class, () -> ExportRequestType.fromValue("unknown"));
34+
assertEquals("Unknown ExportType: unknown", ex.getMessage());
35+
}
36+
37+
@Test
38+
void jsonValueReturnsCamelCase() {
39+
assertEquals("fileId", ExportRequestType.FILE_ID.getValue());
40+
assertEquals("datasetId", ExportRequestType.DATASET_ID.getValue());
41+
}
42+
}

0 commit comments

Comments
 (0)