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

📄 epctypefiltertest.java

📁 SUnRDIS网络应用平台,可以在该平台上开发RFID应用,系统.
💻 JAVA
字号:
/* * EPCTypeFilterTest.java * * Created on December 15, 2005, 2:29 PM */package com.sun.rfid.filter;import com.sun.autoid.ems.*;import com.sun.autoid.event.*;import java.util.*;import java.util.logging.*;import java.net.*;import java.io.*;import java.rmi.RemoteException;import java.text.MessageFormat;import javax.management.*;import com.sun.autoid.util.*;import junit.framework.*;import com.sun.autoid.identity.*;import org.xml.sax.*;import org.w3c.dom.*;/* * Junit testing code for the com.sun.rfid.filter.EPCTypeFilter filter. */public class EPCTypeFilterTest extends TestCase {    /**     * The default log level.     */    public static final String LOGLEVEL_TEST = "FINEST";        /**     * The name of the reader to use in the IdentifierEvents.     */    public static final String READER   = "Feig";        /**     * Tags to be tested.  Simply add or remove tags in this list to modify the     * specific tags or the number of tags being tested.     */    private String[] tags = {"urn:epc:tag:giai-64:7.0614141.2",            "urn:epc:tag:giai-96:7.0614141.2",            "urn:epc:tag:grai-64:7.1234567.00734.2",            "urn:epc:tag:grai-96:7.0614141.000734.2",            "urn:epc:tag:sgln-64:7.1234567.10734.2",            "urn:epc:tag:sgln-96:7.0614141.10734.2",            "urn:epc:tag:sgtin-64:7.1234567.100734.2",            "urn:epc:tag:sgtin-96:7.0614141.100734.2",            "urn:epc:tag:sscc-64:7.0614141.0000000002",            "urn:epc:tag:sscc-96:7.0614141.0000000002",            "urn:epc:tag:gid-64-1:10.1002.1",            "urn:epc:tag:gid-64-3:10.1002.1",            "urn:epc:tag:gid-96:10.1002.20"};                        /**             * Company lookup table.  Required for creating EPCs.             */            public static final String companyLookupXML =                    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?>\n" +                    "<GEPC64Table date=\"2004-04-12T15:34:58-05:00\" >\n" +                    "    <entry index=\"1\" companyPrefix=\"000001\" />\n" +                    "    <entry index=\"2\" companyPrefix=\"52642\" />\n" +                    "    <entry index=\"3\" companyPrefix=\"00712\" />\n" +                    "    <entry index=\"4\" companyPrefix=\"1234567\" />\n" +                    "    <entry index=\"6\" companyPrefix=\"000123\" />\n" +                    "    <entry index=\"7\" companyPrefix=\"0614141\" />\n" +                    "</GEPC64Table>\n\n";                        /**             * A StringReader for parsing the company lookup.             */            private StringReader companyLookupXMLReader;                        /**             * A table for looking up the table.             */            private CompanyLookupTable lookup;                        /**             * The filter being tested.             */            private EPCTypeFilter filter = null;                        /**             * The properties object used to initialize the filter.             */            private Properties props = null;                        /**             * Instantiate a new unit test with the specified name.             *             * @param testName the name of the test             */            public EPCTypeFilterTest(java.lang.String testName) {                super(testName);            }                        /**             * Get the test suite for this unit test.             *             * @return the test suite             */            public static Test suite() {                TestSuite suite = new TestSuite(EPCTypeFilterTest.class);                return suite;            }                        /**             * Sets up the test fixture. Called before every test case method.             */            protected void setUp() {                this.props = new Properties();                this.props.put("LogLevel", LOGLEVEL_TEST);                this.props.put("EPCTypes", "SGLN,SSCC");                this.props.put("EPCSizes", "96,64");                                try {                    this.filter = new EPCTypeFilter(props);                    this.filter.startup();                } catch (Exception ex) {                    fail("Creation of EPCTypeFilter Filter should not fail in setUp()");                    ex.printStackTrace();                }                                try {                    companyLookupXMLReader = new StringReader(companyLookupXML);                    lookup = CompanyLookupTable.createInstance(new InputSource(companyLookupXMLReader));                } catch(Exception ex) {                    ex.printStackTrace();                    this.fail(ex.getMessage());                }            }                        /**             * Tears down the test fixture.  Called after every test case method.             */            protected void tearDown() {                this.filter.shutdown();                props = null;                this.filter = null;            }                        /**             * Test of getLogLevel method, of class com.sun.rfid.filter.EPCTypeFilter.             */            public void testLogLevel() {                String oldLogLevel = filter.getLogLevel();                assertEquals(oldLogLevel, "FINEST");                filter.setLogLevel("INFO");                assertEquals(filter.getLogLevel(), "INFO");                filter.setLogLevel(oldLogLevel);            }                        /**             * Test the processing of events.  This method should be modified to send             * interesting events to the filter and ensure that the appropriate events             * get filtered or modified properly.             */            public void testProcessIdentifierEvent() {                this.filter.reset();                int tagCount = this.tags.length;                long timestamp = System.currentTimeMillis();                try {                    for (int index = 0; index < tagCount; index++) {                        Identifier identifier = IdentifierFactory.createEPC(new URI(this.tags[index]));                        IdentifierEvent event = new IdentifierEvent(identifier,                                READER, timestamp, "IdentifierEvent from " + READER);                        this.filter.postEvent(event);                    }                } catch (Exception e) {                    fail("Unexpected failure of EPC creation");                }                /**                 * Wait for the identifiers to be processed.                 */                this.pause(1000);                assertEquals("Expected 4 identifiers", 4,                        this.filter.getPassCount());            }                        /**             * Test to ensure that the EPCTypeFilter filter can handle events of type             * IdentifierListEvent.             */            public void testProcessIdentifierListEvent() {                this.filter.reset();                int tagCount = this.tags.length;                long timestamp = System.currentTimeMillis();                try {                    IdentifierListEvent event = new IdentifierListEvent(READER, timestamp,                            "IdentifierListEvent from " + READER);                    for (int index = 0; index < tagCount; index++) {                        Identifier identifier = IdentifierFactory.createEPC(new URI(this.tags[index]));                        event.addIdentifier(identifier);                    }                    this.filter.postEvent(event);                } catch (Exception e) {                    fail("Unexpected failure of EPC creation");                }                /**                 * Wait for the identifiers to be processed.                 */                this.pause(1000);                assertEquals("Expected 4 identifiers", 4,                        this.filter.getPassCount());            }                        /**             * Test to ensure that the EPCTypeFilter filter can handle events of type             * DeltaEvent.             */            public void testProcessDeltaEvent() {                this.filter.reset();                int tagCount = this.tags.length;                long timestamp = System.currentTimeMillis();                try {                    DeltaEvent event = new DeltaEvent(READER, timestamp,                            "DeltaEvent from " + READER);                    Collection tagsIn = new LinkedList();                    Collection tagsOut = new LinkedList();                    for (int index = 0; index < tagCount; index++) {                        Identifier identifier = IdentifierFactory.createEPC(new URI(this.tags[index]));                        /*                         * Even index identifiers into tagsIn; odd into tagsOut.                         */                        if (index % 2 == 0) {                            tagsIn.add(identifier);                        } else {                            tagsOut.add(identifier);                        }                    }                    event.setTagsIn(tagsIn);                    event.setTagsOut(tagsOut);                    this.filter.postEvent(event);                } catch (Exception e) {                    fail("Unexpected failure of EPC creation");                }                /**                 * Wait for the identifiers to be processed.                 */                this.pause(1000);                assertEquals("Expected 4 identifiers", 4,                        this.filter.getPassCount());            }                        /**             * Pause the current thread.             *             * @param time the suggested time to pause (in milliseconds)             */            private void pause(int time) {                try {                    Thread.sleep(time);                } catch (InterruptedException ignored) {}            }                        /**             * The main method invokes the test harness.             */            public static void main(String args[]) {                junit.textui.TestRunner.run(EPCTypeFilterTest.class);            }            }

⌨️ 快捷键说明

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