EasyBoxConfigurationParser { public EasyboxConfiguration parseConfguration(HierarchicalConfiguration config) throws ConfigurationException { EasyBoxConfigrationImpl ebc = new EasyBoxConfigrationImpl(); ebc.setName(config.getString("[@name]")); if(StringUtils.isBlank(ebc.getName())) throw new ConfigurationException("Name missing"); ebc.setInterfaceMacAddress(config.getString("[@interfaceMac]")); if(StringUtils.isBlank(ebc.getInterfaceMacAddress())) throw new ConfigurationException("Interface MAC address missing"); ebc.setSnmpConfiguration( new SnmpConfigurationDefaultLocalPortDecorator( snmpConfigParser.parseConfiguration( first(config.configurationsAt("Snmp"), "Snmp")))); ebc.setRoutingConfiguration(routingConfigParser.parseConfiguration(first(config.configurationsAt("Routing"), "Routing"))); return ebc; }  EasyboxConfiguration parseConfguration(HierarchicalConfiguration config);  }
@Test public void testCorrectConfiguration() throws Exception { EasyboxConfiguration eb = parser.parseConfguration(config.configurationAt("EasyBox(0)")); Assert.assertEquals("test1", eb.getName()); Assert.assertEquals("00:00", eb.getInterfaceMacAddress()); SnmpConfiguration snmp = eb.getSnmpConfiguration(); Assert.assertNotNull(snmp); Assert.assertEquals("public", snmp.getCommunity()); Assert.assertEquals(InetAddress.getByAddress(new byte[] { (byte)0xc0, (byte)0xa8, (byte)0x01, (byte)0x01 }), snmp.getTargetAddress()); RoutingConfiguration routing = eb.getRoutingConfiguration(); Assert.assertNotNull(routing); Assert.assertEquals(1, routing.getRoutingConfigurations().size()); }
@Test(expected=ConfigurationException.class) public void testMissingName() throws Exception { parser.parseConfguration(config.configurationAt("EasyBox(1)")); }
@Test(expected=ConfigurationException.class) public void testBlankName() throws Exception { parser.parseConfguration(config.configurationAt("EasyBox(2)")); }
@Test(expected=ConfigurationException.class) public void testMissingInterfaceMacAddress() throws Exception { parser.parseConfguration(config.configurationAt("EasyBox(3)")); }
@Test(expected=ConfigurationException.class) public void testBlankInterfaceMacAddress() throws Exception { parser.parseConfguration(config.configurationAt("EasyBox(4)")); }
@Test(expected=ConfigurationException.class) public void testMissingSnmp() throws Exception { parser.parseConfguration(config.configurationAt("EasyBox(5)")); }
@Test(expected=ConfigurationException.class) public void testMissingRouting() throws Exception { parser.parseConfguration(config.configurationAt("EasyBox(6)")); }