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());
}
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);
}
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());
}
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);
}
Aggregations