View Javadoc

1   /*
2    * Copyright (C) 2007 ETH Zurich
3    *
4    * This file is part of Fosstrak (www.fosstrak.org).
5    *
6    * Fosstrak is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License version 2.1, as published by the Free Software Foundation.
9    *
10   * Fosstrak is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with Fosstrak; if not, write to the Free
17   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18   * Boston, MA  02110-1301  USA
19   */
20  
21  package org.fosstrak.epcis.repository.capture;
22  
23  import junit.framework.TestCase;
24  
25  import org.fosstrak.epcis.repository.InvalidFormatException;
26  
27  /**
28   * Tests some features of the CaptureOperationsModule class.
29   * <p>
30   * TODO: add more tests
31   * 
32   * @author Marco Steybe
33   */
34  public class CaptureOperationsModuleTest extends TestCase {
35  
36      static {
37          // provide the catalina.base property which is not available when the
38          // application is not deployed, i.e., when running tests
39          if (System.getenv("CATALINA_HOME") != null) {
40              System.setProperty("catalina.base", System.getenv("CATALINA_HOME"));
41          }
42      }
43      private static CaptureOperationsModule module = new CaptureOperationsModule();
44  
45      public void testCheckEventTimeZoneOffset() throws InvalidFormatException {
46          assertEquals(module.checkEventTimeZoneOffset("+05:30"), "+05:30");
47          assertEquals(module.checkEventTimeZoneOffset("-00:00"), "-00:00");
48          assertEquals(module.checkEventTimeZoneOffset("+14:00"), "+14:00");
49          try {
50              module.checkEventTimeZoneOffset("+14:30");
51              fail("InvalidFormatException expected");
52          } catch (InvalidFormatException e) {
53          }
54          try {
55              module.checkEventTimeZoneOffset("-16:30");
56              fail("InvalidFormatException expected");
57          } catch (InvalidFormatException e) {
58          }
59          try {
60              module.checkEventTimeZoneOffset("-05:87");
61              fail("InvalidFormatException expected");
62          } catch (InvalidFormatException e) {
63          }
64      }
65  
66      public void testCheckCommonEpcs() throws InvalidFormatException {
67          module.checkEpc("urn:epc:id:sgtin:0652642.800031.400");
68          module.checkEpc("urn:epc:id:sscc:0652642.0123456789");
69          module.checkEpc("urn:epc:id:sgln:0652642.12345.40");
70          module.checkEpc("urn:epc:id:sgln:0652642.12345.0");
71          module.checkEpc("urn:epc:id:grai:0652642.12345.1234");
72          module.checkEpc("urn:epc:id:giai:0652642.123456");
73      }
74  
75      public void testCheckValidEpcs() throws InvalidFormatException {
76          module.checkEpc("urn:epc:id:sgtin:0.0.%AB-+:judihui");
77      }
78  
79      public void testCheckInvalidEpcs() throws InvalidFormatException {
80          try {
81              module.checkEpc("urn:epc:id:gid:1652642.800031.400.123");
82              fail("InvalidFormatException expected");
83          } catch (InvalidFormatException e) {
84          }
85          try {
86              module.checkEpc("urn:epc:id:sgtin:0652642.800031.");
87              fail("InvalidFormatException expected");
88          } catch (InvalidFormatException e) {
89          }
90          try {
91              module.checkEpc("urn:epc:id:sgtin:0652642");
92              fail("InvalidFormatException expected");
93          } catch (InvalidFormatException e) {
94          }
95          try {
96              module.checkEpc("urn:epc:id:sgtin:0652642.800A031.400");
97              fail("InvalidFormatException expected");
98          } catch (InvalidFormatException e) {
99          }
100         try {
101             module.checkEpc("urn:epc:id:1234:0652642.800031.400");
102             fail("InvalidFormatException expected");
103         } catch (InvalidFormatException e) {
104         }
105         try {
106             module.checkEpc("urn:epc:ident:sgtin:0652642.800031.400");
107             fail("InvalidFormatException expected");
108         } catch (InvalidFormatException e) {
109         }
110         try {
111             module.checkEpc("urn.epc.id:sgtin:0652642.800031.400");
112             fail("InvalidFormatException expected");
113         } catch (InvalidFormatException e) {
114         }
115     }
116 }