rust_eureka/response/
applications_response.rs

1use super::Applications;
2
3#[derive(Debug, PartialEq, Serialize, Deserialize)]
4pub struct ApplicationsResponse {
5    pub applications: Applications
6}
7
8impl<'a> ApplicationsResponse {
9    pub fn new(applications: Applications) -> ApplicationsResponse {
10        ApplicationsResponse {
11            applications: applications
12        }
13    }
14}
15
16#[cfg(test)]
17mod tests {
18    use serde_json;
19    use super::*;
20    use super::super::applications::tests::{build_test_applications, build_test_applications_json};
21
22    #[test]
23    fn test_applications_response_serialization() {
24        let applications = build_test_applications();
25        let ar = ApplicationsResponse::new(applications);
26        let result = serde_json::to_string(&ar).unwrap();
27        assert!(result.contains("{\"applications\":"))
28
29    }
30
31    #[test]
32    fn test_applications_response_deserialization() {
33        let json = build_applications_response_json();
34        let applications = build_test_applications();
35        let ar = ApplicationsResponse::new(applications);
36        let result = serde_json::from_str(&json).unwrap();
37        assert_eq!(ar, result);
38    }
39
40    #[test]
41    fn test_local_eureka_response() {
42        let ar = serde_json::from_str::<ApplicationsResponse>(local_eureka_json().as_ref());
43        assert!(ar.is_ok())
44    }
45
46    fn build_applications_response_json() -> String {
47        format!("{{\"applications\":{}}}", build_test_applications_json())
48    }
49
50    fn local_eureka_json() -> String {
51        r#"{
52    "applications": {
53        "versions__delta": 1,
54        "apps__hashcode": "UP_1_",
55        "application": {
56            "name": "INTEGRATION_TEST",
57            "instance": {
58                "hostName": "localhost",
59                "app": "INTEGRATION_TEST",
60                "ipAddr": "127.0.0.1",
61                "status": "UP",
62                "overriddenstatus": "UNKNOWN",
63                "port": {
64                    "@enabled": "true",
65                    "$": "7001"
66                },
67                "securePort": {
68                    "@enabled": "false",
69                    "$": "7002"
70                },
71                "countryId": 1,
72                "dataCenterInfo": {
73                    "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
74                    "name": "MyOwn"
75                },
76                "leaseInfo": {
77                    "renewalIntervalInSecs": 30,
78                    "durationInSecs": 90,
79                    "registrationTimestamp": 1504830481334,
80                    "lastRenewalTimestamp": 1504830481334,
81                    "evictionTimestamp": 0,
82                    "serviceUpTimestamp": 1504830302194
83                },
84                "metadata": {
85                    "@class": "java.util.Collections$EmptyMap"
86                },
87                "homePageUrl": "http://google.com",
88                "statusPageUrl": "http://google.com",
89                "healthCheckUrl": "http://google.com",
90                "vipAddress": "127.0.0.1",
91                "secureVipAddress": "127.0.0.1",
92                "isCoordinatingDiscoveryServer": false,
93                "lastUpdatedTimestamp": 1504830481334,
94                "lastDirtyTimestamp": 1504830480933,
95                "actionType": "ADDED"
96            }
97        }
98    }
99}"#.to_string()
100    }
101}
102