use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method analyzeEntitiesTest.
@Test
@SuppressWarnings("all")
public void analyzeEntitiesTest() {
String language = "language-1613589672";
AnalyzeEntitiesResponse expectedResponse = AnalyzeEntitiesResponse.newBuilder().setLanguage(language).build();
mockLanguageService.addResponse(expectedResponse);
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnalyzeEntitiesResponse actualResponse = client.analyzeEntities(document, encodingType);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
Assert.assertEquals(1, actualRequests.size());
AnalyzeEntitiesRequest actualRequest = (AnalyzeEntitiesRequest) actualRequests.get(0);
Assert.assertEquals(document, actualRequest.getDocument());
Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method analyzeSentimentExceptionTest.
@Test
@SuppressWarnings("all")
public void analyzeSentimentExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockLanguageService.addException(exception);
try {
Document document = Document.newBuilder().build();
client.analyzeSentiment(document);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of org.jdom2.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method annotateTextTest.
@Test
@SuppressWarnings("all")
public void annotateTextTest() {
String language = "language-1613589672";
AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
mockLanguageService.addResponse(expectedResponse);
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
Assert.assertEquals(1, actualRequests.size());
AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
Assert.assertEquals(document, actualRequest.getDocument());
Assert.assertEquals(features, actualRequest.getFeatures());
Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
use of org.jdom2.Document in project JMRI by JMRI.
the class XmlFile method addDefaultInfo.
/**
* Add default information to the XML before writing it out.
* <P>
* Currently, this is identification information as an XML comment. This
* includes: <UL>
* <LI>The JMRI version used <LI>Date of writing <LI>A CVS id string, in
* case the file gets checked in or out </UL>
* <P>
* It may be necessary to extend this to check whether the info is already
* present, e.g. if re-writing a file.
*
* @param root The root element of the document that will be written.
*/
public static void addDefaultInfo(Element root) {
String content = "Written by JMRI version " + jmri.Version.name() + " on " + (new Date()).toString() + " $Id$";
Comment comment = new Comment(content);
root.addContent(comment);
}
use of org.jdom2.Document in project JMRI by JMRI.
the class XmlFile method processOneInstruction.
Document processOneInstruction(ProcessingInstruction p, Document doc) throws org.jdom2.transform.XSLTransformException, org.jdom2.JDOMException, java.io.IOException {
log.trace("handling ", p);
// check target
String target = p.getTarget();
if (!target.equals("transform-xslt")) {
return doc;
}
String href = p.getPseudoAttributeValue("href");
// we expect this to start with http://jmri.org/ and refer to the JMRI file tree
if (!href.startsWith("http://jmri.org/")) {
return doc;
}
href = href.substring(16);
// if starts with 'xml/' we remove that; findFile will put it back
if (href.startsWith("xml/")) {
href = href.substring(4);
}
// read the XSLT transform into a Document to get XInclude done
SAXBuilder builder = getBuilder(Validate.None);
Document xdoc = builder.build(new BufferedInputStream(new FileInputStream(findFile(href))));
org.jdom2.transform.XSLTransformer transformer = new org.jdom2.transform.XSLTransformer(xdoc);
return transformer.transform(doc);
}
Aggregations