blob: 21266a95797fe50eba0da9ca4aeb3bcfdbf4e84d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
package org.uic.barcode.ticket.api.test;
import java.text.ParseException;
import java.util.TimeZone;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.ticket.api.asn.omv3.IncludedOpenTicketType;
import org.uic.barcode.ticket.api.asn.omv3.OpenTicketData;
import org.uic.barcode.ticket.api.asn.omv3.PassengerType;
import org.uic.barcode.ticket.api.asn.omv3.TravelClassType;
import org.uic.barcode.ticket.api.asn.omv3.UicRailTicketData;
import org.uic.barcode.ticket.api.test.testtickets.OpenTestComplexTicketV3;
/**
* The Class FipTimeZoneTestV3.
*
*
*
*/
public class OpenTicketComplexTestV3 {
/** The ticket decoded 1. */
UicRailTicketData ticket = null;
byte[] encodedInTimeZone1 = null;
TimeZone defaulttimeZone = null;
/**
* Prepare tickets.
*/
@Before public void prepare() {
defaulttimeZone = TimeZone.getDefault();
//encode in UTC time zone
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
/**
* clean up
*/
@After public void resetTimeZone() {
TimeZone.setDefault(defaulttimeZone);
}
/**
* Test encode test tickets in UTC and decode in CET.
*
* @throws IllegalArgumentException the illegal argument exception
* @throws IllegalAccessException the illegal access exception
* @throws ParseException
*/
@Test public void decoding() {
//get tickets
String hex = OpenTestComplexTicketV3.getEncodingHex();
byte[] content = UperEncoder.bytesFromHexString(hex);
ticket = UperEncoder.decode(content, UicRailTicketData.class);
assert(ticket != null);
assert(ticket.getTransportDocument().get(0).getTicket().getOpenTicket() != null);
OpenTicketData ot = ticket.getTransportDocument().get(0).getTicket().getOpenTicket();
assert(ot.getReturnIncluded() == false);
assert(ot.getClassCode().equals(TravelClassType.first));
assert(ot.getInfoText().equals("openTicketInfo"));
assert(ot.getVatDetails().size() == 1);
assert(ot.getVatDetails().get(0).getCountry() == 80L);
assert(ot.getVatDetails().get(0).getPercentage() == 70L);
assert(ot.getVatDetails().get(0).getAmount() == 10L);
assert(ot.getVatDetails().get(0).getVatId().equals("IUDGTE"));
assert(ot.getIncludedAddOns().size() == 1);
IncludedOpenTicketType inc = ot.getIncludedAddOns().get(0);
assert(inc.getProductOwnerNum() == 1080L);
assert(inc.getClassCode().equals(TravelClassType.second));
assert(inc.getInfoText().equals("included ticket"));
assert(inc.getValidRegion().get(0).getZones() != null);
assert(inc.getValidRegion().get(0).getZones().getZoneId().get(0) == 100L);
assert(inc.getTariffs().size() == 1);
assert(inc.getTariffs().get(0).getNumberOfPassengers() == 2L);
assert(inc.getTariffs().get(0).getPassengerType().equals(PassengerType.adult));
assert(inc.getTariffs().get(0).getRestrictedToCountryOfResidence() == false);
assert(inc.getTariffs().get(0).getRestrictedToRouteSection().getFromStationNum() == 8000001L);
assert(inc.getTariffs().get(0).getRestrictedToRouteSection().getToStationNum() == 8010000L);
}
@Test public void encoding() throws IllegalArgumentException, IllegalAccessException, ParseException {
//get tickets
String hex = OpenTestComplexTicketV3.getEncodingHex();
byte[] content = UperEncoder.bytesFromHexString(hex);
ticket = UperEncoder.decode(content, UicRailTicketData.class);
//ticket = OpenTestComplexTicketV2.getUicTestTicket();
byte[] encoded = UperEncoder.encode(ticket);
assert(encoded != null);
assert(encoded.length > 20);
String encodedHex = UperEncoder.hexStringFromBytes(encoded);
String expectedHex = OpenTestComplexTicketV3.getEncodingHex();
assert(expectedHex.equals(encodedHex));
}
}
|