@Override public boolean accept(Environment env) { if (!includes.isEmpty()) { return matches(includes, getRestrictedValue(env)); } else if (!excludes.isEmpty()) { return !matches(excludes, getRestrictedValue(env)); } else { return true; } }
private void assertRestrictions(Class<? extends ArtifactRestrictions> type, ImmutableList<ArtifactRestrictions> expected, ChangeInput actual) { assertEquals(getRestrictionsByType(type, expected).getIncludes(), getRestrictionsByType(type, actual.getRestrictions()).getIncludes()); assertEquals(getRestrictionsByType(type, expected).getExcludes(), getRestrictionsByType(type, actual.getRestrictions()).getExcludes()); }
private void assertTest(boolean result, final String platformName, final MutableSet<String> includes, final MutableSet<String> excludes) { Environment env = new Environment(); Platform platform = mock(Platform.class); when(platform.getName()).thenReturn(platformName); env.setPlatform(platform); Restrictable restrictable = new Restrictable() { @Override public ImmutableList<ArtifactRestrictions> getRestrictions() { return Lists.immutable.<ArtifactRestrictions>of(new ArtifactPlatformRestrictions(includes, excludes)); } }; Assert.assertEquals(result, ArtifactRestrictions.apply().accept(restrictable, env)); } }
@Test public void testIncludeEnvs() { ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf( this.doc(TextMarkupDocumentReader.TAG_METADATA, null, Maps.immutable.with("includeEnvs", "dev1,dev3")) ); assertEquals(1, restrictions.size()); assertThat(restrictions.getFirst(), instanceOf(ArtifactEnvironmentRestrictions.class)); assertEquals(UnifiedSet.newSetWith("dev1", "dev3"), restrictions.getFirst().getIncludes()); assertTrue(restrictions.getFirst().getExcludes().isEmpty()); }
private void assertTest(boolean result, String envName, final MutableSet<String> includes, final MutableSet<String> excludes) { Environment env = new Environment(); env.setName(envName); Restrictable restrictable = new Restrictable() { @Override public ImmutableList<ArtifactRestrictions> getRestrictions() { return Lists.immutable.<ArtifactRestrictions>of(new ArtifactEnvironmentRestrictions(includes, excludes)); } }; Assert.assertEquals(result, ArtifactRestrictions.apply().accept(restrictable, env)); } }
@Test public void testIncludeEnvsExcludePlatforms() { ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf( this.doc(TextMarkupDocumentReader.TAG_METADATA, null, Maps.immutable.with( "includeEnvs", "dev1,dev3", "excludePlatforms", "HSQL,HIVE")) ); assertEquals(2, restrictions.size()); assertThat(restrictions.getFirst(), instanceOf(ArtifactEnvironmentRestrictions.class)); assertEquals(UnifiedSet.newSetWith("dev1", "dev3"), restrictions.getFirst().getIncludes()); assertTrue(restrictions.getFirst().getExcludes().isEmpty()); assertThat(restrictions.getLast(), instanceOf(ArtifactPlatformRestrictions.class)); assertTrue(restrictions.getLast().getIncludes().isEmpty()); assertEquals(UnifiedSet.newSetWith("HSQL", "HIVE"), restrictions.getLast().getExcludes()); } }
@Override public boolean accept(Environment env) { if (!includes.isEmpty()) { return matches(includes, getRestrictedValue(env)); } else if (!excludes.isEmpty()) { return !matches(excludes, getRestrictedValue(env)); } else { return true; } }
@Test public void testExcludeEnvs() { ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf( this.doc(TextMarkupDocumentReader.TAG_METADATA, null, Maps.immutable.with("excludeEnvs", "dev1,dev3")) ); assertEquals(1, restrictions.size()); assertThat(restrictions.getFirst(), instanceOf(ArtifactEnvironmentRestrictions.class)); assertEquals(UnifiedSet.newSetWith("dev1", "dev3"), restrictions.getFirst().getExcludes()); assertTrue(restrictions.getFirst().getIncludes().isEmpty()); }
@Test public void testIncludePlatforms() { ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf( this.doc(TextMarkupDocumentReader.TAG_METADATA, null, Maps.immutable.with("includePlatforms", "DB2,SYBASE_ASE")) ); assertEquals(1, restrictions.size()); assertThat(restrictions.getFirst(), instanceOf(ArtifactPlatformRestrictions.class)); assertEquals(UnifiedSet.newSetWith("DB2", "SYBASE_ASE"), restrictions.getFirst().getIncludes()); assertTrue(restrictions.getFirst().getExcludes().isEmpty()); }
@Test public void testExcludePlatforms() { ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf( this.doc(TextMarkupDocumentReader.TAG_METADATA, null, Maps.immutable.with("excludePlatforms", "HSQL,HIVE")) ); assertEquals(1, restrictions.size()); assertEquals(UnifiedSet.newSetWith("HSQL", "HIVE"), restrictions.getFirst().getExcludes()); assertTrue(restrictions.getFirst().getIncludes().isEmpty()); }