Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.gridsuite.monitor.commons.SecurityAnalysisConfig;
import org.gridsuite.monitor.server.dto.ProcessExecution;
import org.gridsuite.monitor.server.dto.ReportPage;
import org.gridsuite.monitor.server.services.MonitorService;
import org.gridsuite.monitor.server.services.internal.MonitorService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.external.adapter;

import org.gridsuite.monitor.commons.ResultType;
import org.gridsuite.monitor.server.services.internal.ResultProvider;
import org.gridsuite.monitor.server.services.external.client.SecurityAnalysisRestClient;
import org.springframework.stereotype.Service;

import java.util.UUID;
Expand All @@ -16,10 +18,10 @@
*/
@Service
public class SecurityAnalysisResultProvider implements ResultProvider {
private final SecurityAnalysisService securityAnalysisService;
private final SecurityAnalysisRestClient securityAnalysisRestClient;

public SecurityAnalysisResultProvider(SecurityAnalysisService securityAnalysisService) {
this.securityAnalysisService = securityAnalysisService;
public SecurityAnalysisResultProvider(SecurityAnalysisRestClient securityAnalysisRestClient) {
this.securityAnalysisRestClient = securityAnalysisRestClient;
}

@Override
Expand All @@ -29,11 +31,11 @@ public ResultType getType() {

@Override
public String getResult(UUID resultId) {
return securityAnalysisService.getResult(resultId);
return securityAnalysisRestClient.getResult(resultId);
}

@Override
public void deleteResult(UUID resultId) {
securityAnalysisService.deleteResult(resultId);
securityAnalysisRestClient.deleteResult(resultId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.external.client;

import org.gridsuite.monitor.server.dto.ReportPage;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -24,7 +24,7 @@
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@Service
public class ReportService {
public class ReportRestClient {
private static final String REPORT_API_VERSION = "v1";

private static final String DELIMITER = "/";
Expand All @@ -33,8 +33,8 @@ public class ReportService {

private final RestTemplate restTemplate;

public ReportService(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri,
RestTemplateBuilder restTemplateBuilder) {
public ReportRestClient(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri,
RestTemplateBuilder restTemplateBuilder) {
this.reportServerBaseUri = reportServerBaseUri;
this.restTemplate = restTemplateBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.external.client;

import lombok.Setter;
import org.slf4j.Logger;
Expand All @@ -23,8 +23,8 @@
* @author Kevin Le Saulnier <kevin.le-saulnier at rte-france.com>
*/
@Service
public class SecurityAnalysisService {
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAnalysisService.class);
public class SecurityAnalysisRestClient {
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAnalysisRestClient.class);
static final String SA_API_VERSION = "v1";
private static final String DELIMITER = "/";

Expand All @@ -37,7 +37,7 @@ private String getSecurityAnalysisServerBaseUri() {
return this.securityAnalysisServerBaseUri + DELIMITER + SA_API_VERSION + DELIMITER;
}

public SecurityAnalysisService(
public SecurityAnalysisRestClient(
RestTemplateBuilder restTemplateBuilder,
@Value("${gridsuite.services.security-analysis-server.base-uri:http://security-analysis-server/}") String securityAnalysisServerBaseUri) {
this.securityAnalysisServerBaseUri = securityAnalysisServerBaseUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.internal;

import org.gridsuite.monitor.commons.ProcessConfig;
import org.gridsuite.monitor.commons.ProcessExecutionStep;
Expand All @@ -18,6 +18,8 @@
import org.gridsuite.monitor.server.mapper.ProcessExecutionMapper;
import org.gridsuite.monitor.server.mapper.ProcessExecutionStepMapper;
import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository;
import org.gridsuite.monitor.server.services.messaging.NotificationService;
import org.gridsuite.monitor.server.services.external.client.ReportRestClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -35,16 +37,16 @@ public class MonitorService {

private final ProcessExecutionRepository executionRepository;
private final NotificationService notificationService;
private final ReportService reportService;
private final ReportRestClient reportRestClient;
private final ResultService resultService;

public MonitorService(ProcessExecutionRepository executionRepository,
NotificationService notificationService,
ReportService reportService,
ReportRestClient reportRestClient,
ResultService resultService) {
this.executionRepository = executionRepository;
this.notificationService = notificationService;
this.reportService = reportService;
this.reportRestClient = reportRestClient;
this.resultService = resultService;
}

Expand Down Expand Up @@ -142,7 +144,7 @@ private ProcessExecutionStepEntity toStepEntity(ProcessExecutionStep processExec
public List<ReportPage> getReports(UUID executionId) {
List<UUID> reportIds = getReportIds(executionId);
return reportIds.stream()
.map(reportService::getReport)
.map(reportRestClient::getReport)
.toList();
}

Expand Down Expand Up @@ -206,7 +208,7 @@ public boolean deleteExecution(UUID executionId) {
}
});
resultIds.forEach(resultService::deleteResult);
reportIds.forEach(reportService::deleteReport);
reportIds.forEach(reportRestClient::deleteReport);

executionRepository.deleteById(executionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.internal;

import org.gridsuite.monitor.commons.ResultType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.internal;

import org.gridsuite.monitor.commons.ResultInfos;
import org.gridsuite.monitor.commons.ResultType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.messaging;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.gridsuite.monitor.commons.MessageType;
import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate;
import org.gridsuite.monitor.commons.ProcessExecutionStep;
import org.gridsuite.monitor.server.services.internal.MonitorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.messaging;

import lombok.RequiredArgsConstructor;
import org.gridsuite.monitor.commons.ProcessConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import org.gridsuite.monitor.server.entities.ProcessExecutionEntity;
import org.gridsuite.monitor.server.repositories.ProcessConfigRepository;
import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository;
import org.gridsuite.monitor.server.services.ConsumerService;
import org.gridsuite.monitor.server.services.messaging.ConsumerService;
import org.gridsuite.monitor.server.services.ProcessConfigService;
import org.gridsuite.monitor.server.services.ReportService;
import org.gridsuite.monitor.server.services.MonitorService;
import org.gridsuite.monitor.server.services.ResultService;
import org.gridsuite.monitor.server.services.external.client.ReportRestClient;
import org.gridsuite.monitor.server.services.internal.MonitorService;
import org.gridsuite.monitor.server.services.internal.ResultService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -78,7 +78,7 @@ class MonitorIntegrationTest {
private MockMvc mockMvc;

@MockitoBean
private ReportService reportService;
private ReportRestClient reportRestClient;

@MockitoBean
private ResultService resultService;
Expand Down Expand Up @@ -183,8 +183,8 @@ void securityAnalysisProcessIT() throws Exception {
new ReportLog("message2", Severity.WARN, 2, UUID.randomUUID())), 100, 10);
ReportPage reportPage1 = new ReportPage(2, List.of(new ReportLog("message3", Severity.ERROR, 3, UUID.randomUUID())), 200, 20);

when(reportService.getReport(reportId0)).thenReturn(reportPage0);
when(reportService.getReport(reportId1)).thenReturn(reportPage1);
when(reportRestClient.getReport(reportId0)).thenReturn(reportPage0);
when(reportRestClient.getReport(reportId1)).thenReturn(reportPage1);

// Test the reports endpoint fetches correctly from database
mockMvc.perform(get("/v1/executions/{executionId}/reports", executionId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.gridsuite.monitor.server.dto.ReportLog;
import org.gridsuite.monitor.server.dto.ReportPage;
import org.gridsuite.monitor.server.dto.Severity;
import org.gridsuite.monitor.server.services.MonitorService;
import org.gridsuite.monitor.server.services.internal.MonitorService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.external.adapter;

import org.gridsuite.monitor.commons.ResultType;
import org.gridsuite.monitor.server.services.external.client.SecurityAnalysisRestClient;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

Expand All @@ -19,11 +20,11 @@
* @author Kevin Le Saulnier <kevin.le-saulnier at rte-france.com>
*/
class SecurityAnalysisResultProviderTest {
private final SecurityAnalysisService securityAnalysisService =
Mockito.mock(SecurityAnalysisService.class);
private final SecurityAnalysisRestClient securityAnalysisRestClient =
Mockito.mock(SecurityAnalysisRestClient.class);

private final SecurityAnalysisResultProvider provider =
new SecurityAnalysisResultProvider(securityAnalysisService);
new SecurityAnalysisResultProvider(securityAnalysisRestClient);

@Test
void getTypeShouldReturnSecurityAnalysis() {
Expand All @@ -36,24 +37,24 @@ void getResultShouldDelegateToSecurityAnalysisService() {
UUID id = UUID.randomUUID();
String expected = "result";

when(securityAnalysisService.getResult(id)).thenReturn(expected);
when(securityAnalysisRestClient.getResult(id)).thenReturn(expected);

String result = provider.getResult(id);

assertThat(result).isEqualTo(expected);
verify(securityAnalysisService).getResult(id);
verifyNoMoreInteractions(securityAnalysisService);
verify(securityAnalysisRestClient).getResult(id);
verifyNoMoreInteractions(securityAnalysisRestClient);
}

@Test
void deleteResultShouldDelegateToSecurityAnalysisService() {
UUID id = UUID.randomUUID();

doNothing().when(securityAnalysisService).deleteResult(id);
doNothing().when(securityAnalysisRestClient).deleteResult(id);

provider.deleteResult(id);

verify(securityAnalysisService).deleteResult(id);
verifyNoMoreInteractions(securityAnalysisService);
verify(securityAnalysisRestClient).deleteResult(id);
verifyNoMoreInteractions(securityAnalysisRestClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 org.gridsuite.monitor.server.services;
package org.gridsuite.monitor.server.services.external.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -32,11 +32,11 @@
/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@RestClientTest(ReportService.class)
@ContextConfiguration(classes = {ReportService.class})
class ReportServiceTest {
@RestClientTest(ReportRestClient.class)
@ContextConfiguration(classes = {ReportRestClient.class})
class ReportRestClientTest {
@Autowired
private ReportService reportService;
private ReportRestClient reportRestClient;

@Autowired
private MockRestServiceServer server;
Expand All @@ -58,7 +58,7 @@ void getReport() throws JsonProcessingException {
.contentType(MediaType.APPLICATION_JSON)
.body(objectMapper.writeValueAsString(reportPage)));

ReportPage reportResult = reportService.getReport(reportId);
ReportPage reportResult = reportRestClient.getReport(reportId);
assertThat(reportResult).usingRecursiveComparison().isEqualTo(reportPage);
}

Expand All @@ -70,7 +70,7 @@ void getReportFailed() {
.andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + reportId + "/logs"))
.andRespond(MockRestResponseCreators.withServerError());

assertThatThrownBy(() -> reportService.getReport(reportId)).isInstanceOf(RestClientException.class);
assertThatThrownBy(() -> reportRestClient.getReport(reportId)).isInstanceOf(RestClientException.class);
}

@Test
Expand All @@ -81,7 +81,7 @@ void deleteReport() {
.andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + reportId))
.andRespond(MockRestResponseCreators.withSuccess());

assertThatNoException().isThrownBy(() -> reportService.deleteReport(reportId));
assertThatNoException().isThrownBy(() -> reportRestClient.deleteReport(reportId));
}

@Test
Expand All @@ -92,6 +92,6 @@ void deleteReportFailed() {
.andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + reportId))
.andRespond(MockRestResponseCreators.withServerError());

assertThatThrownBy(() -> reportService.deleteReport(reportId)).isInstanceOf(RestClientException.class);
assertThatThrownBy(() -> reportRestClient.deleteReport(reportId)).isInstanceOf(RestClientException.class);
}
}
Loading