전략 시간봉 오류 수정
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
package com.goldenchart.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.goldenchart.entity.GcStrategy;
|
||||
import com.goldenchart.repository.GcStrategyRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class StrategyConditionTimeframeServiceTest {
|
||||
|
||||
@Mock
|
||||
private GcStrategyRepository strategyRepo;
|
||||
|
||||
@Spy
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@InjectMocks
|
||||
private StrategyConditionTimeframeService service;
|
||||
|
||||
@BeforeEach
|
||||
void stubStrategy() {
|
||||
GcStrategy strategy = new GcStrategy();
|
||||
strategy.setId(1L);
|
||||
strategy.setBuyConditionJson("""
|
||||
{
|
||||
"type": "TIMEFRAME",
|
||||
"candleType": "5m",
|
||||
"children": [{
|
||||
"type": "CONDITION",
|
||||
"condition": { "indicatorType": "RSI", "period": 14 }
|
||||
}]
|
||||
}
|
||||
""");
|
||||
strategy.setSellConditionJson(null);
|
||||
when(strategyRepo.findById(1L)).thenReturn(Optional.of(strategy));
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectForStrategy_readsTimeframeFromDsl() {
|
||||
Set<String> tfs = service.collectForStrategy(1L);
|
||||
assertEquals(Set.of("5m"), tfs);
|
||||
assertTrue(service.usesTimeframe(1L, "5m"));
|
||||
assertFalse(service.usesTimeframe(1L, "1m"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectForStrategy_legacyTreeDefaultsTo1m() {
|
||||
GcStrategy legacy = new GcStrategy();
|
||||
legacy.setId(2L);
|
||||
legacy.setBuyConditionJson("""
|
||||
{
|
||||
"type": "AND",
|
||||
"children": [{
|
||||
"type": "CONDITION",
|
||||
"condition": { "indicatorType": "RSI", "period": 14 }
|
||||
}]
|
||||
}
|
||||
""");
|
||||
when(strategyRepo.findById(2L)).thenReturn(Optional.of(legacy));
|
||||
|
||||
assertEquals(Set.of("1m"), service.collectForStrategy(2L));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user