Search in sources :

Example 1 with WorkItemQuery

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());
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.jupiter.api.Test)

Example 2 with WorkItemQuery

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);
}
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 WorkItemQuery

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);
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) WorkItemQueryWhere(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQueryWhere)

Example 4 with WorkItemQuery

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);
}
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 5 with WorkItemQuery

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());
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) Test(org.junit.jupiter.api.Test)

Aggregations

WorkItemQuery (com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery)6 Test (org.junit.jupiter.api.Test)5 AzureBoardsIssueTrackerQueryManager (com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager)2 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)2 WorkItemQueryWhere (com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQueryWhere)1 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1