File: TestMarshalIDREFS.java

package info (click to toggle)
castor 1.3.2-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 44,976 kB
  • sloc: java: 206,032; xml: 95,088; sql: 14,460; sh: 365; makefile: 10
file content (112 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download | duplicates (4)
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
import java.io.StringWriter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.InputSource;

public class TestMarshalIDREFS {
    
    private static final Log LOG = LogFactory.getLog(TestMarshalIDREFS.class);
    
    /**
     * test marshall idfrefs
     * 
     * @throws Exception
     */
    public void testMarshallIdrefs() throws Exception {
        Root test = new Root();

        Element1 el1 = new Element1();
        el1.setId1("CASTOR");
        Element2 el2 = new Element2();
        el2.setId2("POLLUX");
        Element3 el3 = new Element3();
        el3.setId3("PROMETHEE");

        ElementRef elRef = new ElementRef();
        elRef.addIdref(el1);
        elRef.addIdref(el2);
        test.setElement1(el1);
        test.setElement2(el2);
        test.setElement3(el3);
        test.setElementRef(elRef);
        StringWriter out = new StringWriter();
        Marshaller marshaller = new Marshaller(out);
        marshaller.setValidation(true);
        marshaller.marshal(test);
    }

    /**
     * test validate a null idref in an idrefs
     * 
     * @throws Exception
     */
    public void testMarshallIdrefsNullId() throws Exception {
        Root test = new Root();

        Element1 el1 = new Element1();
        el1.setId1("CASTOR");
        Element2 el2 = new Element2();
        el2.setId2("POLLUX");
        Element3 el3 = new Element3();
        el3.setId3("PROMETHEE");
        Element3 el4 = new Element3();
        el4.setId3(null);

        ElementRef elRef = new ElementRef();
        elRef.addIdref(el1);
        elRef.addIdref(el4);
        test.setElement1(el1);
        test.setElement2(el2);
        test.setElement3(el3);
        test.setElementRef(elRef);
        
        try {
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller(out);
            marshaller.setValidation(true);
            marshaller.marshal(test);
        } catch (Exception e) {
            // assertTrue(e.getCause() instanceof ValidationException);
        }
    }
    
    /**
     * test validate a non existing idref in an idrefs
     * 
     * @throws Exception
     */
    public void testMarshallIdrefsWrongId() throws Exception {
        Root test = new Root();

        Element1 el1 = new Element1();
        el1.setId1("CASTOR");
        Element2 el2 = new Element2();
        el2.setId2("POLLUX");
        Element3 el3 = new Element3();
        el3.setId3("PROMETHEE");
        Element3 el4 = new Element3();
        el4.setId3("WRONG");

        ElementRef elRef = new ElementRef();
        elRef.addIdref(el1);
        elRef.addIdref(el4);
        test.setElement1(el1);
        test.setElement2(el2);
        test.setElement3(el3);
        test.setElementRef(elRef);
        
        try {
            StringWriter out = new StringWriter();
            Marshaller marshaller = new Marshaller(out);
            marshaller.setValidation(true);
            marshaller.marshal(test);
        } catch (Exception e) {
            // assertTrue(e.getCause() instanceof ValidationException);
        }
    }    
}