Search in sources :

Example 6 with ComponentPolicyRulesView

use of com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView 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)

Aggregations

ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)6 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)6 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)6 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)6 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)6 HttpUrl (com.synopsys.integration.rest.HttpUrl)6 Test (org.junit.jupiter.api.Test)6 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)3 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)3 BlackDuckComponentPolicyDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreator)3 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)3 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 PolicyRuleExpressionExpressionsView (com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionExpressionsView)2 PolicyRuleExpressionView (com.synopsys.integration.blackduck.api.generated.component.PolicyRuleExpressionView)2 RuleViolationClearedUniquePolicyNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationClearedUniquePolicyNotificationContent)1 RuleViolationUniquePolicyNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationUniquePolicyNotificationContent)1 PolicyRuleSeverityType (com.synopsys.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType)1