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 package org.jomc.modlet.test;
32
33 import java.io.IOException;
34 import java.io.ObjectInputStream;
35 import java.util.logging.Level;
36 import org.jomc.modlet.ModelValidationReport;
37 import org.junit.Test;
38 import static org.junit.Assert.assertEquals;
39 import static org.junit.Assert.assertNotNull;
40 import static org.junit.Assert.assertNull;
41
42
43
44
45
46
47
48 public class ModelValidationReportTest
49 {
50
51
52 private static final String ABSOLUTE_RESOURCE_NAME_PREFIX = "/org/jomc/modlet/test/";
53
54
55 public ModelValidationReportTest()
56 {
57 super();
58 }
59
60 @Test
61 public final void testSerializabe() throws Exception
62 {
63 final ModelValidationReport report =
64 this.readObject( ABSOLUTE_RESOURCE_NAME_PREFIX + "ModelValidationReport.ser", ModelValidationReport.class );
65
66 final ModelValidationReport.Detail detail =
67 this.readObject( ABSOLUTE_RESOURCE_NAME_PREFIX + "ModelValidationReportDetail.ser",
68 ModelValidationReport.Detail.class );
69
70 System.out.println( report );
71 System.out.println( detail );
72
73 assertEquals( 1, report.getDetails( "Identifier 1" ).size() );
74 assertEquals( 1, report.getDetails( "Identifier 2" ).size() );
75 assertEquals( 1, report.getDetails( "Identifier 3" ).size() );
76 assertEquals( 1, report.getDetails( "Identifier 4" ).size() );
77 assertEquals( 1, report.getDetails( "Identifier 5" ).size() );
78 assertEquals( 1, report.getDetails( "Identifier 6" ).size() );
79 assertEquals( 1, report.getDetails( "Identifier 7" ).size() );
80 assertEquals( 1, report.getDetails( "Identifier 8" ).size() );
81 assertEquals( 1, report.getDetails( "Identifier 9" ).size() );
82 assertEquals( 1, report.getDetails( "Identifier 10" ).size() );
83
84 assertEquals( "Identifier", detail.getIdentifier() );
85 assertEquals( Level.OFF, detail.getLevel() );
86 assertEquals( "Message", detail.getMessage() );
87 assertNull( detail.getElement() );
88 }
89
90 private <T> T readObject( final String location, final Class<T> type ) throws IOException, ClassNotFoundException
91 {
92 ObjectInputStream in = null;
93 boolean suppressExceptionOnClose = true;
94
95 try
96 {
97 in = new ObjectInputStream( this.getClass().getResourceAsStream( location ) );
98 assertNotNull( in );
99 final T object = (T) in.readObject();
100 suppressExceptionOnClose = false;
101 return object;
102 }
103 finally
104 {
105 try
106 {
107 if ( in != null )
108 {
109 in.close();
110 }
111 }
112 catch ( final IOException e )
113 {
114 if ( !suppressExceptionOnClose )
115 {
116 throw e;
117 }
118 }
119 }
120 }
121
122 }