use of com.alibaba.csp.sentinel.datasource.Converter in project spring-cloud-alibaba by alibaba.
the class NacosDataSourceFactoryBeanTests method testNacosFactoryBeanServerAddr.
@Test
public void testNacosFactoryBeanServerAddr() throws Exception {
NacosDataSourceFactoryBean factoryBean = spy(new NacosDataSourceFactoryBean());
Converter converter = mock(SentinelConverter.class);
factoryBean.setDataId(dataId);
factoryBean.setGroupId(groupId);
factoryBean.setServerAddr(serverAddr);
factoryBean.setContextPath(contextPath);
factoryBean.setConverter(converter);
NacosDataSource nacosDataSource = mock(NacosDataSource.class);
doReturn(nacosDataSource).when(factoryBean).getObject();
when(nacosDataSource.readSource()).thenReturn("{}");
assertThat(factoryBean.getObject()).isEqualTo(nacosDataSource);
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
assertThat(factoryBean.getConverter()).isEqualTo(converter);
assertThat(factoryBean.getDataId()).isEqualTo(dataId);
assertThat(factoryBean.getGroupId()).isEqualTo(groupId);
assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr);
assertThat(factoryBean.getContextPath()).isEqualTo(contextPath);
}
use of com.alibaba.csp.sentinel.datasource.Converter in project spring-cloud-alibaba by alibaba.
the class NacosDataSourceFactoryBeanTests method testNacosFactoryBeanProperties.
@Test
public void testNacosFactoryBeanProperties() throws Exception {
NacosDataSourceFactoryBean factoryBean = spy(new NacosDataSourceFactoryBean());
Converter converter = mock(SentinelConverter.class);
factoryBean.setDataId(dataId);
factoryBean.setGroupId(groupId);
factoryBean.setAccessKey(accessKey);
factoryBean.setSecretKey(secretKey);
factoryBean.setEndpoint(endpoint);
factoryBean.setNamespace(namespace);
factoryBean.setConverter(converter);
NacosDataSource nacosDataSource = mock(NacosDataSource.class);
doReturn(nacosDataSource).when(factoryBean).getObject();
when(nacosDataSource.readSource()).thenReturn("{}");
assertThat(factoryBean.getObject()).isEqualTo(nacosDataSource);
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
assertThat(factoryBean.getConverter()).isEqualTo(converter);
assertThat(factoryBean.getDataId()).isEqualTo(dataId);
assertThat(factoryBean.getGroupId()).isEqualTo(groupId);
assertThat(factoryBean.getNamespace()).isEqualTo(namespace);
assertThat(factoryBean.getEndpoint()).isEqualTo(endpoint);
assertThat(factoryBean.getAccessKey()).isEqualTo(accessKey);
assertThat(factoryBean.getSecretKey()).isEqualTo(secretKey);
}
use of com.alibaba.csp.sentinel.datasource.Converter in project spring-cloud-alibaba by alibaba.
the class ZookeeperDataSourceFactoryBeanTests method testZKWithPathFactoryBean.
@Test
public void testZKWithPathFactoryBean() throws Exception {
ZookeeperDataSourceFactoryBean factoryBean = spy(ZookeeperDataSourceFactoryBean.class);
Converter converter = mock(XmlConverter.class);
ZookeeperDataSource zookeeperDataSource = mock(ZookeeperDataSource.class);
factoryBean.setConverter(converter);
factoryBean.setPath(path);
factoryBean.setServerAddr(serverAddr);
when(zookeeperDataSource.readSource()).thenReturn("{}");
doReturn(zookeeperDataSource).when(factoryBean).getObject();
assertThat(factoryBean.getObject()).isEqualTo(zookeeperDataSource);
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
assertThat(factoryBean.getConverter()).isEqualTo(converter);
assertThat(factoryBean.getPath()).isEqualTo(path);
assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr);
}
use of com.alibaba.csp.sentinel.datasource.Converter in project spring-cloud-alibaba by alibaba.
the class ZookeeperDataSourceFactoryBeanTests method testZKWithoutPathFactoryBean.
@Test
public void testZKWithoutPathFactoryBean() throws Exception {
ZookeeperDataSourceFactoryBean factoryBean = spy(ZookeeperDataSourceFactoryBean.class);
Converter converter = mock(XmlConverter.class);
ZookeeperDataSource zookeeperDataSource = mock(ZookeeperDataSource.class);
factoryBean.setConverter(converter);
factoryBean.setDataId(dataId);
factoryBean.setGroupId(groupId);
factoryBean.setServerAddr(serverAddr);
when(zookeeperDataSource.readSource()).thenReturn("{}");
doReturn(zookeeperDataSource).when(factoryBean).getObject();
assertThat(factoryBean.getObject()).isEqualTo(zookeeperDataSource);
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
assertThat(factoryBean.getDataId()).isEqualTo(dataId);
assertThat(factoryBean.getConverter()).isEqualTo(converter);
assertThat(factoryBean.getGroupId()).isEqualTo(groupId);
assertThat(factoryBean.getServerAddr()).isEqualTo(serverAddr);
}
use of com.alibaba.csp.sentinel.datasource.Converter in project spring-cloud-alibaba by alibaba.
the class ApolloDataSourceFactoryBeanTests method testApolloFactoryBean.
@Test
public void testApolloFactoryBean() throws Exception {
ApolloDataSourceFactoryBean factoryBean = spy(new ApolloDataSourceFactoryBean());
Converter converter = mock(JsonConverter.class);
factoryBean.setDefaultFlowRuleValue(defaultFlowValue);
factoryBean.setFlowRulesKey(flowRuleKey);
factoryBean.setNamespaceName(namespace);
factoryBean.setConverter(converter);
ApolloDataSource apolloDataSource = mock(ApolloDataSource.class);
when(apolloDataSource.readSource()).thenReturn("{}");
doReturn(apolloDataSource).when(factoryBean).getObject();
assertThat(factoryBean.getObject()).isEqualTo(apolloDataSource);
assertThat(factoryBean.getObject().readSource()).isEqualTo("{}");
assertThat(factoryBean.getConverter()).isEqualTo(converter);
assertThat(factoryBean.getFlowRulesKey()).isEqualTo(flowRuleKey);
assertThat(factoryBean.getNamespaceName()).isEqualTo(namespace);
assertThat(factoryBean.getDefaultFlowRuleValue()).isEqualTo(defaultFlowValue);
}
Aggregations