Created
December 19, 2016 16:24
-
-
Save mfurtak/0094306477d3568c47b13ab6e2b18054 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mikefurtak.speechlet; | |
import com.amazon.speech.ui.SsmlOutputSpeech; | |
import com.amazonaws.util.StringInputStream; | |
import org.xml.sax.SAXException; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import javax.xml.parsers.ParserConfigurationException; | |
import java.io.IOException; | |
public class SpeechletTestUtils { | |
public static void assertSsmlValid(SsmlOutputSpeech ssmlOutputSpeech) { | |
assertSsmlValid(ssmlOutputSpeech.getSsml()); | |
} | |
public static void assertSsmlValid(String ssml) { | |
try (StringInputStream ssi = new StringInputStream(ssml)) { | |
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(ssi); | |
} catch (ParserConfigurationException e) { | |
throw new RuntimeException("Failed to initialize XML parsing.", e); | |
} catch (IOException e) { | |
throw new RuntimeException("Failed to read SSML.", e); | |
} catch (SAXException e) { | |
throw new AssertionError("The provided SSML was not valid.", e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment