Skip to content

Instantly share code, notes, and snippets.

@mfurtak
Created December 19, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfurtak/0094306477d3568c47b13ab6e2b18054 to your computer and use it in GitHub Desktop.
Save mfurtak/0094306477d3568c47b13ab6e2b18054 to your computer and use it in GitHub Desktop.
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