2017-01-23 50 views
0

作爲初學者在編寫junit測試用例時,我不知道如何爲bean加載器類寫junit,有人可以告訴我如何爲我的bean加載器編寫junit,下面是我的一段代碼:Junit for Bean定義類

我的豆裝載機是卡桑德拉屬性:

@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()); 
    } 
} 

回答

0

我也是初學者,但我認爲你搜索什麼(測試配置類)是一個集成測試沒有單元測試?

+0

雅,它是一個集成測試級別,但我需要它在單元測試中完成,任何人都可以幫助我在這 – Jech

+0

任何人都可以幫我解決這個問題 – Jech

相關問題