Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: jamal-khey <myjamal89@gmail.com>
  • Loading branch information
jamal-khey committed Aug 1, 2024
1 parent 4fb0ead commit dff6051
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/powsybl/caseserver/CaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ public Set<UUID> getCaseToReindex() {
.map(CaseMetadataEntity::getId)
.collect(Collectors.toSet());
}
public List<CaseInfos> getAllCases() {
return getCases(getStorageRootDir());
}

CaseInfos createInfos(String fileBaseName, UUID caseUuid, String format) {
FileNameParser parser = FileNameParsers.findParser(fileBaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public SupervisionService(CaseInfosService caseInfosService, CaseService caseSer
}

public void reindexAllCases() {
List<CaseInfos> allCases = caseService.getCases(caseService.getStorageRootDir());
List<CaseInfos> allCases = caseService.getAllCases();
Set<UUID> casesToIndex = caseService.getCaseToReindex();
List<CaseInfos> data = allCases.stream().filter(c -> casesToIndex.contains(c.getUuid())).toList();
caseInfosService.recreateAllCaseInfos(data);
Expand All @@ -48,13 +48,13 @@ public long deleteIndexedDirectoryElements() {
AtomicReference<Long> startTime = new AtomicReference<>();
startTime.set(System.nanoTime());

long nbIndexesToDelete = getIndexedDirectoryElementsCount();
long nbIndexesToDelete = getIndexedCaseElementsCount();
caseInfosRepository.deleteAll();
LOGGER.trace("Indexed directory elements deletion : {} seconds", TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get()));
return nbIndexesToDelete;
}

private long getIndexedDirectoryElementsCount() {
public long getIndexedCaseElementsCount() {
return caseInfosRepository.count();
}
}
58 changes: 58 additions & 0 deletions src/test/java/com/powsybl/caseserver/SupervisionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.caseserver;

import com.powsybl.caseserver.elasticsearch.CaseInfosRepository;
import com.powsybl.caseserver.repository.CaseMetadataRepository;
import com.powsybl.caseserver.services.SupervisionService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

/**
* @author Jamal KHEYYAD <jamal.kheyyad at rte-international.com>
*/
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, properties = {"case-store-directory=/cases"})
@ContextConfigurationWithTestChannel
public class SupervisionTest {
@Autowired
SupervisionService supervisionService;
@Autowired
CaseInfosRepository caseInfosRepository;
@Autowired
CaseMetadataRepository caseMetadataRepository;
@Autowired
CaseService caseService;

@Autowired
private MockMvc mvc;

@Test
public void testGetElementInfosCount() {
supervisionService.getIndexedCaseElementsCount();
verify(caseInfosRepository, times(1)).count();
}

@Test
public void testDeleteElementInfos() {
supervisionService.deleteIndexedDirectoryElements();

verify(caseInfosRepository, times(1)).count();
verify(caseInfosRepository, times(1)).deleteAll();
}


}

0 comments on commit dff6051

Please sign in to comment.