use of org.datanucleus.samples.annotations.one_many.bidir_3.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.datanucleus.samples.annotations.one_many.bidir_3.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.datanucleus.samples.annotations.one_many.bidir_3.Document in project JMRI by JMRI.
the class SwitchboardServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
SwitchboardEditor editor = (SwitchboardEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
// add more properties
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
panel.setAttribute("hideunconnected", (editor.hideUnconnected()) ? "yes" : "no");
panel.setAttribute("rangemin", Integer.toString(editor.getPanelMenuRangeMin()));
panel.setAttribute("rangemax", Integer.toString(editor.getPanelMenuRangeMax()));
panel.setAttribute("type", editor.getSwitchType());
panel.setAttribute("connection", editor.getSwitchManu());
panel.setAttribute("shape", editor.getSwitchShape());
panel.setAttribute("columns", Integer.toString(editor.getColumns()));
panel.setAttribute("defaulttextcolor", editor.getDefaultTextColor());
log.debug("webserver Switchboard attribs ready");
Element bgColor = new Element("backgroundColor");
if (editor.getBackgroundColor() == null) {
// set to light grey
bgColor.setAttribute("red", Integer.toString(192));
bgColor.setAttribute("green", Integer.toString(192));
bgColor.setAttribute("blue", Integer.toString(192));
} else {
bgColor.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
bgColor.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
bgColor.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
}
panel.addContent(bgColor);
Element text = new Element("text");
text.setAttribute("color", editor.getDefaultTextColor());
text.setAttribute("content", "For now, Switchboards only present buttons in JMRI WebServer.");
panel.addContent(text);
// include switches, Bug: how to delete the old ones?
// call method in SwitchboardEditor
List<BeanSwitch> _switches = editor.getSwitches();
log.debug("SwbServlet N switches: {}", _switches.size());
for (BeanSwitch sub : _switches) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
log.debug("element name: {}", e.getName());
// }
try {
e.setAttribute("label", sub.getNameString());
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
if (sub.getNamedBean() == null) {
e.setAttribute("connected", "false");
log.debug("switch {} NOT connected", sub.getNameString());
} else {
// activate click action via class
e.setAttribute("connected", "true");
}
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
// read shared attribs
e.setAttribute("textcolor", editor.getDefaultTextColor());
e.setAttribute("type", editor.getSwitchType());
e.setAttribute("connection", editor.getSwitchManu());
e.setAttribute("shape", editor.getSwitchShape());
e.setAttribute("columns", Integer.toString(editor.getColumns()));
// process and add
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error reading xml panel element: " + ex, ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested Switchboard [" + name + "] does not exist.");
return "ERROR Requested Switchboard [" + name + "] does not exist.";
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project JMRI by JMRI.
the class ControlPanelServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
ControlPanelEditor editor = (ControlPanelEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
if (editor.getBackgroundColor() != null) {
Element color = new Element("backgroundColor");
color.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
color.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
color.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
panel.addContent(color);
}
// include contents
List<Positionable> contents = editor.getContents();
log.debug("N elements: {}", contents.size());
for (Positionable sub : contents) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
if ("signalmasticon".equals(e.getName())) {
//insert icon details into signalmast
e.addContent(getSignalMastIconsElement(e.getAttributeValue("signalmast")));
}
try {
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested ControlPanel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project JMRI by JMRI.
the class QualifiedVarTest method setupDoc.
// provide a test document in the above static variables
void setupDoc() {
// create a JDOM tree with just some elements
root = new Element("programmer-config");
doc = new Document(root);
doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
// add some elements
root.addContent(new Element("programmer").setAttribute("showFnLanelPane", "no").setAttribute("showRosterMediaPane", "no").addContent(new Element("pane").setAttribute("name", "Test").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Primary Address")).addContent(new Element("display").setAttribute("item", "CV2")).addContent(new Element("display").setAttribute("item", "CV3")).addContent(new Element("display").setAttribute("item", "CV4")).addContent(new Element("display").setAttribute("item", "CV5")).addContent(new Element("display").setAttribute("item", "CV6")).addContent(new Element("separator")).addContent(new Element("label").setAttribute("label", "set cv3 >= 100 to see CV4")).addContent(new Element("label").setAttribute("label", "set cv3 <=100 to see CV5, CV6"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Minor Version Number")).addContent(new Element("display").setAttribute("item", "Major Version Number")).addContent(new Element("display").setAttribute("item", "iCV53.5.0")).addContent(new Element("display").setAttribute("item", "iCV55.92.0")).addContent(new Element("display").setAttribute("item", "iCV55.92.1")).addContent(new Element("separator")).addContent(new Element("label").setAttribute("label", "set cv3 >= 100 to see iCV53.5.0")).addContent(new Element("label").setAttribute("label", "set minor >= 100 to see iCV55.92.0")).addContent(new Element("label").setAttribute("label", "set minor, major >= 100 to see iCV55.92.1")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "iCV").addContent(new Element("column").addContent(new Element("indxcvtable")))).addContent(new Element("pane").setAttribute("name", "CV3>50").addContent(new Element("qualifier").addContent(new Element("variableref").addContent("CV3")).addContent(new Element("relation").addContent("gt")).addContent(new Element("value").addContent("50"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "CV3")).addContent(new Element("display").setAttribute("item", "CV4")).addContent(new Element("label").setAttribute("label", "Pane visible with CV3>100")))));
return;
}
Aggregations