Search in sources :

Example 1 with PolicyRuleSeverityType

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

Aggregations

ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)1 BlackDuckComponentPolicyDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreator)1 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)1 PolicyRuleSeverityType (com.synopsys.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType)1 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)1 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1 Test (org.junit.jupiter.api.Test)1