Search in sources :

Example 11 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project OpenGrok by OpenGrok.

the class RuntimeEnvironmentTest method testLoadStatistics.

@Test
public void testLoadStatistics() throws IOException, ParseException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String json = "{" + "\"requests_per_minute_max\":3," + "\"timing\":{" + "\"*\":2288," + "\"xref\":53," + "\"root\":2235" + "}," + "\"minutes\":756," + "\"timing_min\":{" + "\"*\":2," + "\"xref\":2," + "\"root\":2235" + "}," + "\"timing_avg\":{" + "\"*\":572.0," + "\"xref\":17.666666666666668," + "\"root\":2235.0" + "}," + "\"request_categories\":{" + "\"*\":4," + "\"xref\":3," + "\"root\":1" + "}," + "\"day_histogram\":[0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,1]," + "\"requests\":4," + "\"requests_per_minute_min\":1," + "\"requests_per_minute\":3," + "\"requests_per_minute_avg\":0.005291005291005291," + "\"month_histogram\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,0]," + "\"timing_max\":{" + "\"*\":2235," + "\"xref\":48," + "\"root\":2235" + "}" + "}";
    try (InputStream in = new StringInputStream(json)) {
        env.loadStatistics(in);
    }
    Statistics stats = env.getStatistics();
    Assert.assertNotNull(stats);
    Assert.assertEquals(756, stats.getMinutes());
    Assert.assertEquals(4, stats.getRequests());
    Assert.assertEquals(3, stats.getRequestsPerMinute());
    Assert.assertEquals(1, stats.getRequestsPerMinuteMin());
    Assert.assertEquals(3, stats.getRequestsPerMinuteMax());
    Assert.assertEquals(0.005291005291005291, stats.getRequestsPerMinuteAvg(), 0.00005);
    Assert.assertArrayEquals(new long[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, stats.getDayHistogram());
    Assert.assertArrayEquals(new long[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0 }, stats.getMonthHistogram());
    Assert.assertEquals(createMap(new Object[][] { { "*", 4L }, { "xref", 3L }, { "root", 1L } }), stats.getRequestCategories());
    Assert.assertEquals(createMap(new Object[][] { { "*", 2288L }, { "xref", 53L }, { "root", 2235L } }), stats.getTiming());
    Assert.assertEquals(createMap(new Object[][] { { "*", 2L }, { "xref", 2L }, { "root", 2235L } }), stats.getTimingMin());
    Assert.assertEquals(createMap(new Object[][] { { "*", 2235L }, { "xref", 48L }, { "root", 2235L } }), stats.getTimingMax());
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) InputStream(java.io.InputStream) Statistics(org.opensolaris.opengrok.web.Statistics) Test(org.junit.Test)

Example 12 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project Gemma by PavlidisLab.

the class EutilFetch method parseStringInputStream.

public static Document parseStringInputStream(String details) throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilder builder = EutilFetch.factory.newDocumentBuilder();
    int tries = 0;
    while (true) {
        try (InputStream is = new StringInputStream(details)) {
            return builder.parse(is);
        } catch (IOException e) {
            tries = EutilFetch.tryAgainOrFail(tries, e);
        }
    }
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringInputStream(org.apache.tools.ant.filters.StringInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 13 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigUtils method customizeCfgXmlForPack.

/**
 * Customize hibernate.cfg.xml file for the particular test package content.
 * @param pack
 * @throws CoreException
 */
public static void customizeCfgXmlForPack(IPackageFragment pack) throws CoreException {
    StringInputStream sis = new StringInputStream(createCfgXmlContent(pack));
    IFolder srcFolder = (IFolder) pack.getParent().getResource();
    IFile iFile = srcFolder.getFile(CFG_FILE_NAME);
    if (iFile.exists()) {
        iFile.delete(true, null);
    }
    iFile.create(sis, true, null);
    try {
        sis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigUtils method customizeCfgXmlForPack.

/**
 * Customize hibernate.cfg.xml file for the particular test package content.
 * @param pack
 * @throws CoreException
 */
public static void customizeCfgXmlForPack(IPackageFragment pack) throws CoreException {
    StringInputStream sis = new StringInputStream(createCfgXmlContent(pack));
    IFolder srcFolder = (IFolder) pack.getParent().getResource();
    IFile iFile = srcFolder.getFile(CFG_FILE_NAME);
    if (iFile.exists()) {
        iFile.delete(true, null);
    }
    iFile.create(sis, true, null);
    try {
        sis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with StringInputStream

use of org.apache.tools.ant.filters.StringInputStream in project kie-wb-common by kiegroup.

the class DMNMarshallerStandaloneTest method testContextEntryDataType.

@Test
@SuppressWarnings("unchecked")
public void testContextEntryDataType() throws Exception {
    final DMNMarshallerStandalone marshaller = getDMNMarshaller();
    final Context context = new Context();
    context.setTypeRef(BuiltInType.DATE_TIME.asQName());
    final ContextEntry contextEntry = new ContextEntry();
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.setTypeRef(BuiltInType.BOOLEAN.asQName());
    literalExpression.getText().setValue("feel");
    contextEntry.setExpression(literalExpression);
    context.getContextEntry().add(contextEntry);
    final Diagram<Graph, Metadata> mockedDiagram = newDiagramDecisionWithExpression(context);
    final String marshalledSource = marshaller.marshall(mockedDiagram);
    final Graph<?, Node<View, ?>> unmarshalledGraph = marshaller.unmarshall(createMetadata(), new StringInputStream(marshalledSource));
    assertThat(unmarshalledGraph.nodes()).hasSize(2);
    checkDecisionExpression(unmarshalledGraph, context);
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) DMNContext(org.kie.dmn.api.core.DMNContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) StringInputStream(org.apache.tools.ant.filters.StringInputStream) Graph(org.kie.workbench.common.stunner.core.graph.Graph) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Test(org.junit.Test)

Aggregations

StringInputStream (org.apache.tools.ant.filters.StringInputStream)17 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 IFile (org.eclipse.core.resources.IFile)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)2 DiagramImpl (org.kie.workbench.common.stunner.core.diagram.DiagramImpl)2 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Statistics (org.opensolaris.opengrok.web.Statistics)2 Document (org.w3c.dom.Document)2 SAXException (org.xml.sax.SAXException)2