Search in sources :

Example 1 with NacosDataSourceFactoryBean

use of com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean 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 NacosDataSourceFactoryBean

use of com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean 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)

Aggregations

SentinelConverter (com.alibaba.cloud.sentinel.datasource.converter.SentinelConverter)2 NacosDataSourceFactoryBean (com.alibaba.cloud.sentinel.datasource.factorybean.NacosDataSourceFactoryBean)2 Converter (com.alibaba.csp.sentinel.datasource.Converter)2 NacosDataSource (com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource)2 Test (org.junit.Test)2