ServiceDescriptionFactory { ServiceDescription getServiceDescription() throws ConfigurationException { final XPath pathsXPath = this.xPathFactory.newXPath(); try { final Node serviceDescriptionNode = (Node) pathsXPath.evaluate( ConfigurationFileTagsV1.SERVICE_DESCRIPTION_ELEMENT_XPATH, this.configuration, XPathConstants.NODE); final String title = getMandatoryElementText( serviceDescriptionNode, ConfigurationFileTagsV1.TITLE_ELEMENT); ServiceDescription.Builder builder = new ServiceDescription.Builder( title, Migrate.class.getCanonicalName()); Property[] serviceProperties = getServiceProperties(serviceDescriptionNode); builder.author(getMandatoryElementText(serviceDescriptionNode, ConfigurationFileTagsV1.CREATOR_ELEMENT)); builder.classname(this.canonicalServiceName); builder.description(getOptionalElementText(serviceDescriptionNode, ConfigurationFileTagsV1.DESCRIPTION_ELEMENT)); final String serviceVersion = getOptionalElementText( serviceDescriptionNode, ConfigurationFileTagsV1.VERSION_ELEMENT); final Tool toolDescription = getToolDescriptionElement(serviceDescriptionNode); String identifier = getOptionalElementText(serviceDescriptionNode, ConfigurationFileTagsV1.IDENTIFIER_ELEMENT); if (identifier == null || "".equals(identifier)) { try { final MessageDigest identDigest = MessageDigest .getInstance("MD5"); identDigest.update(this.canonicalServiceName.getBytes()); final String versionInfo = (serviceVersion != null) ? serviceVersion : ""; identDigest.update(versionInfo.getBytes()); final URI toolIDURI = toolDescription.getIdentifier(); final String toolIdentifier = toolIDURI == null ? "" : toolIDURI.toString(); identDigest.update(toolIdentifier.getBytes()); final BigInteger md5hash = new BigInteger(identDigest.digest()); identifier = md5hash.toString(16); } catch (NoSuchAlgorithmException nsae) { throw new RuntimeException(nsae); } } builder.identifier(identifier); builder.version(serviceVersion); builder.tool(toolDescription); builder.instructions(getOptionalElementText(serviceDescriptionNode, ConfigurationFileTagsV1.INSTRUCTIONS_ELEMENT)); builder.furtherInfo(getOptionalURIElement(serviceDescriptionNode, ConfigurationFileTagsV1.FURTHER_INFO_ELEMENT)); builder.logo(getOptionalURIElement(serviceDescriptionNode, ConfigurationFileTagsV1.LOGO_ELEMENT)); builder.serviceProvider(this.serviceProvider); final DBMigrationPathFactory migrationPathFactory = new DBMigrationPathFactory( this.configuration); final MigrationPaths migrationPaths = migrationPathFactory .getAllMigrationPaths(); builder .paths(MigrationPathConverter .toPlanetsPaths(migrationPaths)); builder.inputFormats(migrationPaths.getInputFormatURIs().toArray( new URI[0])); builder.parameters(getUniqueParameters(migrationPaths)); builder.properties(serviceProperties); return builder.build(); } catch (XPathExpressionException xPathExpressionException) { throw new ConfigurationException(String.format( "Failed parsing the '%s' element in the '%s' element.", ConfigurationFileTagsV1.SERVICE_DESCRIPTION_ELEMENT_XPATH, this.configuration.getNodeName()), xPathExpressionException); } catch (NullPointerException nullPointerException) { throw new ConfigurationException(String.format( "Failed parsing the '%s' element in the '%s' element.", ConfigurationFileTagsV1.SERVICE_DESCRIPTION_ELEMENT_XPATH, this.configuration.getNodeName()), nullPointerException); } } ServiceDescriptionFactory(String canonicalServiceName,
            String serviceProvider, Document wrapperConfiguration);   }
@Test public void testGetServiceDescription() throws Exception { final ServiceDescription serviceDescription = serviceDescriptionFactory .getServiceDescription(); assertNotNull(serviceDescription); assertEquals("Un-expected author (creator) information.", "\"Easter Bunny <easter.bunny@bunny.net>\"", serviceDescription .getAuthor()); final String expectedDescription = "Example description of a service " + "wrapping of a fantastic\n command line tool for migrating an " + "egg to eggnog."; assertEquals("Un-expected description.", expectedDescription, serviceDescription.getDescription()); final URI expectedFurtherInfoURI = new URI("http: assertEquals("Un-expected text returned by getFurtherInfo().", expectedFurtherInfoURI, serviceDescription.getFurtherInfo()); assertEquals("Un-expected identifier.", "-3995df4febea7decc4848e2864b7f863", serviceDescription.getIdentifier()); assertEquals("Un-expected input formats.", getExpectedInputFormats(), new HashSet<URI>(serviceDescription.getInputFormats())); final String expectedInstructions = "Example: Please install the XYZ " + "tool on the system to\n make this service work."; assertEquals("Un-expected instructions.", expectedInstructions, serviceDescription.getInstructions()); final String expectedLogoURL = "http: + "/Planets_Logo.png"; assertEquals("Un-expected logo URI.", expectedLogoURL, serviceDescription.getLogo().toString()); final String expctedServiceName = "Example: Eggnog migration service."; assertEquals("Un-expected service name.", expctedServiceName, serviceDescription.getName()); assertEquals("Un-expected service class name.", this.getClass() .getCanonicalName(), serviceDescription.getClassname()); verifyParameters(serviceDescription.getParameters()); verifyToolDescription(serviceDescription.getTool()); assertEquals("Un-expected service version.", "3.141592653589793", serviceDescription.getVersion()); assertEquals("Not testing a service, thus un-expected end-point URL.", null, serviceDescription.getEndpoint()); verifyProperties(serviceDescription.getProperties()); assertEquals("Un-expected service provider information.", SERVICE_PROVIDER, serviceDescription.getServiceProvider()); assertEquals("Un-expected interface type.", "eu.planets_project.services.migrate.Migrate", serviceDescription.getType()); verifyMigrationPaths(serviceDescription.getPaths()); }