ConsistencyChecker { public void checkNamespaceUri(@NonNull DefinitionsChildId id) { Objects.requireNonNull(id); String uriStr = id.getNamespace().getDecoded(); if (!uriStr.trim().equals(uriStr)) { printAndAddError(id, "Namespace starts or ends with white spaces"); } URI uri; try { uri = new URI(uriStr); } catch (URISyntaxException e) { LOGGER.debug("Invalid URI", e); printAndAddError(id, "Invalid URI: " + e.getMessage()); return; } if (!uri.isAbsolute()) { printAndAddError(id, "URI is relative"); } if ((uriStr.startsWith("http: String[] splitUri = uriStr.split("/"); String lastElement = splitUri[splitUri.length - 1]; String uriStrWithoutLastElement = uriStr.substring(0, (uriStr.length() - lastElement.length())); if (!(id.getXmlId().toString().startsWith(lastElement)) || (!uriStrWithoutLastElement.toLowerCase().equals(uriStrWithoutLastElement))) { printAndAddError(id, "opentosca URI is not lowercase"); } } if (uriStr.endsWith("/")) { printAndAddError(id, "URI ends with a slash"); } if (uriStr.contains(ARTEFACT_BE)) { printAndAddError(id, "artifact is spelled with i in American English, not artefact as in British English"); } boolean namespaceUriContainsDifferentType = DefinitionsChildId.ALL_TOSCA_COMPONENT_ID_CLASSES.stream() .filter(definitionsChildIdClass -> !definitionsChildIdClass.isAssignableFrom(id.getClass())) .flatMap(definitionsChildIdClass -> { final String lowerCaseIdClass = Util.getTypeForComponentId(definitionsChildIdClass).toLowerCase(); return Stream.of(lowerCaseIdClass + "s", lowerCaseIdClass + "/"); }) .anyMatch(definitionsChildName -> uriStr.contains(definitionsChildName)); if (namespaceUriContainsDifferentType) { if ((id instanceof ServiceTemplateId) && (id.getNamespace().getDecoded().contains("compliance"))) { } else { printAndAddError(id, "Namespace URI contains tosca definitions name from other type. E.g., Namespace is ...servicetemplates..., but the type is an artifact template"); } } } ConsistencyChecker(@NonNull ConsistencyCheckerConfiguration configuration);  ConsistencyChecker(@NonNull ConsistencyCheckerConfiguration configuration,
                              @NonNull ConsistencyCheckerProgressListener consistencyCheckerProgressListener); void setConsistencyCheckerProgressListener(ConsistencyCheckerProgressListener consistencyCheckerProgressListener); int numberOfDefinitionsToCheck(); void checkCorruption(); void checkNamespaceUri(@NonNull DefinitionsChildId id); ConsistencyErrorCollector getErrorCollector();  }
@Test public void nodeTypeImplementationNamespaceHasNoErrors() throws Exception { NodeTypeImplementationId id = new NodeTypeImplementationId("http: ConsistencyErrorCollector errorLogger = new ConsistencyErrorCollector(); consistencyChecker.checkNamespaceUri(id); assertEquals(Collections.emptyMap(), errorLogger.getErrorList()); }