summaryrefslogtreecommitdiffstats
path: root/src/org/uic/barcode/ticket/api/test/UperEncodePassTestV1.java
blob: 7436f5de4a4851e853f208532a9a410261fe0711 (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
package org.uic.barcode.ticket.api.test;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.logging.Level;

import org.junit.Test;
import org.uic.barcode.asn1.uper.UperEncoder;
import org.uic.barcode.ticket.EncodingFormatException;
import org.uic.barcode.ticket.api.asn.omv1.UicRailTicketData;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
import org.uic.barcode.ticket.api.test.testtickets.PassTestTicketV1;
import org.uic.barcode.ticket.api.utils.Api2OpenAsnEncoder;
import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder;


public class UperEncodePassTestV1 {

    
	@Test public void testDecodeTicket() throws IllegalArgumentException, IllegalAccessException {
    	UicRailTicketData ticket =  PassTestTicketV1.getUicTestTicket();
        byte[] encoded = UperEncoder.encode(ticket);
        String hex = UperEncoder.hexStringFromBytes(encoded);
        UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));

        UicRailTicketData decodedTicket  = UperEncoder.decode(encoded, UicRailTicketData.class);
        
        OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder();
        IUicRailTicket iTicket = null;
        try {
        	iTicket = decoder.decodeFromAsn(encoded);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        Api2OpenAsnEncoder encoder = new Api2OpenAsnEncoder();
        try {
        	encoded = encoder.encode(iTicket);
		} catch (EncodingFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        assert(decodedTicket != null);
        assertEquals(decodedTicket.controlDetail.ageCheckRequired , false );
        assertEquals(decodedTicket.controlDetail.getInfoText() , "cd" );
        assertEquals(decodedTicket.controlDetail.getIncludedTickets().get(0).getProductOwnerIA5() , "test" );
        assert(decodedTicket.controlDetail.getIdentificationByCardReference().get(0).getTrailingCardIdNum() == 100L );
    }    

}