use of org.springframework.core.convert.support.DefaultConversionService in project dubbo by alibaba.
the class AnnotationPropertyValuesAdapterTest method test.
@Test
public void test() {
MockEnvironment mockEnvironment = new MockEnvironment();
mockEnvironment.setProperty("version", "1.0.0");
mockEnvironment.setProperty("url", " dubbo://localhost:12345");
Field field = ReflectionUtils.findField(TestBean.class, "demoService");
Reference reference = AnnotationUtils.getAnnotation(field, Reference.class);
AnnotationPropertyValuesAdapter propertyValues = new AnnotationPropertyValuesAdapter(reference, mockEnvironment);
ReferenceBean referenceBean = new ReferenceBean();
DataBinder dataBinder = new DataBinder(referenceBean);
dataBinder.setDisallowedFields("application", "module", "consumer", "monitor", "registry");
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<String[], String>() {
@Override
public String convert(String[] source) {
return arrayToCommaDelimitedString(source);
}
});
conversionService.addConverter(new Converter<String[], Map<String, String>>() {
@Override
public Map<String, String> convert(String[] source) {
return CollectionUtils.toStringMap(source);
}
});
dataBinder.setConversionService(conversionService);
dataBinder.bind(propertyValues);
// System.out.println(referenceBean);
Assertions.assertEquals(DemoService.class, referenceBean.getInterfaceClass());
Assertions.assertEquals("org.apache.dubbo.config.spring.api.DemoService", referenceBean.getInterface());
Assertions.assertEquals("1.0.0", referenceBean.getVersion());
Assertions.assertEquals("group", referenceBean.getGroup());
Assertions.assertEquals("dubbo://localhost:12345", referenceBean.getUrl());
Assertions.assertEquals("client", referenceBean.getClient());
Assertions.assertEquals(true, referenceBean.isGeneric());
Assertions.assertNull(referenceBean.isInjvm());
Assertions.assertEquals(false, referenceBean.isCheck());
Assertions.assertEquals(true, referenceBean.isInit());
Assertions.assertEquals(true, referenceBean.getLazy());
Assertions.assertEquals(true, referenceBean.getStubevent());
Assertions.assertEquals("reconnect", referenceBean.getReconnect());
Assertions.assertEquals(true, referenceBean.getSticky());
Assertions.assertEquals("javassist", referenceBean.getProxy());
Assertions.assertEquals("stub", referenceBean.getStub());
Assertions.assertEquals("failover", referenceBean.getCluster());
Assertions.assertEquals(Integer.valueOf(1), referenceBean.getConnections());
Assertions.assertEquals(Integer.valueOf(1), referenceBean.getCallbacks());
Assertions.assertEquals("onconnect", referenceBean.getOnconnect());
Assertions.assertEquals("ondisconnect", referenceBean.getOndisconnect());
Assertions.assertEquals("owner", referenceBean.getOwner());
Assertions.assertEquals("layer", referenceBean.getLayer());
Assertions.assertEquals(Integer.valueOf(1), referenceBean.getRetries());
Assertions.assertEquals("random", referenceBean.getLoadbalance());
Assertions.assertEquals(true, referenceBean.isAsync());
Assertions.assertEquals(Integer.valueOf(1), referenceBean.getActives());
Assertions.assertEquals(true, referenceBean.getSent());
Assertions.assertEquals("mock", referenceBean.getMock());
Assertions.assertEquals("validation", referenceBean.getValidation());
Assertions.assertEquals(Integer.valueOf(2), referenceBean.getTimeout());
Assertions.assertEquals("cache", referenceBean.getCache());
Assertions.assertEquals("default,default", referenceBean.getFilter());
Assertions.assertEquals("default,default", referenceBean.getListener());
Map<String, String> data = new LinkedHashMap<String, String>();
data.put("key1", "value1");
Assertions.assertEquals(data, referenceBean.getParameters());
// Bean compare
Assertions.assertNull(referenceBean.getRegistry());
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.
the class MapBinderTests method bindToMapWithCustomConverterAndChildElements.
@Test
void bindToMapWithCustomConverterAndChildElements() {
// gh-11892
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new MapConverter());
Binder binder = new Binder(this.sources, null, conversionService, null);
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo", "boom");
source.put("foo.a", "a");
source.put("foo.b", "b");
this.sources.add(source);
Map<String, String> map = binder.bind("foo", STRING_STRING_MAP).get();
assertThat(map.get("a")).isEqualTo("a");
assertThat(map.get("b")).isEqualTo("b");
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.
the class IsoOffsetDateTimeConverterTests method registerConverterShouldRegister.
@Test
void registerConverterShouldRegister() {
DefaultConversionService service = new DefaultConversionService();
IsoOffsetDateTimeConverter.registerConverter(service);
OffsetDateTime time = service.convert("2011-12-03T10:15:30+01:00", OffsetDateTime.class);
assertThat(time).isNotNull();
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.
the class ConversionServiceParameterValueMapperTests method createWithConversionServiceShouldNotRegisterIsoOffsetDateTimeConverter.
@Test
void createWithConversionServiceShouldNotRegisterIsoOffsetDateTimeConverter() {
ConversionService conversionService = new DefaultConversionService();
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(conversionService);
assertThatExceptionOfType(ParameterMappingException.class).isThrownBy(() -> mapper.mapParameterValue(new TestOperationParameter(OffsetDateTime.class), "2011-12-03T10:15:30+01:00"));
}
use of org.springframework.core.convert.support.DefaultConversionService in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testPagedRequest.
@Test
public void testPagedRequest() {
int totalPages = 2;
int currentPage = 0;
int pageSize = 2;
OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
AlertNotificationModel entity_1 = new AlertNotificationModel(1L, 1L, "provider", "providerConfigName", "notificationType", "{content: \"content is here...\"}", createdAt, createdAt, false);
entity_1.setId(1L);
AlertNotificationModel entity_2 = new AlertNotificationModel(2L, 2L, "provider", "providerConfigName", "notificationType", "{content: \"content is here...\"}", createdAt, createdAt, false);
entity_2.setId(2L);
List<AlertNotificationModel> pagedEntryList = Arrays.asList(entity_1, entity_2);
Page<AlertNotificationModel> pageResponse = Mockito.mock(Page.class);
Mockito.when(pageResponse.getContent()).thenReturn(pagedEntryList);
Mockito.when(pageResponse.getTotalPages()).thenReturn(totalPages);
Mockito.when(pageResponse.getNumber()).thenReturn(currentPage);
Mockito.when(pageResponse.getSize()).thenReturn(pageSize);
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);
Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(null);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
NotificationEntity notificationContent = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{content: \"content is here...\"}", 1L, 1L).createEntity();
ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
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());
assertEquals(pageResponse.getSize(), restModel.getPageSize());
for (int index = 0; index < pageSize; index++) {
AlertNotificationModel entity = pageResponse.getContent().get(index);
AuditEntryModel entryRestModel = restModel.getContent().get(index);
assertEquals(String.valueOf(entity.getId()), entryRestModel.getId());
}
}
Aggregations