Search in sources :

Example 56 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckComponentPolicyDetailsCreatorTest method toComponentPolicyTest.

@Test
public void toComponentPolicyTest() throws IntegrationException {
    String policyName = "alert-test-policy-01";
    PolicyRuleSeverityType severity = PolicyRuleSeverityType.MAJOR;
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    BlackDuckComponentPolicyDetailsCreator policyDetailsCreator = new BlackDuckComponentPolicyDetailsCreator(POLICY_SEVERITY_CONVERTER, blackDuckApiClient);
    ComponentPolicyRulesView componentPolicyRulesView = new ComponentPolicyRulesView();
    componentPolicyRulesView.setName(policyName);
    componentPolicyRulesView.setSeverity(severity);
    componentPolicyRulesView.setPolicyApprovalStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(new HttpUrl("https://someUrl"));
    componentPolicyRulesView.setMeta(meta);
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(componentPolicyRulesView.getName());
    policyRuleView.setCategory(PolicyRuleCategoryType.UNCATEGORIZED);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.any())).thenReturn(policyRuleView);
    ComponentPolicy componentPolicy = policyDetailsCreator.toComponentPolicy(componentPolicyRulesView);
    assertEquals(policyName, componentPolicy.getPolicyName());
    assertEquals(severity.name(), componentPolicy.getSeverity().getPolicyLabel());
    assertFalse(componentPolicy.isVulnerabilityPolicy(), "Did not expect a vulnerability policy");
    assertFalse(componentPolicy.isOverridden(), "Did not expect the policy to be overridden");
    assertTrue(componentPolicy.getCategory().isPresent());
    assertEquals(PolicyRuleCategoryType.UNCATEGORIZED.name(), componentPolicy.getCategory().get());
}
Also used : BlackDuckComponentPolicyDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreator) ComponentPolicyRulesView(com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView) PolicyRuleSeverityType(com.synopsys.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType) ComponentPolicy(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test)

Example 57 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckComponentPolicyDetailsCreatorTest method toComponentPolicyOverriddenTest.

@Test
public void toComponentPolicyOverriddenTest() throws IntegrationException {
    PolicyRuleExpressionExpressionsView expression = new PolicyRuleExpressionExpressionsView();
    expression.setName(EXAMPLE_VULNERABILITY_EXPRESSION);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    PolicyRuleExpressionView policyRuleExpression = new PolicyRuleExpressionView();
    policyRuleExpression.setExpressions(List.of(expression));
    BlackDuckComponentPolicyDetailsCreator policyDetailsCreator = new BlackDuckComponentPolicyDetailsCreator(POLICY_SEVERITY_CONVERTER, blackDuckApiClient);
    ComponentPolicyRulesView componentPolicyRulesView = new ComponentPolicyRulesView();
    componentPolicyRulesView.setName("override-test-policy");
    componentPolicyRulesView.setSeverity(PolicyRuleSeverityType.TRIVIAL);
    componentPolicyRulesView.setPolicyApprovalStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION_OVERRIDDEN);
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(new HttpUrl("https://someUrl"));
    componentPolicyRulesView.setMeta(meta);
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setName(componentPolicyRulesView.getName());
    policyRuleView.setCategory(PolicyRuleCategoryType.UNCATEGORIZED);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.any())).thenReturn(policyRuleView);
    ComponentPolicy componentPolicy = policyDetailsCreator.toComponentPolicy(componentPolicyRulesView);
    assertTrue(componentPolicy.isOverridden(), "Expected the policy to be overridden");
}
Also used : PolicyRuleExpressionView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView) BlackDuckComponentPolicyDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreator) ComponentPolicyRulesView(com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView) ComponentPolicy(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy) PolicyRuleExpressionExpressionsView(com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionExpressionsView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test)

Example 58 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckMessageComponentVersionUpgradeGuidanceServiceTest method requestUpgradeGuidanceItemsBomTest.

