PowerMock AmazonS3Client配置问题

时间:2016-12-21 20:09:52

标签: java spring amazon-s3 powermockito

尝试使用PowerMock运行Mock测试时,我得到了这个堆栈

 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.amazonaws.services.s3.AmazonS3Client]: Factory method   'amazonS3Client' threw exception; nested exception is org.apache.http.conn.ssl.SSLInitializationException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
 Caused by: org.apache.http.conn.ssl.SSLInitializationException: class  configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
 Caused by: java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext

我尝试过使用org.apache.http.con.ssl.*添加@PowerMockIgnore的建议,但这样做会导致我的Rabbit连接器失败。我不确定是否有任何建议都加载我的测试。如果测试不需要,可以不初始化一个?

我对我所能提供的内容有限,因为这对我的公司来说很重要。

使用亚马逊SDK:1.11.69

以下是我配置测试的方法

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations={"classpath:applicationContext-test.xml"})
@TestExecutionListeners(listeners={ServletTestExecutionListener.class,
        DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class,
        TransactionalTestExecutionListener.class,
        WithSecurityContextTestExecutionListener.class})
@PrepareForTest({Observable.class,HardDeleteUserCommand.class,SoftDeleteUserCommand.class})
@PowerMockIgnore({ "javax.management.*", "ch.qos.logback.*",
    "org.slf4j.*" })

示例Bean:

@Configuration
@Profile("Test")
public class S3Configuration {
    @Bean
    public AmazonS3Client amazonS3Client() throws IOException {
          return new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
    }
}

2 个答案:

答案 0 :(得分:3)

我能够通过添加一个自定义配置文件来解决这个问题,该文件模拟bean并将其返回。

{{1}}

答案 1 :(得分:1)

正如@srkavin在评论中所说,当我添加@PowerMockIgnore({ "javax.net.ssl.*" })

时,此错误消失了