use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaJacksonCodecTest method testApplicationXStreamEncodeJacksonDecode.
@Test
public void testApplicationXStreamEncodeJacksonDecode() throws Exception {
Application original = APPLICATION_1;
// Encode
ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
new EntityBodyConverter().write(original, captureStream, MediaType.APPLICATION_JSON_TYPE);
byte[] encoded = captureStream.toByteArray();
// Decode
InputStream source = new ByteArrayInputStream(encoded);
Application decoded = codec.readValue(Application.class, source);
assertTrue(EurekaEntityComparators.equal(decoded, original));
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaJacksonCodecTest method testApplicationJacksonEncodeXStreamDecode.
@Test
public void testApplicationJacksonEncodeXStreamDecode() throws Exception {
// Encode
ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
codec.writeTo(APPLICATION_1, captureStream);
byte[] encoded = captureStream.toByteArray();
// Decode
InputStream source = new ByteArrayInputStream(encoded);
Application decoded = (Application) new EntityBodyConverter().read(source, Application.class, MediaType.APPLICATION_JSON_TYPE);
assertTrue(EurekaEntityComparators.equal(decoded, APPLICATION_1));
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaJsonAndXmlJacksonCodecTest method doApplicationEncodeDecode.
private void doApplicationEncodeDecode(AbstractEurekaJacksonCodec codec) throws Exception {
Application application = new Application("testApp");
application.addInstance(infoIterator.next());
application.addInstance(infoIterator.next());
String encodedString = codec.getObjectMapper(Application.class).writeValueAsString(application);
Application decodedValue = codec.getObjectMapper(Application.class).readValue(encodedString, Application.class);
assertThat(EurekaEntityComparators.equal(application, decodedValue), is(true));
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaEntityComparators method equal.
public static boolean equal(Applications first, Applications second) {
if (first == second) {
return true;
}
if (first == null || first == null && second != null) {
return false;
}
List<Application> firstApps = first.getRegisteredApplications();
List<Application> secondApps = second.getRegisteredApplications();
if (firstApps == null && secondApps == null) {
return true;
}
if (firstApps == null || secondApps == null || firstApps.size() != secondApps.size()) {
return false;
}
for (Application firstApp : firstApps) {
Application secondApp = second.getRegisteredApplications(firstApp.getName());
if (!equal(firstApp, secondApp)) {
return false;
}
}
return true;
}
use of com.netflix.discovery.shared.Application in project eureka by Netflix.
the class EurekaEntityFunctions method toApplicationMap.
public static Map<String, Application> toApplicationMap(List<InstanceInfo> instances) {
Map<String, Application> applicationMap = new HashMap<String, Application>();
for (InstanceInfo instance : instances) {
String appName = instance.getAppName();
Application application = applicationMap.get(appName);
if (application == null) {
applicationMap.put(appName, application = new Application(appName));
}
application.addInstance(instance);
}
return applicationMap;
}
Aggregations