Subpackages implements ProgressCheckFactory { @Override public ProgressCheck newInstance(final JsonObject config) { List<Rule> rules = Rules.fromJsonArray(arrayOrEmpty(config, keys().rules())); final boolean denyAll = hasNonNull(config, keys().denyAll()) && config.getBoolean(keys().denyAll()); return new Check(rules, denyAll); }  @NotNull static JsonKeys keys(); @Override ProgressCheck newInstance(final JsonObject config); @Deprecated
    static final String CONFIG_RULES; @Deprecated
    static final String CONFIG_DENY_ALL; }
@Test public void testDenyAll() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance(key("denyAll", false).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("denyAll:false", report); Assert.assertEquals("no violations", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance(key("denyAll", true).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("denyAll:false", report); Assert.assertEquals("two violations", 2, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }
@Test public void testPatterns() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance(key("rules", arr()).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("testPatterns:[]", report); Assert.assertEquals("no violations", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance( key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_.*"))).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("testPatterns:sub_.*", report); Assert.assertEquals("two violations", 2, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance( key("rules", arr() .val(key("type", "deny").key("pattern", "my_packages:sub_.*")) .val(key("type", "allow").key("pattern", "my_packages:sub_a")) ).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("testPatterns:sub_.* - sub_a", report); Assert.assertEquals("one violation", 1, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance( key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_a"))).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("testPatterns:sub_a", report); Assert.assertEquals("one violation", 1, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance( key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_b"))).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("testPatterns:sub_b", report); Assert.assertEquals("one violation", 1, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck check = new Subpackages().newInstance( key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_c"))).get()); CheckReport report = scanWithCheck(check, "subtest_with_content.zip"); logViolations("testPatterns:sub_c", report); Assert.assertEquals("one violation", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }