Junit for Bean Definition类

时间:2017-01-23 13:42:50

标签: java spring junit

由于我是编写junit测试用例的初学者,我不知道将junit写入bean加载器类,有人可以建议我如何为我的bean加载器编写junit,下面是我的代码片段:

我的Bean加载程序属于cassandra属性:

@Configuration
@PropertySource("cassandra.properties")
@EnableCassandraRepositories(basePackages = "...repository")
public class Beanloader {

    @Autowired
    public Environment environment;

    CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();

    @Bean(name = "clusterFactory")
    public CassandraClusterFactoryBean getCluster() {
        PoolingOptions poolingOptions = new PoolingOptions();
        cluster.setContactPoints(environment.getProperty("cassandra.contactpoints"));
        cluster.setPoolingOptions(poolingOptions);
        cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port")));
        poolingOptions.setNewConnectionThreshold(HostDistance.LOCAL, 50);

        return cluster;
    }

    @Bean
    @DependsOn("clusterFactory")
    public CassandraSessionFactoryBean getSession() throws Exception {
        CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
        session.setCluster(cluster.getObject());
        session.setKeyspaceName(environment.getProperty("cassandra.keyspace"));
        session.setConverter(new MappingCassandraConverter(new CassandraMappingContextAware()));
        session.setSchemaAction(SchemaAction.NONE);

        return session;
    }

    @Bean
    public CassandraOperations cassandraTemplate() throws Exception {
        return new CassandraTemplate(getSession().getObject());
    }
}

1 个答案:

答案 0 :(得分:0)

我也是初学者,但我认为您搜索的内容(测试配置类)是集成测试而不是单元测试?