1 /**
2 * Copyright 2010, CSIRO Australia.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /**
18 *
19 */
20 package au.csiro.netcdf.util;
21
22 import java.io.ByteArrayInputStream;
23 import java.util.List;
24
25 import junit.framework.TestCase;
26 import ucar.nc2.Attribute;
27
28 /**
29 * Check the function of the NetCDFUtils class.
30 *
31 * Copyright 2010, CSIRO Australia
32 * All rights reserved.
33 *
34 * @author James Dempsey on 19/04/2010
35 * @version $Revision: 78 $ $Date: 2010-07-24 16:23:13 +1000 (Sat, 24 Jul 2010) $
36 */
37 public class NetCDFUtilsTest extends TestCase
38 {
39
40 /* (non-Javadoc)
41 * @see junit.framework.TestCase#setUp()
42 */
43 protected void setUp() throws Exception
44 {
45 super.setUp();
46 }
47
48 /**
49 * Test method for {@link au.csiro.netcdf.util.NetCDFUtils#readAttributesFromStream(java.io.InputStream)}.
50 * @throws Exception
51 */
52 public void testReadAttributesFromStreamNull() throws Exception
53 {
54 List<Attribute> attribs = NetCDFUtils.readAttributesFromStream(null);
55 assertEquals("Attribute list should be empty", 0, attribs.size());
56 }
57
58 /**
59 * Test method for {@link au.csiro.netcdf.util.NetCDFUtils#readAttributesFromStream(java.io.InputStream)}.
60 * @throws Exception
61 */
62 public void testReadAttributesFromStream() throws Exception
63 {
64 String testAttribs = "";
65 List<Attribute> attribs = NetCDFUtils.readAttributesFromStream(new ByteArrayInputStream(
66 testAttribs.getBytes("UTF-8")));
67 assertEquals("Attribute list should be empty", 0, attribs.size());
68
69 testAttribs = "PID=http://hdl.handle.net/10378.3/7023," + "Dataset Name=MDB SY Scenario A (Historical Data),"
70 + "Conversion system=MdbsyScenarioAConverter r1," + "Coordinate system=\"GDA94 / MGA zone 55\"";
71 attribs = NetCDFUtils.readAttributesFromStream(new ByteArrayInputStream(
72 testAttribs.getBytes("UTF-8")));
73 assertEquals("Attribute list wring size", 4, attribs.size());
74 assertEquals("Incorrect attrib name", "Conversion system", attribs.get(2).getName());
75 assertEquals("Incorrect attrib value", "MdbsyScenarioAConverter r1", attribs.get(2).getValue(0));
76 }
77
78 }