### Question:
PortNetServiceDiscoveryComponent implements ResourceDiscoveryComponent, ManualAddFacet { @Override public DiscoveredResourceDetails discoverResource(Configuration pluginConfiguration, ResourceDiscoveryContext context) throws InvalidPluginConfigurationException { PortNetServiceComponentConfiguration componentConfiguration = PortNetServiceComponent .createComponentConfiguration(pluginConfiguration); String resourceKey = createResourceKey(componentConfiguration); return new DiscoveredResourceDetails(context.getResourceType(), resourceKey, resourceKey, null, null, pluginConfiguration, null); }  @Override Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context); @Override DiscoveredResourceDetails discoverResource(Configuration pluginConfiguration,
        ResourceDiscoveryContext context);  }### Answer:
@Test public void testValidComponentConfiguration() { try { DiscoveredResourceDetails resourceDetails = portNetServiceDiscoveryComponent.discoverResource( configuration, resourceDiscoveryContext); assertEquals(resourceDetails.getResourceType(), resourceType); } catch (InvalidPluginConfigurationException e) { fail("Component configuration should be valid", e); } }
@Test public void testMissingAddress() { configuration.remove(ConfigKeys.ADDRESS); try { portNetServiceDiscoveryComponent.discoverResource(configuration, resourceDiscoveryContext); fail("Component configuration should be invalid"); } catch (InvalidPluginConfigurationException e) { assertEquals(e.getMessage(), "Address is not defined"); } }
@Test public void testMissingPort() { configuration.remove(ConfigKeys.PORT); try { portNetServiceDiscoveryComponent.discoverResource(configuration, resourceDiscoveryContext); fail("Component configuration should be invalid"); } catch (InvalidPluginConfigurationException e) { assertEquals(e.getMessage(), "Port is not defined"); } }
@Test public void testInvalidPortNumberFormat() { String configPort = "NaN"; configuration.setSimpleValue(ConfigKeys.PORT, configPort); try { portNetServiceDiscoveryComponent.discoverResource(configuration, resourceDiscoveryContext); fail("Component configuration should be invalid"); } catch (InvalidPluginConfigurationException e) { assertEquals(e.getMessage(), "Invalid port number: " + configPort); } }
@Test public void testMalformedAddress() { String configAddress = "pipomolo"; configuration.setSimpleValue(ConfigKeys.ADDRESS, configAddress); try { portNetServiceDiscoveryComponent.discoverResource(configuration, resourceDiscoveryContext); fail("Component configuration should be invalid"); } catch (InvalidPluginConfigurationException e) { assertEquals(e.getCause().getClass(), UnknownHostException.class); } }