use of mockit.Expectations in project java-chassis by ServiceComb.
the class CertificateUtilTest method testFindRootCAException.
@Test
public void testFindRootCAException(@Mocked X500Principal aX500Principal1, @Mocked X500Principal aX500Principal2, @Mocked MyX509Certificate myX509Certificate) {
new Expectations() {
{
aX500Principal1.getName();
result = "Huawei1";
}
{
aX500Principal2.getName();
result = "Huawei3";
}
{
myX509Certificate.getSubjectX500Principal();
result = aX500Principal1;
myX509Certificate.getIssuerX500Principal();
result = aX500Principal2;
}
};
MyX509Certificate myX509Certificate1 = new MyX509Certificate();
MyX509Certificate myX509Certificate2 = new MyX509Certificate();
MyX509Certificate[] xxmyX509Certificate = new MyX509Certificate[2];
xxmyX509Certificate[0] = myX509Certificate1;
xxmyX509Certificate[1] = myX509Certificate2;
try {
X509Certificate aX509Certificate = CertificateUtil.findOwner(xxmyX509Certificate);
Assert.assertNull(aX509Certificate);
} catch (IllegalArgumentException e) {
Assert.assertEquals("bad certificate chain: no root CA.", e.getMessage());
}
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class TrustManagerExtTest method testCheckClientTrusted.
@Test
public void testCheckClientTrusted(@Mocked CertificateUtil certificateUtil) {
MyX509Certificate myX509Certificate1 = new MyX509Certificate();
MyX509Certificate myX509Certificate2 = new MyX509Certificate();
MyX509Certificate[] MyX509CertificateArray = new MyX509Certificate[2];
MyX509CertificateArray[0] = myX509Certificate1;
MyX509CertificateArray[1] = myX509Certificate2;
new Expectations() {
{
CertificateUtil.findOwner((X509Certificate[]) any);
result = any;
CertificateUtil.getCN((X509Certificate) any);
result = "10.67.147.115";
}
};
MyX509ExtendedTrustManager myX509ExtendedTrustManager = new MyX509ExtendedTrustManager();
TrustManagerExt trustManagerExt = new TrustManagerExt(myX509ExtendedTrustManager, option, custom);
Socket socket = null;
SSLEngine sslengine = null;
boolean validAssert = true;
try {
trustManagerExt.checkClientTrusted(MyX509CertificateArray, "pks", socket);
trustManagerExt.checkClientTrusted(MyX509CertificateArray, "pks", sslengine);
trustManagerExt.checkServerTrusted(MyX509CertificateArray, "pks", socket);
trustManagerExt.checkServerTrusted(MyX509CertificateArray, "pks", sslengine);
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class TestRestServerVerticle method testRestServerVerticleWithRouter.
@Test
public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080");
new Expectations() {
{
transport.parseAddress("http://127.0.0.1:8080");
result = endpointObject;
}
};
Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080");
new Expectations() {
{
context.config();
result = jsonObject;
jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
result = endpiont;
}
};
RestServerVerticle server = new RestServerVerticle();
// process stuff done by Expectations
server.init(vertx, context);
server.start(startFuture);
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class TestRegistry method testRegistryUtilsWithStub.
@Test
public void testRegistryUtilsWithStub(@Mocked final ServiceRegistryClientImpl oMockServiceRegistryClient) throws Exception {
HeartbeatResponse response = new HeartbeatResponse();
response.setOk(true);
response.setMessage("OK");
new Expectations() {
{
oMockServiceRegistryClient.init();
oMockServiceRegistryClient.registerMicroservice((Microservice) any);
result = "sampleServiceID";
oMockServiceRegistryClient.registerMicroserviceInstance((MicroserviceInstance) any);
result = "sampleInstanceID";
oMockServiceRegistryClient.unregisterMicroserviceInstance(anyString, anyString);
result = true;
}
};
RegistryUtils.setSrClient(oMockServiceRegistryClient);
RegistryUtils.init();
Assert.assertEquals(true, RegistryUtils.unregsiterInstance());
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class TestRegistry method testRegistryUtilsWithStubHeartbeatFailure.
@Test
public void testRegistryUtilsWithStubHeartbeatFailure(@Mocked final ServiceRegistryClientImpl oMockServiceRegistryClient) throws Exception {
final HeartbeatResponse response = new HeartbeatResponse();
response.setOk(false);
response.setMessage("FAIL");
new Expectations() {
{
oMockServiceRegistryClient.init();
oMockServiceRegistryClient.registerMicroservice((Microservice) any);
result = "sampleServiceID";
oMockServiceRegistryClient.registerMicroserviceInstance((MicroserviceInstance) any);
result = "sampleInstanceID";
oMockServiceRegistryClient.heartbeat(anyString, anyString);
result = response;
oMockServiceRegistryClient.unregisterMicroserviceInstance(anyString, anyString);
result = false;
}
};
RegistryUtils.setSrClient(oMockServiceRegistryClient);
RegistryUtils.init();
Assert.assertEquals(false, RegistryUtils.heartbeat().isOk());
Assert.assertEquals(false, RegistryUtils.unregsiterInstance());
}
Aggregations