ModelMapper { public Module getModule(final DbModule dbModule) { final Module module = DataModelFactory.createModule(dbModule.getName(), dbModule.getVersion()); module.setPromoted(dbModule.isPromoted()); module.setSubmodule(dbModule.isSubmodule()); module.setCreatedDateTime(dbModule.getCreatedDateTime()); module.setUpdatedDateTime(dbModule.getUpdatedDateTime()); for (final String gavc : dbModule.getArtifacts()) { final DbArtifact dbArtifact = repositoryHandler.getArtifact(gavc); if (null != dbArtifact) { final Artifact artifact = getArtifact(dbArtifact); module.addArtifact(artifact); } } for (final DbDependency dbDependency : dbModule.getDependencies()) { final Dependency dependency = getDependency(dbDependency, module.getName(), module.getVersion()); dependency.setSourceName(module.getName()); dependency.setSourceVersion(module.getVersion()); module.addDependency(dependency); } for (final DbModule dbSubmodule : dbModule.getSubmodules()) { module.addSubmodule(getModule(dbSubmodule)); } return module; } ModelMapper(final RepositoryHandler repoHandler); DbOrganization getDbOrganization(final Organization organization); Organization getOrganization(final DbOrganization dbOrganization); DbLicense getDbLicense(final License license); License getLicense(final DbLicense dbLicense); DbArtifact getDbArtifact(final Artifact artifact); Artifact getArtifact(final DbArtifact dbArtifact); DbModule getDbModule(final Module module); Module getModule(final DbModule dbModule); Dependency getDependency(final DbDependency dbDependency, final String sourceName, final String sourceVersion); Comment getComment(final DbComment dbComment); DbComment getDbComment(final Comment comment);  }
@Test public void getModule(){ final DbModule dbModule = new DbModule(); dbModule.setName("root"); dbModule.setVersion("1.0.0-SNAPSHOT"); final DbArtifact dbArtifact = new DbArtifact(); dbArtifact.setGroupId("com.axway.root"); dbArtifact.setArtifactId("artifact1"); dbArtifact.setVersion("1.0.0-SNAPSHOT"); dbArtifact.setClassifier("win"); dbArtifact.setType("component"); dbArtifact.setExtension("jar"); dbModule.addArtifact(dbArtifact); final DbArtifact dbThirdParty = new DbArtifact(); dbThirdParty.setGroupId("org.apache"); dbThirdParty.setArtifactId("all"); dbThirdParty.setVersion("6.8.0-5426"); dbThirdParty.setType("jar"); dbThirdParty.setExtension("jar"); dbModule.addDependency(dbThirdParty.getGavc(), Scope.COMPILE); final DbModule dbSubmodule = new DbModule(); dbSubmodule.setSubmodule(true); dbSubmodule.setName("sub1"); dbSubmodule.setVersion("1.0.0-SNAPSHOT"); final DbArtifact dbArtifact2 = new DbArtifact(); dbArtifact2.setGroupId("com.axway.root.sub1"); dbArtifact2.setArtifactId("artifactSub1"); dbArtifact2.setVersion("1.0.0-SNAPSHOT"); dbArtifact2.setExtension("jar"); dbSubmodule.addArtifact(dbArtifact2); final DbArtifact dbThirdParty2 = new DbArtifact(); dbThirdParty2.setGroupId("org.lol"); dbThirdParty2.setArtifactId("all"); dbThirdParty2.setVersion("1.2.3-4"); dbThirdParty2.setExtension("jar"); dbSubmodule.addDependency(dbThirdParty2.getGavc(), Scope.PROVIDED); dbModule.addSubmodule(dbSubmodule); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getArtifact(dbArtifact.getGavc())).thenReturn(dbArtifact); when(repositoryHandler.getArtifact(dbArtifact2.getGavc())).thenReturn(dbArtifact2); when(repositoryHandler.getArtifact(dbThirdParty.getGavc())).thenReturn(dbThirdParty); when(repositoryHandler.getArtifact(dbThirdParty2.getGavc())).thenReturn(dbThirdParty2); final ModelMapper modelMapper = new ModelMapper(repositoryHandler); final Module module = modelMapper.getModule(dbModule); assertEquals(dbModule.getName(), module.getName()); assertEquals(dbModule.getVersion(), module.getVersion()); assertEquals(1, module.getArtifacts().size()); assertEquals(dbArtifact.getGavc(), module.getArtifacts().iterator().next().getGavc()); assertEquals(1, module.getDependencies().size()); final Dependency thirdParty = module.getDependencies().iterator().next(); assertEquals(dbThirdParty.getGavc(), thirdParty.getTarget().getGavc()); assertEquals(Scope.COMPILE, thirdParty.getScope()); assertEquals(dbModule.getName(), thirdParty.getSourceName()); assertEquals(dbModule.getVersion(), thirdParty.getSourceVersion()); assertEquals(1, module.getSubmodules().size()); final Module submodule = module.getSubmodules().iterator().next(); assertEquals(dbSubmodule.getName() , submodule.getName()); assertEquals(dbSubmodule.getVersion(), submodule.getVersion()); assertEquals(1, submodule.getArtifacts().size()); assertEquals(dbArtifact2.getGavc(), submodule.getArtifacts().iterator().next().getGavc()); assertEquals(1, submodule.getDependencies().size()); assertEquals(dbThirdParty2.getGavc(), submodule.getDependencies().iterator().next().getTarget().getGavc()); assertEquals(dbSubmodule.getName(), submodule.getDependencies().iterator().next().getSourceName()); assertEquals(dbSubmodule.getVersion(), submodule.getDependencies().iterator().next().getSourceVersion()); assertEquals(Scope.PROVIDED, submodule.getDependencies().iterator().next().getScope()); }