74 lines
2.7 KiB
Java
74 lines
2.7 KiB
Java
package com.goldenchart.service;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class StrategyDslTimeframeNormalizerTest {
|
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
private final StrategyDslTimeframeNormalizer normalizer = new StrategyDslTimeframeNormalizer(objectMapper);
|
|
|
|
@Test
|
|
void normalize_preserves3mAnd5mWithout1m() throws Exception {
|
|
String json = """
|
|
{
|
|
"type": "TIMEFRAME",
|
|
"candleType": "1m",
|
|
"candleTypes": ["3m", "5m"],
|
|
"children": [{
|
|
"type": "CONDITION",
|
|
"condition": { "indicatorType": "RSI", "period": 14 }
|
|
}]
|
|
}
|
|
""";
|
|
String normalized = normalizer.normalizeJson(json, "테스트");
|
|
JsonNode root = objectMapper.readTree(normalized);
|
|
assertEquals(2, root.path("candleTypes").size());
|
|
assertEquals("3m", root.path("candleTypes").get(0).asText());
|
|
assertEquals("5m", root.path("candleTypes").get(1).asText());
|
|
assertEquals("3m", root.path("candleType").asText());
|
|
}
|
|
|
|
@Test
|
|
void normalize_preservesSingleExplicit3m() throws Exception {
|
|
String json = """
|
|
{
|
|
"type": "TIMEFRAME",
|
|
"candleType": "3m",
|
|
"children": [{
|
|
"type": "CONDITION",
|
|
"condition": { "indicatorType": "RSI", "period": 14 }
|
|
}]
|
|
}
|
|
""";
|
|
String normalized = normalizer.normalizeJson(json, "테스트");
|
|
JsonNode root = objectMapper.readTree(normalized);
|
|
assertEquals("3m", root.path("candleType").asText());
|
|
}
|
|
|
|
@Test
|
|
void normalize_preservesMultiCandleTypesOnSave() throws Exception {
|
|
String json = """
|
|
{
|
|
"type": "TIMEFRAME",
|
|
"candleType": "1m",
|
|
"candleTypes": ["1m", "3m", "5m"],
|
|
"children": [{
|
|
"type": "CONDITION",
|
|
"condition": { "indicatorType": "RSI", "period": 14 }
|
|
}]
|
|
}
|
|
""";
|
|
String normalized = normalizer.normalizeJson(json, "5분봉 테스트 전략");
|
|
JsonNode root = objectMapper.readTree(normalized);
|
|
assertTrue(root.path("candleTypes").isArray());
|
|
assertEquals(3, root.path("candleTypes").size());
|
|
assertEquals("1m", root.path("candleTypes").get(0).asText());
|
|
assertEquals("3m", root.path("candleTypes").get(1).asText());
|
|
assertEquals("5m", root.path("candleTypes").get(2).asText());
|
|
}
|
|
}
|