From 52d6ed4496b5a339674a54fe2cf68313c5b277d8 Mon Sep 17 00:00:00 2001 From: shantyk <121134650+shantyk@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:02:48 -0600 Subject: [PATCH] Changes related to refactoring and fixing ITs. (#442) * Changes related to refactoring and fixing ITs. Initial commit: Some refactoring to enable easier debugging of intermittently failing IT * Update NotificationsTestIT * Remove DELETEs from notification test since they present a race condition. * Trying to clean up the created project versions lead to race condition still, even after notifications are delievered. Changing this test case to only test for one project and version creation. --- README.md | 5 +++- .../comprehensive/NotificationsTestIT.java | 27 +++++++------------ .../http/client/IntHttpClientTestHelper.java | 5 ++++ .../http/client/TestingPropertyKey.java | 3 ++- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b473e1a05..11e4904ea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ ## Overview ## The blackduck-common library supplies convenient communication with a Black Duck server through REST API's as well as providing convenient ways to download the CLI and execute it. -To run integration tests, create a test.properties file under src/test/resources and populate the relevant key-value pairs (See TestingPropertyKey enum for possible keys). ## Build ## @@ -15,3 +14,7 @@ You can download the latest release from Maven Central. ## Documentation ## All documentation for blackduck-common can be found on the base project: https://github.com/blackducksoftware/blackduck-common/wiki + +## Tests ## +To run integration tests, create a test.properties file under src/test/resources and populate the relevant key-value pairs (See TestingPropertyKey enum for possible keys). + diff --git a/src/test/java/com/synopsys/integration/blackduck/comprehensive/NotificationsTestIT.java b/src/test/java/com/synopsys/integration/blackduck/comprehensive/NotificationsTestIT.java index c9920e3c3..27c1d7990 100644 --- a/src/test/java/com/synopsys/integration/blackduck/comprehensive/NotificationsTestIT.java +++ b/src/test/java/com/synopsys/integration/blackduck/comprehensive/NotificationsTestIT.java @@ -10,12 +10,12 @@ import java.util.List; import java.util.Set; +import com.synopsys.integration.log.IntLogger; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import com.synopsys.integration.blackduck.TimingExtension; -import com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery; import com.synopsys.integration.blackduck.api.generated.view.UserView; import com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent; import com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent; @@ -42,11 +42,11 @@ public class NotificationsTestIT { @Test public void testProjectNotifications() throws IntegrationException, InterruptedException { - BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory(); + IntLogger logger = intHttpClientTestHelper.createIntLogger(intHttpClientTestHelper.getTestLogLevel()); + BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory(logger); String projectName = "notifications_test_" + System.currentTimeMillis(); String projectVersionName = "notifications_test_version_" + System.currentTimeMillis(); - String projectVersion2Name = "notifications_test_version2_" + System.currentTimeMillis(); BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient(); ProjectService projectService = blackDuckServicesFactory.createProjectService(); @@ -54,7 +54,6 @@ public void testProjectNotifications() throws IntegrationException, InterruptedE UserService userService = blackDuckServicesFactory.createUserService(); ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName); - ProjectSyncModel projectSyncModel2 = ProjectSyncModel.createWithDefaults(projectName, projectVersion2Name); UserView currentUser = userService.findCurrentUser(); Date startDate = notificationService.getLatestUserNotificationDate(currentUser); @@ -65,15 +64,9 @@ public void testProjectNotifications() throws IntegrationException, InterruptedE // CREATE ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel); - ProjectVersionWrapper projectVersionWrapper2 = projectService.syncProjectAndVersion(projectSyncModel2, true); - // DELETE - blackDuckApiClient.delete(projectVersionWrapper2.getProjectVersionView()); - blackDuckApiClient.delete(projectVersionWrapper.getProjectView()); - - // two project version create - // one project version delete, one project delete - Set expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName, "CREATE" + projectVersion2Name, "DELETE" + projectName, "DELETE" + projectVersion2Name)); + // one project version create + Set expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName)); Set foundKeys = new HashSet<>(); long start = System.currentTimeMillis(); @@ -83,12 +76,7 @@ public void testProjectNotifications() throws IntegrationException, InterruptedE NotificationEditor notificationEditor = new NotificationEditor(startDate, endDate, notificationTypes); List notifications = notificationService.getAllUserNotifications(currentUser, notificationEditor); for (NotificationUserView notificationUserView : notifications) { - if (notificationUserView instanceof ProjectNotificationUserView) { - ProjectNotificationContent content = ((ProjectNotificationUserView) notificationUserView).getContent(); - if (projectName.equals(content.getProjectName())) { - foundKeys.add(content.getOperationType() + content.getProjectName()); - } - } else if (notificationUserView instanceof ProjectVersionNotificationUserView) { + if (notificationUserView instanceof ProjectVersionNotificationUserView) { ProjectVersionNotificationContent content = ((ProjectVersionNotificationUserView) notificationUserView).getContent(); if (projectName.equals(content.getProjectName())) { foundKeys.add(content.getOperationType() + content.getProjectVersionName()); @@ -100,6 +88,9 @@ public void testProjectNotifications() throws IntegrationException, InterruptedE } assertEquals(expectedKeys, foundKeys); + + // CLEAN UP + blackDuckApiClient.delete(projectVersionWrapper.getProjectView()); } } diff --git a/src/test/java/com/synopsys/integration/blackduck/http/client/IntHttpClientTestHelper.java b/src/test/java/com/synopsys/integration/blackduck/http/client/IntHttpClientTestHelper.java index 0caaaddbd..47ac53178 100644 --- a/src/test/java/com/synopsys/integration/blackduck/http/client/IntHttpClientTestHelper.java +++ b/src/test/java/com/synopsys/integration/blackduck/http/client/IntHttpClientTestHelper.java @@ -80,6 +80,11 @@ public BlackDuckServerConfig getBlackDuckServerConfig() { return getBlackDuckServerConfigBuilder().build(); } + public LogLevel getTestLogLevel() { + // defaults to INFO if none or invalid value is provided in test.properties + return LogLevel.fromString(IntHttpClientTestHelper.testProperties.getProperty(TestingPropertyKey.INTEGRATION_TEST_LOG_LEVEL.toString())); + } + public BlackDuckServerConfigBuilder getBlackDuckServerConfigBuilder() { BlackDuckServerConfigBuilder builder; diff --git a/src/test/java/com/synopsys/integration/blackduck/http/client/TestingPropertyKey.java b/src/test/java/com/synopsys/integration/blackduck/http/client/TestingPropertyKey.java index e8d7f46a4..a80c0600e 100644 --- a/src/test/java/com/synopsys/integration/blackduck/http/client/TestingPropertyKey.java +++ b/src/test/java/com/synopsys/integration/blackduck/http/client/TestingPropertyKey.java @@ -51,7 +51,8 @@ public enum TestingPropertyKey { TEST_VULNERABLE_COMPONENT_NAME, TEST_VULNERABLE_COMPONENT_MIN_VULNERABILITIES, TEST_VULNERABLE_COMPONENT_VULNERABILITY_NAME, - LOG_DETAILS_TO_CONSOLE; + LOG_DETAILS_TO_CONSOLE, + INTEGRATION_TEST_LOG_LEVEL; public String fromEnvironment() { return System.getenv(name());