View Javadoc
1   /*
2    * Copyright (c) 2008, The JUNG Authors
3    *
4    * All rights reserved.
5    *
6    * This software is open-source under the BSD license; see either
7    * "license.txt" or
8    * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
9    */
10  
11  package edu.uci.ics.jung.io.graphml.parser;
12  
13  import org.junit.Assert;
14  import org.junit.Test;
15  
16  import edu.uci.ics.jung.io.GraphIOException;
17  import edu.uci.ics.jung.io.graphml.PortMetadata;
18  
19  public class TestPortElementParser extends AbstractParserTest {
20  
21      @Test(expected= GraphIOException.class)
22      public void testNoName() throws Exception {
23          
24          String xml = 
25              "<port/>";
26          
27          readObject(xml);
28      }
29  
30      @Test
31      public void testName() throws Exception {
32          
33          String xml = 
34              "<port name=\"p1\"/>";
35          
36          PortMetadata port = (PortMetadata) readObject(xml);
37          Assert.assertNotNull(port);
38          Assert.assertEquals("p1", port.getName());
39          Assert.assertEquals(null, port.getDescription());
40      }
41  
42      @Test
43      public void testDesc() throws Exception {
44          
45          String xml = 
46              "<port name=\"p1\">" +
47                  "<desc>this is my port</desc>" +
48              "</port>";
49          
50          PortMetadata port = (PortMetadata) readObject(xml);
51          Assert.assertNotNull(port);
52          Assert.assertEquals("p1", port.getName());
53          Assert.assertEquals("this is my port", port.getDescription());
54      }
55  
56      @Test
57      public void testUserAttributes() throws Exception {
58          
59          String xml = 
60              "<port name=\"p1\" bob=\"abc123\"/>";
61          
62          PortMetadata port = (PortMetadata) readObject(xml);
63          Assert.assertNotNull(port);
64          Assert.assertEquals("p1", port.getName());
65          Assert.assertEquals(1, port.getProperties().size());
66          Assert.assertEquals("abc123", port.getProperty("bob"));
67      }
68  
69      @Test
70      public void testData() throws Exception {
71          
72          String xml =
73              "<port name=\"p1\">" +
74                  "<data key=\"d1\">value1</data>" +
75                  "<data key=\"d2\">value2</data>" +
76              "</port>";
77          
78          PortMetadata port = (PortMetadata) readObject(xml);
79          Assert.assertNotNull(port);
80          Assert.assertEquals("p1", port.getName());
81          Assert.assertEquals(2, port.getProperties().size());
82          Assert.assertEquals("value1", port.getProperty("d1"));
83          Assert.assertEquals("value2", port.getProperty("d2"));
84      }
85  }