CorporateFilter implements Filter { @Override public boolean filter(final Object datamodelObj) { if(datamodelObj instanceof DbModule){ return matches((DbModule) datamodelObj); } if(datamodelObj instanceof DbArtifact){ return matches((DbArtifact)datamodelObj); } if(datamodelObj instanceof DbDependency){ return matches((DbDependency)datamodelObj); } return false; } CorporateFilter(final DbOrganization organization); @Override boolean filter(final Object datamodelObj); boolean matches(final DbModule module); boolean matches(final DbArtifact artifact); boolean matches(final DbDependency dependency); @Override Map<String, Object> moduleFilterFields(); @Override Map<String, Object> artifactFilterFields(); DBRegExp getMongoRegExp();  }
@Test public void checkFilterModuleThatHasNoArtifactAndWhichIsNotCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbModule module = new DbModule(); module.setName("module"); module.setVersion("1.0.0"); assertFalse(filter.filter(module)); }
@Test public void checkFilterModuleThatHasNoArtifactAndWhichIsCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbModule module = new DbModule(); module.setName(GrapesTestUtils.CORPORATE_GROUPID_4TEST+":module"); module.setVersion("1.0.0"); assertTrue(filter.filter(module)); }
@Test public void checkFilterModuleWithAnArtifactAndWhichIsNotCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbModule module = new DbModule(); module.setName("module"); module.setVersion("1.0.0"); module.getArtifacts().add("org.apache.something.module:test:1.0.0::jar"); assertFalse(filter.filter(module)); }
@Test public void checkFilterModuleWithAnArtifactAndWhichIsCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbModule module = new DbModule(); module.setName("module"); module.setVersion("1.0.0"); module.getArtifacts().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST + ".module:test:1.0.0::jar"); assertTrue(filter.filter(module)); }
@Test public void checkFilterArtifactWhichIsNotCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbArtifact artifact = new DbArtifact(); artifact.setGroupId("org.apache.something"); assertFalse(filter.filter(artifact)); }
@Test public void checkFilterArtifactWhichIsCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbArtifact artifact = new DbArtifact(); artifact.setGroupId(GrapesTestUtils.CORPORATE_GROUPID_4TEST); assertTrue(filter.filter(artifact)); }
@Test public void checkFilterDependencyWhichIsNotCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbDependency dependency = new DbDependency(); dependency.setTarget("com.company.all:test:1.0.0::"); assertFalse(filter.filter(dependency)); }
@Test public void checkFilterDependencyWhichIsCorporate(){ final DbOrganization organization = new DbOrganization(); organization.setName("testOrganization"); organization.getCorporateGroupIdPrefixes().add(GrapesTestUtils.CORPORATE_GROUPID_4TEST); final CorporateFilter filter = new CorporateFilter(organization); final DbDependency dependency = new DbDependency(); dependency.setTarget(GrapesTestUtils.CORPORATE_GROUPID_4TEST + ":test:1.0.0::"); assertTrue(filter.filter(dependency)); }