use of mockit.MockUp in project java-chassis by ServiceComb.
the class TestIpPortManager method testCreateServiceRegistryCache.
@Test
public void testCreateServiceRegistryCache() {
boolean validAssert = true;
List<MicroserviceInstance> list = new ArrayList<MicroserviceInstance>();
MicroserviceInstance e1 = new MicroserviceInstance();
List<String> endpoints = new ArrayList<>();
endpoints.add("rest://127.0.0.1:8080");
e1.setEndpoints(endpoints);
list.add(e1);
new MockUp<RegistryUtils>() {
@Mock
public List<MicroserviceInstance> findServiceInstance(String appId, String serviceName, String versionRule) {
return list;
}
};
Microservice microservice = new Microservice();
new MockUp<RegistryUtils>() {
@Mock
private Microservice createMicroserviceFromDefinition() {
return microservice;
}
};
try {
manager.createServiceRegistryCache();
Assert.assertNotNull(manager.get());
Assert.assertNull(manager.next());
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of mockit.MockUp in project java-chassis by ServiceComb.
the class TestRegistry method testFindServiceInstanceWithMicroServiceInstance.
@Test
public void testFindServiceInstanceWithMicroServiceInstance() {
List<MicroserviceInstance> microserviceInstanceList = new ArrayList<MicroserviceInstance>();
microserviceInstanceList.add(new MicroserviceInstance());
new MockUp<ServiceRegistryClientImpl>() {
@Mock
List<MicroserviceInstance> findServiceInstance(String selfMicroserviceId, String appId, String serviceName, String versionRule) {
return microserviceInstanceList;
}
};
List<MicroserviceInstance> microserviceInstanceListt = RegistryUtils.findServiceInstance("appId", "serviceName", "versionRule");
Assert.assertNotNull(microserviceInstanceListt);
}
use of mockit.MockUp in project java-chassis by ServiceComb.
the class TestRegistry method testUpdateInstanceProperties.
@Test
public void testUpdateInstanceProperties() {
MicroserviceInstance instance = RegistryUtils.getMicroserviceInstance();
instance.setServiceId("1");
instance.setInstanceId("1");
new MockUp<ServiceRegistryClientImpl>() {
@Mock
public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId, Map<String, String> instanceProperties) {
return true;
}
};
Assert.assertEquals(1, instance.getProperties().size());
Map<String, String> properties = new HashMap<>();
properties.put("tag1", "value1");
RegistryUtils.updateInstanceProperties(properties);
Assert.assertEquals(properties, instance.getProperties());
new MockUp<ServiceRegistryClientImpl>() {
@Mock
public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId, Map<String, String> instanceProperties) {
return false;
}
};
RegistryUtils.updateInstanceProperties(new HashMap<>());
Assert.assertEquals(properties, instance.getProperties());
}
use of mockit.MockUp 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 mockit.MockUp 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)));
}
Aggregations