Refactored unit-tests to check for SAX parser exceptions

revert-dabc3590
harshanL 10 years ago
parent 26883800ea
commit ac6eca2cbc

@ -25,6 +25,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
@ -70,44 +71,44 @@ public class MobileDeviceManagementConfigTests {
} }
} }
@Test(expectedExceptions = JAXBException.class) @Test
public void testMandateManagementRepositoryElement() throws JAXBException { public void testMandateManagementRepositoryElement() {
File malformedConfig = File malformedConfig =
new File( new File(
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY); MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_MGT_REPOSITORY);
this.validateMalformedConfig(malformedConfig); this.validateMalformedConfig(malformedConfig);
} }
@Test(expectedExceptions = JAXBException.class) @Test
public void testMandateDataSourceConfigurationElement() throws JAXBException { public void testMandateDataSourceConfigurationElement() {
File malformedConfig = new File( File malformedConfig = new File(
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG); MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_DS_CONFIG);
this.validateMalformedConfig(malformedConfig); this.validateMalformedConfig(malformedConfig);
} }
@Test(expectedExceptions = JAXBException.class) @Test
public void testMandateJndiLookupDefinitionElement() throws JAXBException { public void testMandateJndiLookupDefinitionElement() {
File malformedConfig = new File( File malformedConfig = new File(
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG); MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_JNDI_CONFIG);
this.validateMalformedConfig(malformedConfig); this.validateMalformedConfig(malformedConfig);
} }
@Test(expectedExceptions = JAXBException.class) @Test
public void testMandateAPIPublisherElement() throws JAXBException { public void testMandateAPIPublisherElement() {
File malformedConfig = new File( File malformedConfig = new File(
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG); MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_PUBLISHER_CONFIG);
this.validateMalformedConfig(malformedConfig); this.validateMalformedConfig(malformedConfig);
} }
@Test(expectedExceptions = JAXBException.class) @Test
public void testMandateAPIsElement() throws JAXBException { public void testMandateAPIsElement() {
File malformedConfig = new File( File malformedConfig = new File(
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG); MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_APIS_CONFIG);
this.validateMalformedConfig(malformedConfig); this.validateMalformedConfig(malformedConfig);
} }
@Test(expectedExceptions = JAXBException.class) @Test
public void testMandateAPIElement() throws JAXBException { public void testMandateAPIElement() {
File malformedConfig = new File( File malformedConfig = new File(
MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG); MobileDeviceManagementConfigTests.MALFORMED_TEST_CONFIG_LOCATION_NO_API_CONFIG);
this.validateMalformedConfig(malformedConfig); this.validateMalformedConfig(malformedConfig);
@ -116,12 +117,21 @@ public class MobileDeviceManagementConfigTests {
/** /**
* Validates a given malformed-configuration file. * Validates a given malformed-configuration file.
*/ */
private void validateMalformedConfig(File malformedConfig) throws JAXBException { private void validateMalformedConfig(File malformedConfig) {
JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class); try {
Unmarshaller um = ctx.createUnmarshaller(); JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class);
um.setSchema(this.getSchema()); Unmarshaller um = ctx.createUnmarshaller();
um.unmarshal(malformedConfig); um.setSchema(this.getSchema());
Assert.assertTrue(false); um.unmarshal(malformedConfig);
Assert.assertTrue(false);
} catch (JAXBException e) {
Throwable linkedException = e.getLinkedException();
if (!(linkedException instanceof SAXParseException)) {
log.error("Unexpected error occurred while unmarshalling mobile device management config", e);
Assert.assertTrue(false);
}
Assert.assertTrue(true);
}
} }
private Schema getSchema() { private Schema getSchema() {

Loading…
Cancel
Save