|
| 1 | +/* |
| 2 | + * Copyright 2019 Ipregistry (https://ipregistry.co). |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package co.ipregistry.api.client.model; |
| 17 | + |
| 18 | + |
| 19 | +import tools.jackson.databind.ObjectMapper; |
| 20 | +import org.junit.jupiter.api.Assertions; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | + |
| 24 | +class ConnectionTest { |
| 25 | + |
| 26 | + private static final ObjectMapper MAPPER = new ObjectMapper(); |
| 27 | + |
| 28 | + @Test |
| 29 | + void testDeserializeFullPayload() { |
| 30 | + final Connection connection = MAPPER.readValue("{\n" + |
| 31 | + " \"asn\" : 15169,\n" + |
| 32 | + " \"domain\" : \"google.com\",\n" + |
| 33 | + " \"is_anycast\" : true,\n" + |
| 34 | + " \"organization\" : \"Google LLC\",\n" + |
| 35 | + " \"route\" : \"8.8.8.0/24\",\n" + |
| 36 | + " \"type\" : \"hosting\"\n" + |
| 37 | + " }", Connection.class); |
| 38 | + |
| 39 | + Assertions.assertEquals(15169L, connection.getAsn()); |
| 40 | + Assertions.assertEquals("google.com", connection.getDomain()); |
| 41 | + Assertions.assertTrue(connection.isAnycast()); |
| 42 | + Assertions.assertEquals("Google LLC", connection.getOrganization()); |
| 43 | + Assertions.assertEquals("8.8.8.0/24", connection.getRoute()); |
| 44 | + Assertions.assertEquals(ConnectionType.HOSTING, connection.getType()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void testIsAnycastFalse() { |
| 49 | + final Connection connection = MAPPER.readValue("{\"is_anycast\" : false}", Connection.class); |
| 50 | + |
| 51 | + Assertions.assertFalse(connection.isAnycast()); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testIsAnycastDefaultsToFalseWhenAbsent() { |
| 56 | + final Connection connection = MAPPER.readValue("{\"asn\" : 15169}", Connection.class); |
| 57 | + |
| 58 | + Assertions.assertFalse(connection.isAnycast()); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments