use of mockit.Expectations in project pulsar by yahoo.
the class AbstractIncrementalLongHashTest method testResumeLongReadOnlyByteBuffer.
@Test
public void testResumeLongReadOnlyByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
new Expectations(hash) {
{
hash.resumeUnchecked(0x4200000000L, withInstanceOf(byte[].class), 0, 10);
}
};
hash.resume(0x4200000000L, input);
assertEquals(input.limit(), input.position());
}
use of mockit.Expectations in project pulsar by yahoo.
the class AbstractIncrementalLongHashTest method testResumeLongByteBuffer.
@Test
public void testResumeLongByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
new Expectations(hash) {
{
hash.resumeUnchecked(0x4200000000L, input.array(), input.arrayOffset() + 5, 10);
}
};
hash.resume(0x4200000000L, input);
assertEquals(input.limit(), input.position());
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class TestCseApplicationListener method testCseApplicationListenerThrowException.
@Test
public void testCseApplicationListenerThrowException(@Injectable ContextRefreshedEvent event, @Injectable AbstractApplicationContext context, @Injectable BootListener listener, @Injectable ProducerProviderManager producerProviderManager) throws Exception {
Map<String, BootListener> listeners = new HashMap<>();
listeners.put("test", listener);
new Expectations() {
{
event.getApplicationContext();
result = context;
context.getBeansOfType(BootListener.class);
result = listeners;
producerProviderManager.init();
result = new IOException();
}
};
CseApplicationListener cal = new CseApplicationListener();
ReflectUtils.setField(cal, "producerProviderManager", producerProviderManager);
cal.onApplicationEvent(event);
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class SSLManagerTest method testSSLManagerServerAndClient.
@Test
public void testSSLManagerServerAndClient(@Mocked final NetworkInterface nif) throws Exception {
final InetAddress ia = Inet4Address.getByName("10.57.65.225");
final Enumeration<NetworkInterface> interfaces = new Enumeration<NetworkInterface>() {
int count = 1;
int cur = 0;
@Override
public boolean hasMoreElements() {
if (cur < count) {
cur++;
return true;
}
return false;
}
@Override
public NetworkInterface nextElement() {
return nif;
}
};
final Enumeration<InetAddress> ias = new Enumeration<InetAddress>() {
int count = 1;
int cur = 0;
@Override
public boolean hasMoreElements() {
if (cur < count) {
cur++;
return true;
}
return false;
}
@Override
public InetAddress nextElement() {
return ia;
}
};
new Expectations() {
@Mocked
NetworkInterface nif;
{
NetworkInterface.getNetworkInterfaces();
result = interfaces;
}
};
new Expectations() {
{
nif.getInetAddresses();
result = ias;
ia.getHostAddress();
result = "10.57.65.225";
}
};
SSLOption option = SSLOption.build(DIR + "/server.ssl.properties");
SSLCustom custom = new SSLCustom() {
@Override
public String getFullPath(String filename) {
return DIR + "/ssl/" + filename;
}
@Override
public char[] decode(char[] encrypted) {
return encrypted;
}
};
final SSLServerSocket serverSocket = SSLManager.createSSLServerSocket(option, custom);
serverSocket.bind(new InetSocketAddress("127.0.0.1", 8886));
String[] protos = serverSocket.getEnabledCipherSuites();
String[] protosExpected = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA".split(",");
Assert.assertArrayEquals(protos, protosExpected);
String[] ciphers = serverSocket.getEnabledCipherSuites();
String[] ciphersExpected = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA".split(",");
Assert.assertArrayEquals(ciphers, ciphersExpected);
Assert.assertEquals(serverSocket.getNeedClientAuth(), true);
SSLOption clientoption = SSLOption.build(DIR + "/client.ssl.properties");
SSLSocket clientsocket = SSLManager.createSSLSocket(clientoption, custom);
String[] clientprotos = clientsocket.getEnabledCipherSuites();
String[] clientprotosExpected = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA".split(",");
Assert.assertArrayEquals(clientprotos, clientprotosExpected);
String[] clientciphers = clientsocket.getEnabledCipherSuites();
String[] clientciphersExpected = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA".split(",");
Assert.assertArrayEquals(clientciphers, clientciphersExpected);
Assert.assertEquals(clientsocket.getNeedClientAuth(), false);
boolean validAssert = true;
try {
clientsocket.connect(new InetSocketAddress("127.0.0.1", 8886));
new Thread() {
public void run() {
try {
SSLSocket s = (SSLSocket) serverSocket.accept();
s.addHandshakeCompletedListener(new HandshakeCompletedListener() {
@Override
public void handshakeCompleted(HandshakeCompletedEvent arg0) {
}
});
s.getOutputStream().write(new byte[] { 0, 1 });
} catch (IOException e) {
e.printStackTrace();
// this should not happen, do a false assert
Assert.assertEquals(false, true);
}
}
}.start();
clientsocket.startHandshake();
clientsocket.close();
serverSocket.close();
// socked successfully opened and closed
} catch (Exception e) {
e.printStackTrace();
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of mockit.Expectations in project java-chassis by ServiceComb.
the class CertificateUtilTest method testFindOwner.
@Test
public void testFindOwner(@Mocked X500Principal aX500Principal1, @Mocked X500Principal aX500Principal2, @Mocked MyX509Certificate myX509Certificate) {
new Expectations() {
{
aX500Principal1.getName();
result = "Huawei";
}
{
aX500Principal2.getName();
result = "Huawei";
}
{
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;
X509Certificate aX509Certificate = CertificateUtil.findOwner(xxmyX509Certificate);
Assert.assertNull(aX509Certificate);
}
Aggregations