Search in sources :

Example 1 with AzureBoardsIssueTrackerQueryManager

use of com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager in project hub-alert by blackducksoftware.

the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelForUnknownVersionTest.

@Test
public void findExistingIssuesByProjectIssueModelForUnknownVersionTest() throws AlertException {
    Gson gson = new Gson();
    String organizationName = "orgName";
    AzureBoardsIssueTrackerQueryManager queryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
    AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, "test proj");
    AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
    IssueComponentUnknownVersionDetails componentUnknownVersionDetails = new IssueComponentUnknownVersionDetails(ItemOperation.ADD, createRiskModels());
    IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.componentUnknownVersion(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, componentUnknownVersionDetails);
    WorkItemResponseModel workItemResponseModel = createWorkItemResponseModel(workItemReopenState);
    Mockito.when(queryManager.executeQueryAndRetrieveWorkItems(Mockito.any())).thenReturn(List.of(workItemResponseModel));
    List<ExistingIssueDetails<Integer>> existingIssueDetailsList = componentIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    assertEquals(1, existingIssueDetailsList.size());
    ExistingIssueDetails<Integer> existingIssueDetails = existingIssueDetailsList.get(0);
    assertEquals(IssueStatus.RESOLVABLE, existingIssueDetails.getIssueStatus());
    assertEquals(IssueCategory.BOM, existingIssueDetails.getIssueCategory());
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Gson(com.google.gson.Gson) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) Test(org.junit.jupiter.api.Test)

Example 2 with AzureBoardsIssueTrackerQueryManager

use of com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager in project hub-alert by blackducksoftware.

the class AzureBoardsWorkItemFinderTest method verifyQueryWhereStatementTruncated.

@Test
public void verifyQueryWhereStatementTruncated() throws AlertException {
    AzureBoardsIssueTrackerQueryManager azureBoardsIssueTrackerQueryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    ArgumentCaptor<WorkItemQuery> workItemQueryArgumentCaptor = ArgumentCaptor.forClass(WorkItemQuery.class);
    String teamProjectName = "team project name";
    AzureBoardsWorkItemFinder azureBoardsWorkItemFinder = new AzureBoardsWorkItemFinder(azureBoardsIssueTrackerQueryManager, teamProjectName);
    LinkableItem provider = new LinkableItem("providerLabel", "providerValue");
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    String componentKey = StringUtils.repeat("componentKey", 100);
    String subTopicKey = "subTopicKey";
    String additionalInfoKey = "additionalInfoKey";
    AzureSearchFieldMappingBuilder azureSearchFieldMappingBuilder = AzureSearchFieldMappingBuilder.create().addComponentKey(componentKey).addSubTopic(subTopicKey).addAdditionalInfoKey(additionalInfoKey);
    Mockito.doReturn(List.of()).when(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(Mockito.any());
    azureBoardsWorkItemFinder.findWorkItems(provider, project, azureSearchFieldMappingBuilder);
    Mockito.verify(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(workItemQueryArgumentCaptor.capture());
    WorkItemQuery workItemQuery = workItemQueryArgumentCaptor.getValue();
    assertNotNull(workItemQuery);
    assertFalse(workItemQuery.exceedsCharLimit());
    Map<String, String> whereClauseValues = extractValuesFromWhereClause(workItemQuery.rawQuery());
    assertTrue(whereClauseValues.size() > 3);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfoKey);
    String component = whereClauseValues.get(AzureCustomFieldManager.ALERT_COMPONENT_KEY_FIELD_REFERENCE_NAME);
    assertNotNull(component);
    // This is Azure boards custom field size limit
    String truncatedComponent = StringUtils.truncate(componentKey, 256);
    assertEquals(truncatedComponent, component);
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Test(org.junit.jupiter.api.Test)

Example 3 with AzureBoardsIssueTrackerQueryManager

use of com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager in project hub-alert by blackducksoftware.

the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelTest.

@Test
public void findExistingIssuesByProjectIssueModelTest() throws AlertException {
    Gson gson = new Gson();
    String organizationName = "orgName";
    AzureBoardsIssueTrackerQueryManager queryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
    AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, "test proj");
    AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
    IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, testPolicy);
    WorkItemResponseModel workItemResponseModel = createWorkItemResponseModel(workItemReopenState);
    Mockito.when(queryManager.executeQueryAndRetrieveWorkItems(Mockito.any())).thenReturn(List.of(workItemResponseModel));
    List<ExistingIssueDetails<Integer>> existingIssueDetailsList = componentIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    assertEquals(1, existingIssueDetailsList.size());
    ExistingIssueDetails<Integer> existingIssueDetails = existingIssueDetailsList.get(0);
    assertEquals(IssueStatus.RESOLVABLE, existingIssueDetails.getIssueStatus());
    assertEquals(IssueCategory.POLICY, existingIssueDetails.getIssueCategory());
}
Also used : AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Gson(com.google.gson.Gson) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) WorkItemResponseModel(com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel) IssueCategoryRetriever(com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever) Test(org.junit.jupiter.api.Test)

Example 4 with AzureBoardsIssueTrackerQueryManager

use of com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager in project hub-alert by blackducksoftware.

the class AzureBoardsWorkItemFinderTest method verifyQueryWhereStatementExists.

@Test
public void verifyQueryWhereStatementExists() throws AlertException {
    AzureBoardsIssueTrackerQueryManager azureBoardsIssueTrackerQueryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    ArgumentCaptor<WorkItemQuery> workItemQueryArgumentCaptor = ArgumentCaptor.forClass(WorkItemQuery.class);
    String teamProjectName = "team project name";
    AzureBoardsWorkItemFinder azureBoardsWorkItemFinder = new AzureBoardsWorkItemFinder(azureBoardsIssueTrackerQueryManager, teamProjectName);
    LinkableItem provider = new LinkableItem("providerLabel", "providerValue");
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    String componentKey = "componentKey";
    String subTopicKey = "subTopicKey";
    String additionalInfoKey = "additionalInfoKey";
    AzureSearchFieldMappingBuilder azureSearchFieldMappingBuilder = AzureSearchFieldMappingBuilder.create().addComponentKey(componentKey).addSubTopic(subTopicKey).addAdditionalInfoKey(additionalInfoKey);
    Mockito.doReturn(List.of()).when(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(Mockito.any());
    azureBoardsWorkItemFinder.findWorkItems(provider, project, azureSearchFieldMappingBuilder);
    Mockito.verify(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(workItemQueryArgumentCaptor.capture());
    WorkItemQuery workItemQuery = workItemQueryArgumentCaptor.getValue();
    assertNotNull(workItemQuery);
    assertFalse(workItemQuery.exceedsCharLimit());
    Map<String, String> whereClauseValues = extractValuesFromWhereClause(workItemQuery.rawQuery());
    assertTrue(whereClauseValues.size() > 3);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfoKey);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_COMPONENT_KEY_FIELD_REFERENCE_NAME, componentKey);
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Test(org.junit.jupiter.api.Test)

Aggregations

AzureBoardsIssueTrackerQueryManager (com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager)4 Test (org.junit.jupiter.api.Test)4 Gson (com.google.gson.Gson)2 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)2 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)2 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)2 WorkItemQuery (com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery)2 WorkItemResponseModel (com.synopsys.integration.azure.boards.common.service.workitem.response.WorkItemResponseModel)2 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)1