⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifiedselectortest.java

📁 java ant的源码!非常值得看的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        cache.put("key", "value");        cache.save();        assertTrue("Cachefile not created.", cachefile.exists());        cache.delete();        assertFalse("Cachefile not deleted.", cachefile.exists());    }    /** Checks whether a cache file is created. */    public void testCreatePropertiesCacheViaModifiedSelector() {        File cachefile = new File(basedir, "cachefile.properties");        try {            // initialize test environment (called "bed")            makeBed();            // Configure the selector            ModifiedSelector s = (ModifiedSelector)getSelector();            s.setDelayUpdate(false);            s.addParam("cache.cachefile", cachefile);            ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName();            cacheName.setValue("propertyfile");            s.setCache(cacheName);            s.setUpdate(true);            // does the selection            String results = selectionString(s);            // evaluate correctness            assertTrue("Cache file is not created.", cachefile.exists());        } finally {            cleanupBed();            if (cachefile!=null) cachefile.delete();        }    }    /**     * In earlier implementations there were problems with the <i>order</i>     * of the <param>s. The scenario was <pre>     *   <custom class="ModifiedSelector">     *       <param name="cache.cachefile" value="mycache.properties" />     *       <param name="cache" value="propertyfiles" />     *   </custom>     * </pre> It was important first to set the cache and then to set     * the cache's configuration parameters. That results in the reorganized     * configure() method of ModifiedSelector. This testcase tests that.     */    public void testCreatePropertiesCacheViaCustomSelector() {        File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null);        try {            // initialize test environment (called "bed")            makeBed();            // Configure the selector            ExtendSelector s = new ExtendSelector();            s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector");            s.addParam(createParam("update", "true"));            s.addParam(createParam("cache.cachefile", cachefile.getAbsolutePath()));            s.addParam(createParam("cache", "propertyfile"));            // does the selection            String results = selectionString(s);            // evaluate correctness            assertTrue("Cache file is not created.", cachefile.exists());        } finally {            cleanupBed();            if (cachefile!=null) cachefile.delete();        }    }    public void _testCustomCache() {        // same logic as on algorithm, no testcases created    }    /**     * Test the interface semantic of Caches.     * This method does some common test for cache implementations.     * A cache must return a stored value and a valid iterator.     * After calling the delete() the cache must be empty.     *     * @param algo   configured test object     */    protected void doTest(Cache cache) {        assertTrue("Cache not proper configured.", cache.isValid());        String key1   = "key1";        String value1 = "value1";        String key2   = "key2";        String value2 = "value2";        // given cache must be empty        Iterator it1 = cache.iterator();        assertFalse("Cache is not empty", it1.hasNext());        // cache must return a stored value        cache.put(key1, value1);        cache.put(key2, value2);        assertEquals("cache returned wrong value", value1, cache.get(key1));        assertEquals("cache returned wrong value", value2, cache.get(key2));        // test the iterator        Iterator it2 = cache.iterator();        Object   returned = it2.next();        boolean ok = (key1.equals(returned) || key2.equals(returned));        String msg = "Iterator returned unexpected value."                   + "  key1.equals(returned)="+key1.equals(returned)                   + "  key2.equals(returned)="+key2.equals(returned)                   + "  returned="+returned                   + "  ok="+ok;        assertTrue(msg, ok);        // clear the cache        cache.delete();        Iterator it3 = cache.iterator();        assertFalse("Cache is not empty", it1.hasNext());    }    // ==============  testcases for the algorithm implementations  ==============    public void testHashvalueAlgorithm() {        HashvalueAlgorithm algo = new HashvalueAlgorithm();        doTest(algo);    }    public void testDigestAlgorithmMD5() {        DigestAlgorithm algo = new DigestAlgorithm();        algo.setAlgorithm("MD5");        doTest(algo);    }    public void testDigestAlgorithmSHA() {        DigestAlgorithm algo = new DigestAlgorithm();        algo.setAlgorithm("SHA");        doTest(algo);    }    public void testChecksumAlgorithm() {        ChecksumAlgorithm algo = new ChecksumAlgorithm();        doTest(algo);    }    public void testChecksumAlgorithmCRC() {        ChecksumAlgorithm algo = new ChecksumAlgorithm();        algo.setAlgorithm("CRC");        doTest(algo);    }    public void testChecksumAlgorithmAdler() {        ChecksumAlgorithm algo = new ChecksumAlgorithm();        algo.setAlgorithm("Adler");        doTest(algo);    }    /**     * Test the interface semantic of Algorithms.     * This method does some common test for algorithm implementations.     * An algorithm must return always the same value for the same file and     * it must not return <i>null</i>.     *     * @param algo   configured test object     */    protected void doTest(Algorithm algo) {        assertTrue("Algorithm not proper configured.", algo.isValid());        try {            makeBed();            for (int i=0; i<files.length; i++) {                File file = files[i];  // must not be a directory                if (file.isFile()) {                    // get the Hashvalues                    String hash1 = algo.getValue(file);                    String hash2 = algo.getValue(file);                    String hash3 = algo.getValue(file);                    String hash4 = algo.getValue(file);                    String hash5 = algo.getValue(new File(file.getAbsolutePath()));                    // Assert !=null and equality                    assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash1);                    assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash2);                    assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash3);                    assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash4);                    assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash5);                    assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash2);                    assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash3);                    assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash4);                    assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash5);                }//if-isFile            }//for        } finally {            cleanupBed();        }    }    // ==============  testcases for the comparator implementations  ==============    public void testEqualComparator() {        EqualComparator comp = new EqualComparator();        doTest(comp);    }    public void testRuleComparator() {        RuleBasedCollator comp = (RuleBasedCollator)RuleBasedCollator.getInstance();        doTest(comp);    }    public void testEqualComparatorViaSelector() {        ModifiedSelector s = (ModifiedSelector)getSelector();        ModifiedSelector.ComparatorName compName = new ModifiedSelector.ComparatorName();        compName.setValue("equal");        s.setComparator(compName);        try {            performTests(s, "TTTTTTTTTTTT");        } finally {            s.getCache().delete();        }    }    public void _testRuleComparatorViaSelector() { //not yet supported see note in selector        ModifiedSelector s = (ModifiedSelector)getSelector();        ModifiedSelector.ComparatorName compName = new ModifiedSelector.ComparatorName();        compName.setValue("rule");        s.setComparator(compName);        try {            performTests(s, "TTTTTTTTTTTT");        } finally {            s.getCache().delete();        }    }    public void _testCustomComparator() {        // same logic as on algorithm, no testcases created    }    public void testResourceSelectorSimple() {        BFT bft = new BFT("modifiedselector");        bft.doTarget("modifiedselectortest-ResourceSimple");        bft.deleteCachefile();        //new File("src/etc/testcases/types/resources/selectors/cache.properties").delete();    }    public void testResourceSelectorSelresTrue() {        BFT bft = new BFT("modifiedselector");        bft.doTarget("modifiedselectortest-ResourceSelresTrue");        bft.assertLogContaining("does not provide an InputStream");        bft.deleteCachefile();    }    public void testResourceSelectorSelresFalse() {        BFT bft = new BFT("modifiedselector");        bft.doTarget("modifiedselectortest-ResourceSelresFalse");        bft.deleteCachefile();    }    public void testResourceSelectorScenarioSimple() {        BFT bft = new BFT("modifiedselector");        bft.doTarget("modifiedselectortest-scenario-resourceSimple");        bft.doTarget("modifiedselectortest-scenario-clean");        bft.deleteCachefile();    }    /**     * Test the interface semantic of Comparators.     * This method does some common test for comparator implementations.     *     * @param algo   configured test object     */    protected void doTest(Comparator comp) {        Object o1 = new String("string1");        Object o2 = new String("string2");        Object o3 = new String("string2"); // really "2"        assertTrue("Comparator gave wrong value.", comp.compare(o1, o2) != 0);        assertTrue("Comparator gave wrong value.", comp.compare(o1, o3) != 0);        assertTrue("Comparator gave wrong value.", comp.compare(o2, o3) == 0);    }    // =====================  scenario tests  =====================    /**     * Tests whether the seldirs attribute is used.     */    public void testSeldirs() {        ModifiedSelector s = (ModifiedSelector)getSelector();        try {            makeBed();            StringBuffer sbTrue  = new StringBuffer();            StringBuffer sbFalse = new StringBuffer();            for (int i=0; i<filenames.length; i++) {                if (files[i].isDirectory()) {                    sbTrue.append("T");                    sbFalse.append("F");                } else {                    sbTrue.append("T");                    sbFalse.append("T");                }            }            s.setSeldirs(true);            performTests(s, sbTrue.toString());            s.getCache().delete();            s.setSeldirs(false);            performTests(s, sbFalse.toString());            s.getCache().delete();        } finally {            cleanupBed();            if (s!=null) s.getCache().delete();        }    }    /**     * Complex test scenario using default values (DigestAlgorithm with MD5,     * PropertiesfileCache with file=cache.properties, EqualComparator     * and update=true). <ol>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -