ModelMapper { public DbModule getDbModule(final Module module) { final DbModule dbModule = new DbModule(); dbModule.setName(module.getName()); dbModule.setVersion(module.getVersion()); dbModule.setPromoted(module.isPromoted()); dbModule.setSubmodule(module.isSubmodule()); dbModule.setCreatedDateTime(module.getCreatedDateTime()); dbModule.setUpdatedDateTime(module.getUpdatedDateTime()); for (final Artifact artifact : module.getArtifacts()) { final DbArtifact dbArtifact = getDbArtifact(artifact); dbModule.addArtifact(dbArtifact); } for (final Dependency dependency : module.getDependencies()) { dbModule.addDependency(dependency.getTarget().getGavc(), dependency.getScope()); } final StringBuilder sb = new StringBuilder(); for (final Module submodule : module.getSubmodules()) { final DbModule dbSubmodule = getDbModule(submodule); dbModule.addSubmodule(dbSubmodule); sb.setLength(0); } return dbModule; } 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 getDbModule(){ final Module module = DataModelFactory.createModule("root", "1.0.0-SNAPSHOT"); final Artifact artifact = DataModelFactory.createArtifact("com.axway.root", "artifact1", "1.0.0-SNAPSHOT", "win", "component", "jar"); module.addArtifact(artifact); final Artifact thirdparty = DataModelFactory.createArtifact("org.apache", "all", "6.8.0-5426", "", "", "jar"); final Dependency dependency = DataModelFactory.createDependency(thirdparty, Scope.COMPILE); module.addDependency(dependency); final Module submodule = DataModelFactory.createModule("sub1", "1.0.0-SNAPSHOT"); final Artifact artifact2 = DataModelFactory.createArtifact("com.axway.root.sub1", "artifactSub1", "1.0.0-SNAPSHOT", "", "", "jar"); submodule.addArtifact(artifact2); final Artifact thirdparty2 = DataModelFactory.createArtifact("org.lol", "all", "1.2.3-4", "", "", "jar"); final Dependency dependency2 = DataModelFactory.createDependency(thirdparty2, Scope.PROVIDED); submodule.addDependency(dependency2); module.addSubmodule(submodule); final ModelMapper modelMapper = new ModelMapper(mock(RepositoryHandler.class)); final DbModule dbModule = modelMapper.getDbModule(module); assertEquals(module.getName(), dbModule.getName()); assertEquals(module.getVersion(), dbModule.getVersion()); assertEquals(1, dbModule.getArtifacts().size()); assertEquals(artifact.getGavc(), dbModule.getArtifacts().get(0)); assertEquals(1, dbModule.getDependencies().size()); assertEquals(thirdparty.getGavc(), dbModule.getDependencies().get(0).getTarget()); assertEquals(DbModule.generateID(module.getName(), module.getVersion()), dbModule.getDependencies().get(0).getSource()); assertEquals(dependency.getScope(), dbModule.getDependencies().get(0).getScope()); assertEquals(1, dbModule.getSubmodules().size()); final DbModule dbSubmodule = dbModule.getSubmodules().get(0); assertEquals(submodule.getName() , dbSubmodule.getName()); assertEquals(submodule.getVersion(), dbSubmodule.getVersion()); assertEquals(1, dbSubmodule.getArtifacts().size()); assertEquals(artifact2.getGavc(), dbSubmodule.getArtifacts().get(0)); assertEquals(1, dbSubmodule.getDependencies().size()); assertEquals(thirdparty2.getGavc(), dbSubmodule.getDependencies().get(0).getTarget()); assertEquals(DbModule.generateID(submodule.getName(), submodule.getVersion()), dbSubmodule.getDependencies().get(0).getSource()); assertEquals(dependency2.getScope(), dbSubmodule.getDependencies().get(0).getScope()); }