Search in sources :

Example 61 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testPagedRequestEmptyList.

@Test
public void testPagedRequestEmptyList() {
    int totalPages = 1;
    int currentPage = 1;
    int pageSize = 1;
    Page<AlertNotificationModel> pageResponse = Mockito.mock(Page.class);
    Mockito.when(pageResponse.getContent()).thenReturn(Collections.emptyList());
    Mockito.when(pageResponse.getTotalPages()).thenReturn(totalPages);
    Mockito.when(pageResponse.getNumber()).thenReturn(currentPage);
    Mockito.when(pageResponse.getSize()).thenReturn(0);
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    AuditDescriptorKey auditDescriptorKey = new AuditDescriptorKey();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    DefaultNotificationAccessor notificationManager = Mockito.mock(DefaultNotificationAccessor.class);
    Mockito.when(notificationManager.findAll(Mockito.any(PageRequest.class), Mockito.anyBoolean())).thenReturn(pageResponse);
    PageRequest pageRequest = PageRequest.of(currentPage, pageSize, Sort.unsorted());
    Mockito.when(notificationManager.getPageRequestForNotifications(Mockito.anyInt(), Mockito.anyInt(), Mockito.any(), Mockito.any())).thenReturn(pageRequest);
    NotificationContentRepository notificationRepository = Mockito.mock(NotificationContentRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
    NotificationEntity notificationContent = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{content: \"content is here...\"}", 1L, 1L).createEntity();
    DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("distributionType").name("name").createdAt(OffsetDateTime.now()).distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of("type")).processingType(ProcessingType.DEFAULT).build();
    Mockito.doReturn(Optional.of(distributionJob)).when(jobAccessor).getJobById(Mockito.any());
    Mockito.when(notificationRepository.findAllById(Mockito.anyList())).thenReturn(Collections.singletonList(notificationContent));
    DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, notificationManager, contentConverter);
    AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationManager, jobAccessor, null, null);
    ActionResponse<AuditEntryPageModel> response = auditEntryActions.get(currentPage, pageSize, null, null, null, true);
    assertTrue(response.hasContent());
    AuditEntryPageModel restModel = response.getContent().orElse(null);
    assertEquals(pageResponse.getTotalPages(), restModel.getTotalPages());
    assertEquals(pageResponse.getNumber(), restModel.getCurrentPage());
    // Assert 0 because there aren't any entries in the pageResponse content
    assertEquals(0, restModel.getPageSize());
    assertTrue(restModel.getContent().isEmpty());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) PageRequest(org.springframework.data.domain.PageRequest) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Example 62 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-data-mongodb by spring-projects.

the class MongoConvertersUnitTests method convertsUrisToString.

// DATAMONGO-2210
@Test
void convertsUrisToString() {
    MongoCustomConversions conversions = new MongoCustomConversions();
    assertThat(conversions.getSimpleTypeHolder().isSimpleType(URI.class)).isTrue();
    ConfigurableConversionService conversionService = new DefaultConversionService();
    conversions.registerConvertersIn(conversionService);
    assertThat(conversionService.convert(URI.create("/segment"), String.class)).isEqualTo("/segment");
    assertThat(conversionService.convert("/segment", URI.class)).isEqualTo(URI.create("/segment"));
}
Also used : ConfigurableConversionService(org.springframework.core.convert.support.ConfigurableConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.jupiter.api.Test)

Example 63 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-data-mongodb by spring-projects.

the class AbstractMongoConverterUnitTests method registersObjectIdConvertersExplicitly.

// DATAMONGO-1324
@Test
public void registersObjectIdConvertersExplicitly() {
    DefaultConversionService conversionService = spy(new DefaultConversionService());
    new SampleMongoConverter(conversionService).afterPropertiesSet();
    verify(conversionService).addConverter(StringToObjectIdConverter.INSTANCE);
    verify(conversionService).addConverter(ObjectIdToStringConverter.INSTANCE);
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.jupiter.api.Test)

Example 64 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-data-jdbc by spring-projects.

the class AggregateReferenceConvertersUnitTests method setUp.

@BeforeEach
void setUp() {
    conversionService = new DefaultConversionService();
    AggregateReferenceConverters.getConvertersToRegister(DefaultConversionService.getSharedInstance()).forEach(it -> conversionService.addConverter(it));
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 65 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-security by spring-projects.

the class BasicLookupStrategyWithAclClassTypeTests method initializeBeans.

@Override
@BeforeEach
public void initializeBeans() {
    super.initializeBeans();
    this.uuidEnabledStrategy = new BasicLookupStrategy(getDataSource(), aclCache(), aclAuthStrategy(), new DefaultPermissionGrantingStrategy(new ConsoleAuditLogger()));
    this.uuidEnabledStrategy.setPermissionFactory(new DefaultPermissionFactory());
    this.uuidEnabledStrategy.setAclClassIdSupported(true);
    this.uuidEnabledStrategy.setConversionService(new DefaultConversionService());
}
Also used : DefaultPermissionGrantingStrategy(org.springframework.security.acls.domain.DefaultPermissionGrantingStrategy) DefaultPermissionFactory(org.springframework.security.acls.domain.DefaultPermissionFactory) ConsoleAuditLogger(org.springframework.security.acls.domain.ConsoleAuditLogger) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)84 Test (org.junit.jupiter.api.Test)37 Test (org.junit.Test)29 ConversionService (org.springframework.core.convert.ConversionService)13 MethodParameter (org.springframework.core.MethodParameter)12 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)12 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)12 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)12 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)11 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 RequestParam (org.springframework.web.bind.annotation.RequestParam)9 Optional (java.util.Optional)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)6 HashMap (java.util.HashMap)5 DefaultDatatypeChannelMessageConverter (org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 Before (org.junit.Before)4 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)3 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3