Skip to content

Commit

Permalink
Changes related to refactoring and fixing ITs. (#442)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
shantyk authored Sep 17, 2024
1 parent 2c0e243 commit 52d6ed4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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 ##

Expand All @@ -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).

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,19 +42,18 @@ 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();
NotificationService notificationService = blackDuckServicesFactory.createNotificationService();
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);
Expand All @@ -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<String> expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName, "CREATE" + projectVersion2Name, "DELETE" + projectName, "DELETE" + projectVersion2Name));
// one project version create
Set<String> expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName));

Set<String> foundKeys = new HashSet<>();
long start = System.currentTimeMillis();
Expand All @@ -83,12 +76,7 @@ public void testProjectNotifications() throws IntegrationException, InterruptedE
NotificationEditor notificationEditor = new NotificationEditor(startDate, endDate, notificationTypes);
List<NotificationUserView> 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());
Expand All @@ -100,6 +88,9 @@ public void testProjectNotifications() throws IntegrationException, InterruptedE
}

assertEquals(expectedKeys, foundKeys);

// CLEAN UP
blackDuckApiClient.delete(projectVersionWrapper.getProjectView());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 52d6ed4

Please sign in to comment.