Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
25   127   7   5
0   56   0.28   5
5     1.4  
1    
 
  CommunicationFactoryTest       Line # 41 25 0% 7 4 86.7% 0.8666667
 
  (3)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6   
7    ARESTC is free software: you can redistribute it and/or modify
8    it under the terms of the Lesser General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11   
12    ARESTC is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    GNU General Public License for more details.
16   
17    You should have received a copy of the Lesser General Public License
18    along with ARESTC. If not, see <http://www.gnu.org/licenses/>.
19   
20    */
21    package net.sf.arestc.communication;
22   
23    import java.io.ByteArrayInputStream;
24    import java.io.ByteArrayOutputStream;
25    import java.io.IOException;
26    import java.io.InputStream;
27    import java.io.ObjectInputStream;
28    import java.io.ObjectOutputStream;
29   
30    import junit.framework.TestCase;
31    import net.sf.arestc.configuration.CommunicationFactory;
32   
33    import org.apache.log4j.Logger;
34   
35    // TODO: Auto-generated Javadoc
36    /**
37    * The Class CommunicationFactoryTest.
38    *
39    * @author georgosn
40    */
 
41    public class CommunicationFactoryTest extends TestCase {
42   
43    /** The Constant LOGGER. */
44    private static final Logger LOGGER = Logger
45    .getLogger(CommunicationFactoryTest.class
46    .getName());
47   
48    /*
49    * (non-Javadoc)
50    *
51    * @see junit.framework.TestCase#setUp()
52    */
 
53  3 toggle @Override
54    protected void setUp() throws Exception {
55  3 super.setUp();
56    }
57   
58    /*
59    * (non-Javadoc)
60    *
61    * @see junit.framework.TestCase#tearDown()
62    */
 
63  3 toggle @Override
64    protected void tearDown() throws Exception {
65  3 CommunicationFactory.getInstance().shutdown();
66  3 super.tearDown();
67    }
68   
69    /**
70    * Test method for.
71    *
72    * {@link lu.ng.urlchecker.communication.CommunicationFactory#isConfigured()}
73    * .
74    */
 
75  1 toggle public void testIsConfigured() {
76  1 assertNotNull(CommunicationFactory.getInstance().isConfigured());
77   
78    }
79   
80    /**
81    * Test method for.
82    *
83    * {@link lu.ng.urlchecker.communication.CommunicationFactory#isMultiThreaded()}
84    * .
85    */
 
86  1 toggle public void testIsMultiThreaded() {
87  1 assertNotNull(CommunicationFactory.getInstance().isMultiThreaded());
88    }
89   
90    /**
91    * Test serialisation.
92    */
 
93  1 toggle public void testSerialisation() {
94    // serialize
95  1 final ByteArrayOutputStream out = new ByteArrayOutputStream();
96  1 ObjectOutputStream oos;
97  1 try {
98  1 oos = new ObjectOutputStream(out);
99   
100  1 oos.writeObject(CommunicationFactory.getInstance());
101  1 oos.close();
102   
103    // deserialize
104  1 byte[] pickled = null;
105  1 pickled = out.toByteArray();
106  1 InputStream in = null;
107  1 in = new ByteArrayInputStream(pickled);
108  1 ObjectInputStream ois = null;
109  1 ois = new ObjectInputStream(in);
110  1 Object o = null;
111  1 o = ois.readObject();
112  1 final CommunicationFactory copy = (CommunicationFactory) o;
113   
114    // test the result
115  1 assertEquals(CommunicationFactory.getInstance().isMultiThreaded(),
116    copy.isMultiThreaded());
117   
118    } catch (final IOException e) {
119  0 LOGGER.error(e);
120  0 fail("IOException");
121    } catch (final ClassNotFoundException e) {
122  0 LOGGER.error(e);
123  0 fail("ClassNotFoundException");
124    }
125    }
126   
127    }