ArtifactHandler { public DbOrganization getOrganization(final DbArtifact dbArtifact) { final DbModule module = getModule(dbArtifact); if(module == null || module.getOrganization() == null){ return null; } return repositoryHandler.getOrganization(module.getOrganization()); } ArtifactHandler(final RepositoryHandler repositoryHandler,
                           final LicenseMatcher matcher); void store(final DbArtifact dbArtifact); void storeIfNew(final DbArtifact fromClient); void addLicense(final String gavc, final String licenseId); List<String> getArtifactGavcs(final FiltersHolder filters); List<String> getArtifactGroupIds(final FiltersHolder filters); List<String> getArtifactVersions(final String gavc); String getArtifactLastVersion(final String gavc); DbArtifact getArtifact(final String gavc); DbArtifact getArtifactUsingSHA256(final String sha256); DbModule getModule(final DbArtifact dbArtifact); DbOrganization getOrganization(final DbArtifact dbArtifact); void updateDownLoadUrl(final String gavc, final String downLoadUrl); void updateProvider(final String gavc, final String provider); void deleteArtifact(final String gavc); void updateDoNotUse(final String gavc, final Boolean doNotUse); List<DbModule> getAncestors(final String gavc, final FiltersHolder filters); List<DbLicense> getArtifactLicenses(final String gavc, final FiltersHolder filters); void addLicenseToArtifact(final String gavc, final String licenseId); void removeLicenseFromArtifact(final String gavc, final String licenseId); List<DbArtifact> getArtifacts(final FiltersHolder filters); String getModuleJenkinsJobInfo(final DbArtifact dbArtifact);  }
@Test public void getTheOrganizationOfAnArtifactThatDoesNotHaveModule(){ final DbArtifact artifact = new DbArtifact(); artifact.setArtifactId("test"); artifact.setVersion("1.0.0-SNAPSHOT"); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final ArtifactHandler handler = new ArtifactHandler(repositoryHandler, mock(LicenseMatcher.class)); final DbOrganization organization = handler.getOrganization(artifact); assertNull(organization); }
@Test public void getTheOrganizationOfAnArtifactWhichIsInAModuleThatDoesNotHaveOrganization(){ final DbArtifact artifact = new DbArtifact(); artifact.setArtifactId("test"); artifact.setVersion("1.0.0-SNAPSHOT"); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getRootModuleOf(artifact.getGavc())).thenReturn(new DbModule()); final ArtifactHandler handler = new ArtifactHandler(repositoryHandler, mock(LicenseMatcher.class)); final DbOrganization organization = handler.getOrganization(artifact); assertNull(organization); }
@Test public void getTheOrganizationOfAnArtifactWhichIsInAModuleThatHasAnOrganization(){ final DbArtifact artifact = new DbArtifact(); artifact.setArtifactId("test"); artifact.setVersion("1.0.0-SNAPSHOT"); final DbOrganization organization = new DbOrganization(); organization.setName("Test Organization"); final DbModule module = new DbModule(); module.setOrganization(organization.getName()); final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); when(repositoryHandler.getRootModuleOf(artifact.getGavc())).thenReturn(module); when(repositoryHandler.getOrganization(organization.getName())).thenReturn(organization); final ArtifactHandler handler = new ArtifactHandler(repositoryHandler, mock(LicenseMatcher.class)); final DbOrganization gotOrganization = handler.getOrganization(artifact); assertNotNull(gotOrganization); assertEquals(organization, gotOrganization); }