use of com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery in project hub-alert by blackducksoftware.
the class WorkItemQueryTest method toStringTest.
@Test
public void toStringTest() {
LocalDate asOfDate = LocalDate.of(2020, 1, 1);
DateTimeFormatter asOfDateFormat = DateTimeFormatter.ofPattern("MM/dd/yyyy");
String expectedQueryString = "SELECT [Field] FROM WorkItems WHERE [Field] = 'a value' ORDER BY [Field] ASOF " + asOfDateFormat.format(asOfDate);
WorkItemQuery workItemQuery = WorkItemQuery.select("Field").fromWorkItems().where("Field", WorkItemQueryWhereOperator.EQ, "a value").orderBy("Field").asOf(asOfDate);
assertEquals(expectedQueryString, workItemQuery.toString());
}
use of com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery 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.azure.boards.common.service.query.fluent.WorkItemQuery in project hub-alert by blackducksoftware.
the class AzureBoardsWorkItemFinder method findWorkItems.
public List<WorkItemResponseModel> findWorkItems(LinkableItem provider, LinkableItem project, AzureSearchFieldMappingBuilder fieldReferenceNameToExpectedValue) throws AlertException {
String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
String topicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(project);
String systemIdFieldName = WorkItemResponseFields.System_Id.getFieldName();
String teamProjectFieldName = WorkItemResponseFields.System_TeamProject.getFieldName();
WorkItemQueryWhere queryBuilder = WorkItemQuery.select(systemIdFieldName).fromWorkItems().whereGroup(teamProjectFieldName, WorkItemQueryWhereOperator.EQ, teamProjectName).and(AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, WorkItemQueryWhereOperator.EQ, providerKey).and(AzureCustomFieldManager.ALERT_TOPIC_KEY_FIELD_REFERENCE_NAME, WorkItemQueryWhereOperator.EQ, topicKey);
for (AzureSearchFieldMappingBuilder.ReferenceToValue refToValue : fieldReferenceNameToExpectedValue.buildAsList()) {
queryBuilder = queryBuilder.and(refToValue.getReferenceKey(), WorkItemQueryWhereOperator.EQ, refToValue.getFieldValue());
}
WorkItemQuery query = queryBuilder.orderBy(systemIdFieldName).build();
return queryManager.executeQueryAndRetrieveWorkItems(query);
}
use of com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery 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);
}
use of com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery in project hub-alert by blackducksoftware.
the class WorkItemQueryTest method whereGroupTest.
@Test
public void whereGroupTest() {
String expectedQueryString = "SELECT [Field] FROM WorkItems WHERE ( [Field] = 'a value' OR [Other Field] Contains 'something else' ) ORDER BY [Other Field]";
WorkItemQuery workItemQuery = WorkItemQuery.select("Field").fromWorkItems().whereGroup("Field", WorkItemQueryWhereOperator.EQ, "a value").or("Other Field", WorkItemQueryWhereOperator.CONTAINS, "something else").orderBy("Other Field").build();
assertEquals(expectedQueryString, workItemQuery.toString());
}
Aggregations