use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckProjectSyncTaskTest method createUserView.
private UserView createUserView(String email, Boolean active) {
UserView userView = new UserView();
userView.setEmail(email);
userView.setActive(active);
return userView;
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method createUserViews.
private Set<UserView> createUserViews() {
String emailAddress1 = "someone@gmail.com";
String emailAddress2 = "someoneelse@gmail.com";
String emailAddress3 = "other@gmail.com";
UserView userView1 = new UserView();
userView1.setActive(true);
userView1.setEmail(emailAddress1);
UserView userView2 = new UserView();
userView2.setActive(true);
userView2.setEmail(emailAddress2);
UserView userView3 = new UserView();
userView3.setActive(true);
userView3.setEmail(emailAddress3);
UserView userView4 = new UserView();
userView4.setActive(false);
userView4.setEmail(emailAddress1);
UserView userView5 = new UserView();
userView5.setActive(true);
userView5.setEmail(emailAddress2);
Set<UserView> userViews = new HashSet<>();
userViews.add(userView1);
userViews.add(userView2);
userViews.add(userView3);
userViews.add(userView4);
userViews.add(userView5);
return userViews;
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method init.
@BeforeEach
void init() throws Exception {
blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
projectService = Mockito.mock(ProjectService.class);
Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
projectUsersService = Mockito.mock(ProjectUsersService.class);
Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
apiDiscovery = Mockito.mock(ApiDiscovery.class);
UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method getEmailAddressesForProjectHrefTest.
@Test
void getEmailAddressesForProjectHrefTest() throws Exception {
Long providerConfigId = providerConfiguration.getConfigurationId();
ProjectView projectView = createProjectView1();
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
Set<UserView> userViews = createUserViews();
Mockito.when(projectUsersService.getAllActiveUsersForProject(Mockito.any(ProjectView.class))).thenReturn(userViews);
BlackDuckProviderDataAccessor providerDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
Set<String> foundEmailAddresses = providerDataAccessor.getEmailAddressesForProjectHref(providerConfigId, HREF_1);
assertEquals(3, foundEmailAddresses.size());
}
use of com.synopsys.integration.blackduck.api.generated.view.UserView in project hub-alert by blackducksoftware.
the class BlackDuckDataSyncTask method getEmailsPerProject.
private Map<ProviderProject, Set<String>> getEmailsPerProject(Map<ProjectView, ProviderProject> blackDuckToAlertProjects, ProjectUsersService projectUsersService) {
Map<ProviderProject, Set<String>> projectToEmailAddresses = new ConcurrentHashMap<>();
blackDuckToAlertProjects.entrySet().parallelStream().forEach(entry -> {
try {
ProjectView blackDuckProjectView = entry.getKey();
ProviderProject alertProject = entry.getValue();
Set<String> projectUserEmailAddresses = projectUsersService.getAllActiveUsersForProject(blackDuckProjectView).stream().filter(UserView::getActive).map(UserView::getEmail).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
if (StringUtils.isNotBlank(alertProject.getProjectOwnerEmail())) {
projectUserEmailAddresses.add(alertProject.getProjectOwnerEmail());
}
projectToEmailAddresses.put(alertProject, projectUserEmailAddresses);
} catch (IntegrationException e) {
// We do this to break out of the stream
throw new AlertRuntimeException(e.getMessage(), e);
}
});
return projectToEmailAddresses;
}
Aggregations