use of io.servicecomb.foundation.common.entities.HttpsConfigInfoBean in project java-chassis by ServiceComb.
the class TestHttpsClient method testCreateSSLContext.
@Test
public void testCreateSSLContext() {
final String SSL_VERSION = "TLSv1.2";
String sslVersion = SSL_VERSION;
try {
final SSLContext sslContext = SSLContext.getInstance(sslVersion);
new MockUp<HttpsClient>() {
@Mock
private SSLContext createSSLContext(HttpsConfigInfoBean configBean) throws GeneralSecurityException, IOException {
return sslContext;
}
};
} catch (NoSuchAlgorithmException e) {
Assert.assertTrue(false);
}
HttpsConfigInfoBean oBean = new HttpsConfigInfoBean();
HttpsClient.getHttpsClient(oBean);
Assert.assertNotEquals(null, HttpsClient.getHttpsClient(Mockito.mock(HttpsConfigInfoBean.class)));
}
use of io.servicecomb.foundation.common.entities.HttpsConfigInfoBean in project java-chassis by ServiceComb.
the class TestHttpsClient method testHttpClient.
@Test
public void testHttpClient() throws ClientProtocolException, IOException {
// test valid Invalid Inputs
Map<String, String> oHeaders = new HashMap<String, String>();
oHeaders.put("X-Auth", "JHGUGJGH");
HttpResponse oResponse = HttpsClient.execute("UNKNOWN METHOD", oHeaders, "//check", "body", null);
Assert.assertEquals(null, oResponse);
oResponse = HttpsClient.execute("", oHeaders, "//check", "body", null);
Assert.assertEquals(null, oResponse);
oResponse = HttpsClient.execute("UNKNOWN METHOD", oHeaders, "", "body", null);
Assert.assertEquals(null, oResponse);
oResponse = HttpsClient.execute("UNKNOWN METHOD", null, "//check", "body", null);
Assert.assertEquals(null, oResponse);
// With default Bean
HttpsConfigInfoBean oBean = new HttpsConfigInfoBean();
oBean.setKeyStorePath("JHGJ");
oBean.setKeyStorePasswd("HJGJH");
oBean.setTrustStorePasswd("JHGJHG");
oBean.setTrustStorePath("JHGJGj");
Assert.assertEquals("JHGJGj", oBean.getTrustStorePath());
Assert.assertEquals("JHGJHG", oBean.getTrustStorePasswd());
oResponse = HttpsClient.execute("UNKNOWN METHOD", oHeaders, "//check", "body", oBean);
Assert.assertEquals(null, oResponse);
HttpsClient.getHttpsClient(oBean);
Assert.assertNotEquals(null, HttpsClient.getHttpsClient(Mockito.mock(HttpsConfigInfoBean.class)));
//Handle Error Scenarios
try {
oResponse = HttpsClient.execute("POST", oHeaders, "//check", "body", oBean);
} catch (Exception e) {
Assert.assertEquals("Target host is null", e.getMessage());
}
try {
oResponse = HttpsClient.execute("GET", oHeaders, "//check", "body", oBean);
} catch (Exception e) {
Assert.assertEquals("Target host is null", e.getMessage());
}
try {
oResponse = HttpsClient.execute("DELETE", oHeaders, "//check", "body", oBean);
} catch (Exception e) {
Assert.assertEquals("Target host is null", e.getMessage());
}
// TODO Check the valid Responses
}
use of io.servicecomb.foundation.common.entities.HttpsConfigInfoBean in project java-chassis by ServiceComb.
the class TestHttpsClient method testInitKeyStore.
@Test
public void testInitKeyStore(@Mocked final HttpsConfigInfoBean configInfoBean, @Mocked final KeyManagerFactory factory) {
HttpsConfigInfoBean oBean = new HttpsConfigInfoBean();
new Expectations() {
{
configInfoBean.getKeyStorePath();
result = "/foundation-common/src/test/resources/config/test.1.properties";
configInfoBean.getKeyStorePasswd();
result = "1769";
configInfoBean.getTrustStorePath();
result = "/foundation-common/src/test/resources/config/test.1.properties";
configInfoBean.getTrustStorePasswd();
result = "1769";
}
};
new MockUp<KeyManagerFactory>() {
@Mock
public final void init(KeyStore ks, char[] password) {
}
@Mock
public final KeyManager[] getKeyManagers() {
return null;
}
};
String keyStoreType = KeyStore.getDefaultType();
try {
final KeyStore keyStore = KeyStore.getInstance(keyStoreType);
new MockUp<HttpsClient>() {
@Mock
private KeyStore initKeyStore(String storePath, String storePasswd, String storeType) throws IOException {
return keyStore;
}
};
} catch (KeyStoreException e) {
Assert.assertTrue(false);
}
HttpsClient.getHttpsClient(oBean);
Assert.assertNotEquals(null, HttpsClient.getHttpsClient(Mockito.mock(HttpsConfigInfoBean.class)));
}
use of io.servicecomb.foundation.common.entities.HttpsConfigInfoBean in project java-chassis by ServiceComb.
the class TestHttpsClient method testGeneralSecurityException.
@Test
public void testGeneralSecurityException() {
new MockUp<HttpsClient>() {
@Mock
private SSLContext createSSLContext(HttpsConfigInfoBean configBean) throws GeneralSecurityException, IOException {
throw new GeneralSecurityException();
}
};
HttpsConfigInfoBean oBean = new HttpsConfigInfoBean();
Assert.assertNotNull(HttpsClient.getHttpsClient(oBean));
}
use of io.servicecomb.foundation.common.entities.HttpsConfigInfoBean in project java-chassis by ServiceComb.
the class TestHttpsClient method testFullOperation.
@Test
public void testFullOperation() {
new MockUp<KeyStore>() {
@Mock
public KeyStore getInstance(String type) throws KeyStoreException {
throw new KeyStoreException();
}
};
HttpsClient.getHttpsClient();
new MockUp<KeyStore>() {
@Mock
public KeyStore getInstance(String type) throws KeyStoreException {
throw new RuntimeException();
}
};
HttpsClient.getHttpsClient();
HttpsConfigInfoBean oBean = new HttpsConfigInfoBean();
HttpsClient.getHttpsClient(oBean);
Assert.assertNotEquals(null, HttpsClient.getHttpsClient(Mockito.mock(HttpsConfigInfoBean.class)));
}
Aggregations