2016-12-21 2 views
2

Ich bekomme diese Stapel beim Versuch, ein Mock-TestPowerMock AmazonS3Client Config Ausgabe

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 

Ich habe versucht, Vorschläge mit dem org.apache.http.con.ssl.* des Hinzufügens eines @PowerMockIgnore haben mit PowerMock zu laufen, aber tun, dass bewirkt, dass mein Kaninchen-Anschluss zum Scheitern verurteilt . Ich war mir nicht sicher, ob es irgendwelche Vorschläge gibt, die beide für meinen Test laden. Oder nicht initialisieren, wenn es für den Test nicht benötigt wird?

Ich bin begrenzt in was ich bieten kann, da dies etwas für meine Firma ist.

Verwendung von Amazon SDK: 1.11.69

Hier ist, wie ich meine Tests Konfiguration

@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.*" }) 

Beispiel Bean:

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

Stellen Sie bitte ein MCVE zur Verfügung. – Compass

+0

Ich bin begrenzt in was ich bieten kann, da dies etwas für meine Firma ist. –

+2

Bei mir ist dieser Fehler weggefallen, als ich '@PowerMockIgnore ({" javax.net.ssl. * "})' Hinzugefügt habe – srkavin

Antwort

1

Ich konnte dies lösen, indem eine Zugabe Benutzerdefinierte Konfigurationsdatei, die die Bean anspricht und zurückgibt.

@Configuration 
@Profile("Test") 
public class TestConfig { 

    @Mock 
    AmazonS3Client client; 

    public TestConfig(){ 
     MockitoAnnotations.initMocks(this); 
    } 

    @Bean 
    public AmazonS3Client amazonS3Client(){ 
     return client; 
    } 
} 
Verwandte Themen