@Test
public void requestUpgradeGuidanceItemsBomTest() throws IntegrationException {
    HttpUrl httpUrl = new HttpUrl("https://fake-url");
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> expectedUrl = new UrlSingleResponse<>(httpUrl, ComponentVersionUpgradeGuidanceView.class);
    ComponentVersionUpgradeGuidanceView upgradeGuidanceView = createUpgradeGuidance(true);
    BlackDuckApiClient blackDuckApiClient = createBlackDuckApiClient(expectedUrl, upgradeGuidanceView);
    LinkSingleResponse<ComponentVersionUpgradeGuidanceView> upgradeGuidanceLink = new LinkSingleResponse<>("upgrade-guidance", ComponentVersionUpgradeGuidanceView.class);
    ProjectVersionComponentVersionView bomComponent = createBomComponent(upgradeGuidanceLink, expectedUrl);
    BlackDuckMessageComponentVersionUpgradeGuidanceService upgradeGuidanceService = new BlackDuckMessageComponentVersionUpgradeGuidanceService(blackDuckApiClient);
    ComponentUpgradeGuidance componentUpgradeGuidance = upgradeGuidanceService.requestUpgradeGuidanceItems(bomComponent);
    assertTrue(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertTrue(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) LinkSingleResponse(com.synopsys.integration.blackduck.api.core.response.LinkSingleResponse) HttpUrl(com.synopsys.integration.rest.HttpUrl) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 59 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckMessageLinkUtilsTest method createComponentQueryLinkTest.

@Test
public void createComponentQueryLinkTest() throws IntegrationException {
    String componentName = "An Example Component";
    String encodedComponentName = componentName.replace(" ", "%20");
    String componentsUrl = EXAMPLE_BLACKDUCK_PROJECT_VERSION_URL + BlackDuckMessageLinkUtils.URI_PIECE_COMPONENTS;
    String expectedUrl = String.format("%s?q=%s:%s", componentsUrl, BlackDuckMessageLinkUtils.QUERY_PARAM_COMPONENT_NAME, encodedComponentName);
    String inputUrl = componentsUrl + "/bb9a56d3-8a48-43fd-8db1-5a7529b857f0/versions/9b36b6b4-8221-4071-8685-8c567d68e90e/licenses/7cae335f-1193-421e-92f1-8802b4243e93";
    HttpUrl inputHttpUrl = new HttpUrl(inputUrl);
    ProjectVersionComponentVersionView bomComponent = Mockito.mock(ProjectVersionComponentVersionView.class);
    Mockito.when(bomComponent.getComponentName()).thenReturn(componentName);
    Mockito.when(bomComponent.getHref()).thenReturn(inputHttpUrl);
    String componentQueryLink = BlackDuckMessageLinkUtils.createComponentQueryLink(bomComponent);
    assertEquals(expectedUrl, componentQueryLink);
}
Also used : HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 60 with HttpUrl

use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.

the class BlackDuckSSOConfigRetrieverTest method retrieveExceptionTest.

@Test
public void retrieveExceptionTest() throws IntegrationException {
    HttpUrl baseUrl = new HttpUrl("https://a-blackduck-server");
    ApiDiscovery apiDiscovery = new ApiDiscovery(baseUrl);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(BlackDuckRequest.class))).thenThrow(new AlertException());
    BlackDuckSSOConfigRetriever ssoConfigRetriever = new BlackDuckSSOConfigRetriever(apiDiscovery, blackDuckApiClient);
    try {
        ssoConfigRetriever.retrieve();
        fail(String.format("Expected an %s to be thrown", AlertException.class.getSimpleName()));
    } catch (AlertException e) {
    // Pass
    }
}
Also used : ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckRequest(com.synopsys.integration.blackduck.service.request.BlackDuckRequest) HttpUrl(com.synopsys.integration.rest.HttpUrl) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Aggregations

HttpUrl (com.synopsys.integration.rest.HttpUrl)65 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)35 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)29 Test (org.junit.jupiter.api.Test)28 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)23 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)21 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)18 IntegrationException (com.synopsys.integration.exception.IntegrationException)15 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)15 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)13 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)9 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)9 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)7 ProjectVersionComponentVersionLicensesView (com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView)7 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)6 ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)6 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)6 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)6 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)5