Skip to content

Commit

Permalink
EPMRPP-89421 || Display number of tests related to each Unique Error …
Browse files Browse the repository at this point in the history
…cluster (#1021)
  • Loading branch information
APiankouski committed Jul 16, 2024
1 parent c771cec commit 823f284
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
if (releaseMode) {
compile 'com.epam.reportportal:commons'
} else {
implementation 'com.github.reportportal:commons:67cbfaea24'
implementation 'com.github.reportportal:commons:9620556'
}

implementation 'org.springframework.security:spring-security-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.epam.ta.reportportal.dao;

import com.epam.reportportal.model.launch.cluster.ClusterInfoResource;
import com.epam.ta.reportportal.entity.cluster.Cluster;
import java.util.Collection;
import java.util.List;
Expand All @@ -42,6 +43,13 @@ public interface ClusterRepository extends ReportPortalRepository<Cluster, Long>

int deleteAllByLaunchId(Long launchId);

@Query(value =
"SELECT new com.epam.reportportal.model.launch.cluster.ClusterInfoResource(c.id, c.indexId as index, c.launchId, c.message, count(cti.itemId) as matchedTests) "
+ "FROM Cluster c LEFT JOIN ClusterTestItem cti ON c.id = cti.clusterId "
+ "WHERE c.launchId = :launchId "
+ "GROUP BY c.id")
Page<ClusterInfoResource> findAllByLaunchIdWithCount(@Param("launchId") Long launchId, Pageable pageable);

@Modifying
@Query(value = "DELETE FROM clusters_test_item WHERE cluster_id IN (SELECT id FROM clusters WHERE project_id = :projectId)", nativeQuery = true)
int deleteClusterTestItemsByProjectId(@Param("projectId") Long projectId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.epam.ta.reportportal.entity.cluster;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* @author <a href="mailto:andrei_piankouski@epam.com">Andrei Piankouski</a>
*/
@Entity
@Table(name = "clusters_test_item", schema = "public")
public class ClusterTestItem {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "item_id")
private Long itemId;

@Column(name = "cluster_id")
private Long clusterId;

public ClusterTestItem() {
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getItemId() {
return itemId;
}

public void setItemId(Long itemId) {
this.itemId = itemId;
}

public Long getCluster() {
return clusterId;
}

public void setCluster(Long clusterId) {
this.clusterId = clusterId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.epam.reportportal.model.launch.cluster.ClusterInfoResource;
import com.epam.ta.reportportal.BaseTest;
import com.epam.ta.reportportal.entity.cluster.Cluster;
import java.util.ArrayList;
Expand Down Expand Up @@ -86,6 +87,15 @@ void shouldFindAllByLaunchId() {
clusters.forEach(cluster -> assertEquals(LAUNCH_ID, cluster.getLaunchId()));
}

@Test
void shouldFindAllByLaunchIdWithCount() {
final Pageable pageable = PageRequest.of(0, 3, Sort.by(Sort.Order.by(CRITERIA_ID)));
final Page<ClusterInfoResource> clusters = clusterRepository.findAllByLaunchIdWithCount(LAUNCH_ID, pageable);
assertFalse(clusters.isEmpty());
assertEquals(3, clusters.getContent().size());
clusters.getContent().forEach(cluster -> assertEquals(LAUNCH_ID, cluster.getLaunchId()));
}

@Test
void shouldFindByLaunchId() {

Expand Down

0 comments on commit 823f284

Please sign in to comment.