summaryrefslogtreecommitdiffstats
path: root/src/org/uic/barcode/ticket/api/test/UperEncodeTicketLinkTestV1.java
blob: 96d003dd2e594b78abecefb8e621a91e21d0994a (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
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.api.asn.omv1.UicRailTicketData;
import org.uic.barcode.ticket.api.spec.ILinkMode;
import org.uic.barcode.ticket.api.spec.ITicketLink;
import org.uic.barcode.ticket.api.spec.ITicketType;
import org.uic.barcode.ticket.api.spec.IUicRailTicket;
import org.uic.barcode.ticket.api.utils.OpenAsn2ApiDecoder;


public class UperEncodeTicketLinkTestV1 {

 



    @Test public void testEncodeTicket() throws IllegalArgumentException, IllegalAccessException {
    	UicRailTicketData ticket = SimpleTicketLinkTestTicket.getUicTestTicket();
        byte[] encoded = UperEncoder.encode(ticket);
        String hex = UperEncoder.hexStringFromBytes(encoded);
        UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
       
        String expectedHex = SimpleTicketLinkTestTicket.getEncodingV1Hex();
         UperEncoder.logger.debug(String.format("first difference at index: %d",hex.compareTo(expectedHex)));
        UperEncoder.logger.debug(String.format("data returned: %s",hex)); 
        UperEncoder.logger.debug(String.format("data expected: %s",expectedHex)); 
        assert(hex.equals(expectedHex));
    }
    
	@Test public void testDecodeTicket() throws IllegalArgumentException, IllegalAccessException {
    	UicRailTicketData ticket = SimpleTicketLinkTestTicket.getUicTestTicket();
        byte[] encoded = UperEncoder.encode(ticket);
        String hex = UperEncoder.hexStringFromBytes(encoded);
        UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
        String expectedHex = SimpleTicketLinkTestTicket.getEncodingV1Hex();
        assertEquals(hex,expectedHex);
        UicRailTicketData decodedTicket  = UperEncoder.decode(encoded, UicRailTicketData.class);
        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 );
        assert(decodedTicket.controlDetail.getIncludedTickets().size() == 1);
  	}    

	@Test public void testDecodeTicket2Api() throws IllegalArgumentException, IllegalAccessException {
    	UicRailTicketData ticket = SimpleTicketLinkTestTicket.getUicTestTicket();
        byte[] encoded = UperEncoder.encode(ticket);
        UicRailTicketData decodedTicket  = UperEncoder.decode(encoded, UicRailTicketData.class);       
        
        OpenAsn2ApiDecoder decoder = new OpenAsn2ApiDecoder();
        IUicRailTicket uicTicket = null;
		try {
			uicTicket = decoder.decodeFromAsn(decodedTicket);
		} catch (IOException e) {
			assert (false);
		}
        
        assert(uicTicket.getControlDetails().getLinkedTickets().size() == 1);
        for (ITicketLink link: uicTicket.getControlDetails().getLinkedTickets() ) {   	
              	assert(link.getLinkMode() == ILinkMode.onlyValidInCombination);
              	assert(link.getTicketType() == ITicketType.pass);
        }
	}    

	
}