ModelConverter extends AbstractModelConverter<Model> { @Override public <G> G convert(Type targetType, Object sourceValue) { if (targetType == Extension.class) { return (G) convertToExtension((Model) sourceValue); } else { throw new ConversionException(String.format("Unsupported target type [%s]", targetType)); } }  @Override G convert(Type targetType, Object sourceValue); static final ParameterizedType ROLE; }
@Test void convertPomToExtension() throws SecurityException { Model model = new Model(); model.setGroupId("groupid"); model.setArtifactId("artifactid"); model.setVersion("version"); model.setPackaging("pom"); Extension extension = this.converter.convert(Extension.class, model); assertNull(extension.getType()); }
@Test void convertToExtensionWithIncludedOptionalDependencies() throws SecurityException, URISyntaxException { Model model = new Model(); model.setGroupId("groupid"); model.setArtifactId("artifactid"); model.setVersion("version"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_CATEGORY, "category"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES, "namespace1, namespace2,\r\n\t {root}, \"namespace3\", 'namespace4'"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_FEATURES, "feature1/1.0"); model.addProperty(Extension.IKEYPREFIX + "optionalIncluded", "true"); Repository repository = new Repository(); repository.setId("repository-id"); repository.setUrl("http: model.addRepository(repository); Dependency dependency = new Dependency(); dependency.setGroupId("dgroupid"); dependency.setArtifactId("dartifactId"); dependency.setVersion("1.0"); dependency.setOptional(true); model.addDependency(dependency); Extension extension = this.converter.convert(Extension.class, model); assertEquals(model.getGroupId() + ':' + model.getArtifactId(), extension.getId().getId()); assertEquals(model.getVersion(), extension.getId().getVersion().getValue()); assertEquals(ListUtils.union(Arrays.asList(new ExtensionId("feature1", "1.0")), INJECTED_FEATURES), new ArrayList<>(extension.getExtensionFeatures())); assertEquals("category", extension.getCategory()); assertNull(extension.getProperty(Extension.IKEYPREFIX + Extension.FIELD_CATEGORY)); assertEquals(Arrays.asList("namespace1", "namespace2", "{root}", "namespace3", "namespace4"), new ArrayList<>(extension.getAllowedNamespaces())); assertNull(extension.getProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES)); assertEquals( Arrays.asList(new DefaultExtensionRepositoryDescriptor("repository-id", "maven", new URI("http: extension.getRepositories()); assertEquals(1, extension.getDependencies().size()); ExtensionDependency extensionDependency = extension.getDependencies().iterator().next(); assertTrue(extensionDependency.isOptional()); }
@Test void convertToXWikiExtensionWithOptionalDependencies() throws SecurityException, URISyntaxException { Model model = new Model(); model.setGroupId("org.xwiki"); model.setArtifactId("artifactid"); model.setVersion("version"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_CATEGORY, "category"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES, "namespace1, namespace2,\r\n\t {root}, \"namespace3\", 'namespace4'"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_FEATURES, "feature1/1.0"); Repository repository = new Repository(); repository.setId("repository-id"); repository.setUrl("http: model.addRepository(repository); Dependency dependency = new Dependency(); dependency.setGroupId("dgroupid"); dependency.setArtifactId("dartifactId"); dependency.setVersion("1.0"); dependency.setOptional(true); model.addDependency(dependency); Extension extension = this.converter.convert(Extension.class, model); assertEquals(model.getGroupId() + ':' + model.getArtifactId(), extension.getId().getId()); assertEquals(model.getVersion(), extension.getId().getVersion().getValue()); assertEquals(ListUtils.union(Arrays.asList(new ExtensionId("feature1", "1.0")), INJECTED_FEATURES), new ArrayList<>(extension.getExtensionFeatures())); assertEquals("category", extension.getCategory()); assertNull(extension.getProperty(Extension.IKEYPREFIX + Extension.FIELD_CATEGORY)); assertEquals(Arrays.asList("namespace1", "namespace2", "{root}", "namespace3", "namespace4"), new ArrayList<>(extension.getAllowedNamespaces())); assertNull(extension.getProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES)); assertEquals( Arrays.asList(new DefaultExtensionRepositoryDescriptor("repository-id", "maven", new URI("http: extension.getRepositories()); assertEquals(1, extension.getDependencies().size()); ExtensionDependency extensionDependency = extension.getDependencies().iterator().next(); assertTrue(extensionDependency.isOptional()); }
@Test void convertToExtensionAllowedOnRoot() throws SecurityException { Model model = new Model(); model.setGroupId("groupid"); model.setArtifactId("artifactid"); model.setVersion("version"); model.addProperty(Extension.IKEYPREFIX + Extension.FIELD_NAMESPACES, "{root}"); Extension extension = this.converter.convert(Extension.class, model); assertEquals(Arrays.asList("{root}"), new ArrayList<>(extension.getAllowedNamespaces())); }