use of com.epam.ta.reportportal.core.analyzer.auto.client.model.cluster.ClusterData in project service-api by reportportal.
the class CreateClusterHandlerImplTest method saveCluster.
@Test
void saveCluster() {
final ClusterData clusterData = new ClusterData();
clusterData.setProject(1L);
clusterData.setLaunchId(1L);
final ClusterInfoRs first = new ClusterInfoRs();
first.setClusterId(1L);
first.setClusterMessage("first");
first.setLogIds(Set.of(1L, 2L));
first.setItemIds(Set.of(1L, 2L));
final ClusterInfoRs second = new ClusterInfoRs();
second.setClusterId(2L);
second.setClusterMessage("second");
second.setLogIds(Set.of(3L, 4L));
second.setItemIds(Set.of(3L, 4L));
clusterData.setClusters(List.of(first, second));
when(clusterRepository.findByIndexIdAndLaunchId(anyLong(), eq(clusterData.getLaunchId()))).thenReturn(Optional.empty());
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
Cluster cluster = ((Cluster) args[0]);
cluster.setId(cluster.getIndexId());
return cluster;
}).when(clusterRepository).save(any(Cluster.class));
createClusterHandler.create(clusterData);
verify(clusterRepository, times(2)).save(any(Cluster.class));
verify(clusterRepository, times(2)).saveClusterTestItems(any(Cluster.class), anySet());
verify(logRepository, times(2)).updateClusterIdByIdIn(any(Long.class), anySet());
}
use of com.epam.ta.reportportal.core.analyzer.auto.client.model.cluster.ClusterData in project service-api by reportportal.
the class AnalyzerClusterDataProviderTest method shouldReturnDataWhenNoIndexLaunch.
@Test
void shouldReturnDataWhenNoIndexLaunch() {
when(analyzerServiceClient.hasClients()).thenReturn(true);
final GenerateClustersConfig config = getConfig(false);
when(launchPreparerService.prepare(config.getLaunchId(), config.getAnalyzerConfig())).thenReturn(Optional.of(new IndexLaunch()));
when(analyzerServiceClient.generateClusters(any(GenerateClustersRq.class))).thenReturn(new ClusterData());
final Optional<ClusterData> data = provider.provide(config);
assertTrue(data.isPresent());
}
use of com.epam.ta.reportportal.core.analyzer.auto.client.model.cluster.ClusterData in project service-api by reportportal.
the class SaveClusterDataPartProviderTest method shouldSaveWhenDataExists.
@Test
void shouldSaveWhenDataExists() {
final GenerateClustersConfig config = getConfig(false);
final ClusterData clusterData = new ClusterData();
when(dataProvider.provide(config)).thenReturn(Optional.of(clusterData));
final PipelinePart pipelinePart = provider.provide(config);
pipelinePart.handle();
verify(createClusterHandler, times(1)).create(clusterData);
}
use of com.epam.ta.reportportal.core.analyzer.auto.client.model.cluster.ClusterData in project service-api by reportportal.
the class CreateClusterHandlerImplTest method updateCluster.
@Test
void updateCluster() {
final ClusterData clusterData = new ClusterData();
clusterData.setProject(1L);
clusterData.setLaunchId(1L);
final ClusterInfoRs first = new ClusterInfoRs();
first.setClusterId(1L);
first.setClusterMessage("first");
first.setLogIds(Set.of(1L, 2L));
first.setItemIds(Set.of(1L, 2L));
final ClusterInfoRs second = new ClusterInfoRs();
second.setClusterId(2L);
second.setClusterMessage("second");
second.setLogIds(Set.of(3L, 4L));
second.setItemIds(Set.of(3L, 4L));
clusterData.setClusters(List.of(first, second));
final Cluster firstCluster = new Cluster();
firstCluster.setIndexId(1L);
final Cluster secondCluster = new Cluster();
secondCluster.setIndexId(2L);
when(clusterRepository.findByIndexIdAndLaunchId(1L, clusterData.getLaunchId())).thenReturn(Optional.of(firstCluster));
when(clusterRepository.findByIndexIdAndLaunchId(2L, clusterData.getLaunchId())).thenReturn(Optional.of(secondCluster));
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
Cluster cluster = ((Cluster) args[0]);
cluster.setId(cluster.getIndexId());
return cluster;
}).when(clusterRepository).save(any(Cluster.class));
createClusterHandler.create(clusterData);
verify(clusterRepository, times(2)).save(any(Cluster.class));
verify(clusterRepository, times(2)).saveClusterTestItems(any(Cluster.class), anySet());
verify(logRepository, times(2)).updateClusterIdByIdIn(any(Long.class), anySet());
}
use of com.epam.ta.reportportal.core.analyzer.auto.client.model.cluster.ClusterData in project service-api by reportportal.
the class AnalyzerClusterDataProviderTest method shouldNotReturnDataWhenNoIndexLaunch.
@Test
void shouldNotReturnDataWhenNoIndexLaunch() {
when(analyzerServiceClient.hasClients()).thenReturn(true);
final GenerateClustersConfig config = getConfig(false);
when(launchPreparerService.prepare(config.getLaunchId(), config.getAnalyzerConfig())).thenReturn(Optional.empty());
final Optional<ClusterData> data = provider.provide(config);
assertTrue(data.isEmpty());
}
Aggregations