/*
* Copyright 2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.cep.core.internal.process;
import junit.framework.TestCase;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.OMElement;
import org.wso2.carbon.cep.core.XpathDefinition;
import org.wso2.carbon.cep.core.exception.CEPEventProcessingException;
import javax.xml.stream.XMLStreamException;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public class TestOMElementProcessor extends TestCase {
public void testGetValue(){
String xmlString = "<statdata:ServiceStatisticsDataEvent xmlns:statdata=\"http://wso2.org/ns/2009/09/bam/service/statistics/data\">\n" +
" <statdata:ServiceStatisticsData>\n" +
" <statdata:ServerName>http://127.0.0.1:9763</statdata:ServerName>\n" +
" <statdata:AveageResponseTime>16.4</statdata:AveageResponseTime>\n" +
" <statdata:MinimumResponseTime>0</statdata:MinimumResponseTime>\n" +
" <statdata:MaximumResponseTime>109</statdata:MaximumResponseTime>\n" +
" <statdata:RequestCount>23</statdata:RequestCount>\n" +
" <statdata:ResponseCount>20</statdata:ResponseCount>\n" +
" <statdata:FaultCount>120</statdata:FaultCount>\n" +
" <statdata:ServiceName>HelloService</statdata:ServiceName>\n" +
" <statdata:OperationName>greet</statdata:OperationName>\n" +
" </statdata:ServiceStatisticsData>\n" +
"</statdata:ServiceStatisticsDataEvent>";
try {
StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(new ByteArrayInputStream(xmlString.getBytes()));
OMElement omElement = stAXOMBuilder.getDocumentElement();
ArrayList<XpathDefinition> xpathDefinitionsList = new ArrayList<XpathDefinition>();
XpathDefinition xpathDefinition = new XpathDefinition();
xpathDefinition.setPrefix("statdata");
xpathDefinition.setNamespace("http://wso2.org/ns/2009/09/bam/service/statistics/data");
xpathDefinitionsList.add(xpathDefinition);
Object value = OMElementProcessor.getValue(omElement,
"//statdata:ServiceStatisticsData/statdata:RequestCount",
"java.lang.Integer",
xpathDefinitionsList);
} catch (XMLStreamException e) {
e.printStackTrace();
} catch (CEPEventProcessingException e) {
e.printStackTrace();
}
}
}