private static void assertDescriptorEquals(ServiceDescriptor expected, ServiceDescriptor actual) { assertEquals(actual, expected); assertEquals(actual.getId(), expected.getId()); assertEquals(actual.getNodeId(), expected.getNodeId()); assertEquals(actual.getType(), expected.getType()); assertEquals(actual.getPool(), expected.getPool()); assertEquals(actual.getLocation(), expected.getLocation()); assertEquals(actual.getProperties(), expected.getProperties()); } }
private static void assertDescriptorEquals(ServiceDescriptor expected, ServiceDescriptor actual) { assertEquals(actual, expected); assertEquals(actual.getId(), expected.getId()); assertEquals(actual.getNodeId(), expected.getNodeId()); assertEquals(actual.getType(), expected.getType()); assertEquals(actual.getPool(), expected.getPool()); assertEquals(actual.getLocation(), expected.getLocation()); assertEquals(actual.getProperties(), expected.getProperties()); } }
@Test public void testJsonDecode() throws Exception { ServiceDescriptor expected = new ServiceDescriptor(UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); String json = Resources.toString(Resources.getResource("service-descriptor.json"), Charsets.UTF_8); ServiceDescriptor actual = serviceDescriptorCodec.fromJson(json); assertEquals(actual, expected); assertEquals(actual.getId(), expected.getId()); assertEquals(actual.getNodeId(), expected.getNodeId()); assertEquals(actual.getType(), expected.getType()); assertEquals(actual.getPool(), expected.getPool()); assertEquals(actual.getLocation(), expected.getLocation()); assertEquals(actual.getProperties(), expected.getProperties()); }
assertEquals(service.getId().toString(), id); assertNull(service.getNodeId()); assertEquals(service.getLocation(), announcement.get("location")); assertEquals(service.getPool(), announcement.get("pool")); assertEquals(service.getProperties(), announcement.get("properties"));
assertNotNull(service.getId()); assertEquals(service.getNodeId(), announcerNodeInfo.getNodeId()); assertEquals(service.getLocation(), announcerNodeInfo.getLocation()); assertEquals(service.getPool(), announcerNodeInfo.getPool()); assertEquals(service.getProperties(), announcement.getProperties());
@Test public void testBuilderNodeId() { ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptorBuilder builder = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeId(expected.getNodeId()) .setPool(expected.getPool()) .setState(expected.getState()); for (Map.Entry<String, String> entry : expected.getProperties().entrySet()) { builder.addProperty(entry.getKey(), entry.getValue()); } assertDescriptorEquals(expected, builder.build()); }
@Test public void testBuilderNodeId() { ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), "node", "type", "pool", "location", ServiceState.RUNNING, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptorBuilder builder = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeId(expected.getNodeId()) .setPool(expected.getPool()) .setState(expected.getState()); for (Map.Entry<String, String> entry : expected.getProperties().entrySet()) { builder.addProperty(entry.getKey(), entry.getValue()); } assertDescriptorEquals(expected, builder.build()); }
@Test public void testBuilderNodeInfo() { NodeInfo nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setPool("pool")); ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), nodeInfo.getNodeId(), "type", nodeInfo.getPool(), "location", ServiceState.STOPPED, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptor actual = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeInfo(nodeInfo) .setState(expected.getState()) .addProperties(expected.getProperties()) .build(); assertDescriptorEquals(expected, actual); }
@Test public void testBuilderNodeInfo() { NodeInfo nodeInfo = new NodeInfo(new NodeConfig().setEnvironment("test").setPool("pool")); ServiceDescriptor expected = new ServiceDescriptor( UUID.fromString("12345678-1234-1234-1234-123456789012"), nodeInfo.getNodeId(), "type", nodeInfo.getPool(), "location", ServiceState.STOPPED, ImmutableMap.of("a", "apple", "b", "banana")); ServiceDescriptor actual = serviceDescriptor(expected.getType()) .setId(expected.getId()) .setLocation(expected.getLocation()) .setNodeInfo(nodeInfo) .setState(expected.getState()) .addProperties(expected.getProperties()) .build(); assertDescriptorEquals(expected, actual); }