Search in sources :

Example 1 with Converter

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);
}
Also used : NacosDataSourceFactoryBean(com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean) NacosDataSource(com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource) SentinelConverter(com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter) Converter(com.alibaba.csp.sentinel.datasource.Converter) Test(org.junit.Test)

Example 2 with Converter

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);
}
Also used : NacosDataSourceFactoryBean(com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean) NacosDataSource(com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource) SentinelConverter(com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter) Converter(com.alibaba.csp.sentinel.datasource.Converter) Test(org.junit.Test)

Example 3 with Converter

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);
}
Also used : ZookeeperDataSource(com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource) Converter(com.alibaba.csp.sentinel.datasource.Converter) XmlConverter(com.alibaba.cloud.sentinel.datasource.converter.XmlConverter) ZookeeperDataSourceFactoryBean(com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean) Test(org.junit.Test)

Example 4 with Converter

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);
}
Also used : ZookeeperDataSource(com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource) Converter(com.alibaba.csp.sentinel.datasource.Converter) XmlConverter(com.alibaba.cloud.sentinel.datasource.converter.XmlConverter) ZookeeperDataSourceFactoryBean(com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean) Test(org.junit.Test)

Example 5 with Converter

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);
}
Also used : JsonConverter(com.alibaba.cloud.sentinel.datasource.converter.JsonConverter) Converter(com.alibaba.csp.sentinel.datasource.Converter) ApolloDataSource(com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource) ApolloDataSourceFactoryBean(com.alibaba.cloud.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean) Test(org.junit.Test)

Aggregations

Converter (com.alibaba.csp.sentinel.datasource.Converter)5 Test (org.junit.Test)5 SentinelConverter (com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter)2 XmlConverter (com.alibaba.cloud.sentinel.datasource.converter.XmlConverter)2 NacosDataSourceFactoryBean (com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean)2 ZookeeperDataSourceFactoryBean (com.alibaba.cloud.sentinel.datasource.factorybean.ZookeeperDataSourceFactoryBean)2 NacosDataSource (com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource)2 ZookeeperDataSource (com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource)2 JsonConverter (com.alibaba.cloud.sentinel.datasource.converter.JsonConverter)1 ApolloDataSourceFactoryBean (com.alibaba.cloud.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean)1 ApolloDataSource (com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource)1