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.test;
22  
23  import java.io.ByteArrayInputStream;
24  import java.io.IOException;
25  
26  import junit.framework.TestCase;
27  
28  import org.fosstrak.epcis.captureclient.CaptureClient;
29  import org.fosstrak.epcis.queryclient.QueryControlClient;
30  
31  /**
32   * This Test first inserts two events each containing two fieldname extensions
33   * into the EPCIS Repository. It then sends a query asking for all events with a
34   * fieldname extension greater the given value. If everything works as expected,
35   * we have correctly inserted the event extension with the correct data type
36   * into the database.
37   * 
38   * @author Marco Steybe
39   */
40  public class EventFieldExtensionTest extends TestCase {
41  
42      private static String event1 = null;
43      private static String event2 = null;
44      private static String query = null;
45  
46      /**
47       * Tests event fieldname extensions.
48       * 
49       * @throws Exception
50       *             Any exception, caught by the JUnit framework.
51       */
52      public void testExtension() throws Exception {
53  
54          // send event1
55          CaptureClient captureClient = new CaptureClient();
56          int resp = captureClient.capture(event1);
57          assertEquals(200, resp);
58  
59          // send event2
60          resp = captureClient.capture(event2);
61          assertEquals(200, resp);
62  
63          // send query
64          QueryControlClient queryClient = new QueryControlClient();
65          queryClient.poll(new ByteArrayInputStream(query.getBytes()));
66  
67          // TODO check response!
68      }
69  
70      /**
71       * @see junit.framework.TestCase#setUp()
72       */
73      public void setUp() throws IOException {
74          StringBuilder sb = new StringBuilder();
75          sb
76                  .append("<epcis:EPCISDocument xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\" xmlns:epcglobal=\"urn:epcglobal:xsd:1\" xsi:schemaLocation=\"urn:epcglobal:epcis:xsd:1 EPCglobal-epcis-1_0.xsd\" xmlns:hls=\"http://schema.hls.com/extension\" creationDate=\"2006-06-25T00:00:00Z\" schemaVersion=\"1.0\">");
77          sb.append("<EPCISBody>");
78          sb.append("<EventList>");
79          sb.append("<ObjectEvent>");
80          sb.append("<eventTime>2006-06-25T00:01:00Z</eventTime>");
81          sb.append("<eventTimeZoneOffset>-06:00</eventTimeZoneOffset>");
82          sb.append("<epcList>");
83          sb.append("<epc>urn:epc:id:sgtin:0614141.107340.1</epc>");
84          sb.append("</epcList>");
85          sb.append("<action>ADD</action>");
86          sb.append("<bizStep>urn:epcglobal:hls:bizstep:commissioning</bizStep>");
87          sb.append("<disposition>urn:epcglobal:hls:disp:active</disposition>");
88          sb.append("<readPoint>");
89          sb.append("<id>urn:epcglobal:fmcg:loc:0614141073467.RP-1</id>");
90          sb.append("</readPoint>");
91          sb.append("<bizLocation>");
92          sb.append("<id>urn:epcglobal:fmcg:loc:0614141073467.1</id>");
93          sb.append("</bizLocation>");
94          sb.append("<hls:temperature>49</hls:temperature>");
95          sb.append("<hls:batchNumber>2</hls:batchNumber>");
96          sb.append("</ObjectEvent>");
97          sb.append("</EventList>");
98          sb.append("</EPCISBody>");
99          sb.append("</epcis:EPCISDocument>");
100         event1 = sb.toString();
101 
102         sb = new StringBuilder();
103         sb
104                 .append("<epcis:EPCISDocument xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\" xmlns:epcglobal=\"urn:epcglobal:xsd:1\" xsi:schemaLocation=\"urn:epcglobal:epcis:xsd:1 EPCglobal-epcis-1_0.xsd\" xmlns:hls=\"http://schema.hls.com/extension\" creationDate=\"2006-06-25T00:00:00Z\" schemaVersion=\"1.0\">");
105         sb.append("<EPCISBody>");
106         sb.append("<EventList>");
107         sb.append("<ObjectEvent>");
108         sb.append("<eventTime>2006-06-25T00:01:00Z</eventTime>");
109         sb.append("<eventTimeZoneOffset>-06:00</eventTimeZoneOffset>");
110         sb.append("<epcList>");
111         sb.append("<epc>urn:epc:id:sgtin:0614141.107340.1</epc>");
112         sb.append("</epcList>");
113         sb.append("<action>ADD</action>");
114         sb.append("<bizStep>urn:epcglobal:hls:bizstep:commissioning</bizStep>");
115         sb.append("<disposition>urn:epcglobal:hls:disp:active</disposition>");
116         sb.append("<readPoint>");
117         sb.append("<id>urn:epcglobal:fmcg:loc:0614141073467.RP-1</id>");
118         sb.append("</readPoint>");
119         sb.append("<bizLocation>");
120         sb.append("<id>urn:epcglobal:fmcg:loc:0614141073467.1</id>");
121         sb.append("</bizLocation>");
122         sb.append("<hls:temperature>48</hls:temperature>");
123         sb.append("<hls:batchNumber>2</hls:batchNumber>");
124         sb.append("</ObjectEvent>");
125         sb.append("</EventList>");
126         sb.append("</EPCISBody>");
127         sb.append("</epcis:EPCISDocument>");
128         event2 = sb.toString();
129 
130         sb = new StringBuilder();
131         sb.append("<epcisq:poll xmlns:epcisq=\"urn:epcglobal:epcis-query:xsd:1\">");
132         sb.append("<queryName>SimpleEventQuery</queryName>");
133         sb.append("<params>");
134         sb.append("<param>");
135         sb.append("<name>GT_http://schema.hls.com/extension#temperature</name>");
136         sb.append("<value>48</value>");
137         sb.append("</param>");
138         sb.append("</params>");
139         sb.append("</epcisq:poll>");
140         query = sb.toString();
141 
142         sb = new StringBuilder();
143         sb.append("<ObjectEvent>\n");
144         sb.append("  <eventTime>2006-06-25T00:01:00.000Z</eventTime>\n");
145         sb.append("  <recordTime>2006-12-14T13:41:28.000Z</recordTime>\n");
146         sb.append("  <eventTimeZoneOffset>-06:00</eventTimeZoneOffset>\n");
147         sb.append("  <epcList/>\n");
148         sb.append("  <action>ADD</action>\n");
149         sb.append("  <bizStep>urn:epcglobal:hls:bizstep:commissioning</bizStep>\n");
150         sb.append("  <disposition>urn:epcglobal:hls:disp:active</disposition>\n");
151         sb.append("  <readPoint><id>urn:epcglobal:fmcg:loc:0614141073467.RP-1</id></readPoint>\n");
152         sb.append("  <bizLocation><id>urn:epcglobal:fmcg:loc:0614141073467.1</id></bizLocation>\n");
153         sb.append("  <bizTransactionList/>\n");
154         sb.append("  <hls:temperature xmlns:hls=\"http://schema.hls.com/extension\">49</hls:temperature>\n");
155         sb.append("  <hls:batchNumber xmlns:hls=\"http://schema.hls.com/extension\">2</hls:batchNumber>\n");
156         sb.append("</ObjectEvent>");
157     }
158 
159     /**
160      * @see junit.framework.TestCase#tearDown()
161      */
162     @Override
163     protected void tearDown() throws Exception {
164         // reset the database
165         new CaptureClient().dbReset();
166     }
167 }