use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.
the class XMLReport method createElement.
/**
* Creates an XML element.
* @param element the parent element
* @param name the name of the element to create
* @return the resulting XML tree.
*/
private Xpp3Dom createElement(Xpp3Dom element, String name) {
Xpp3Dom component = new Xpp3Dom(name);
element.addChild(component);
return component;
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.
the class XMLReport method writeTestProblems.
/**
* Utility method writing failed and in error test result in the report.
* @param test the test
* @param e the thrown error
* @param name type of failure ("error" or "failure")
* @param out the output messages printed during the test execution
* @param err the error messages printed during the test execution
* @param log the messages logged during the test execution
*/
private void writeTestProblems(Test test, Throwable e, String name, String out, String err, String log) {
long runTime = m_endTime - m_startTime;
Xpp3Dom testCase = createTestElement(test, runTime);
Xpp3Dom element = createElement(testCase, name);
String stackTrace = getStackTrace(test, e);
Throwable t = e;
if (t != null) {
String message = t.getMessage();
if (message != null) {
element.setAttribute("message", message);
element.setAttribute("type", stackTrace.indexOf(":") > -1 ? stackTrace.substring(0, stackTrace.indexOf(":")) : stackTrace);
} else {
element.setAttribute("type", new StringTokenizer(stackTrace).nextToken());
}
}
if (stackTrace != null) {
element.setValue(stackTrace);
}
addOutputStreamElement(out, "system-out", testCase);
addOutputStreamElement(err, "system-err", testCase);
if (log != null) {
addOutputStreamElement(log, "log-service", testCase);
}
m_results.add(testCase);
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.
the class XMLReport method showProperties.
/**
* Adds system properties to the XML report.
* This method also adds installed bundles.
* @param testSuite the XML element.
* @param bc the bundle context
* @param configuration the configuration of the underlying OSGi platform
*/
private void showProperties(Xpp3Dom testSuite, BundleContext bc, Map configuration) {
Xpp3Dom properties = createElement(testSuite, "properties");
Properties systemProperties = System.getProperties();
if (systemProperties != null) {
Enumeration propertyKeys = systemProperties.propertyNames();
while (propertyKeys.hasMoreElements()) {
String key = (String) propertyKeys.nextElement();
String value = systemProperties.getProperty(key);
if (value == null) {
value = "null";
}
Xpp3Dom property = createElement(properties, "property");
property.setAttribute("name", key);
property.setAttribute("value", value);
}
}
if (configuration != null) {
Iterator it = configuration.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
Object obj = (Object) configuration.get(key);
String value = null;
if (obj == null) {
value = "null";
} else if (obj instanceof String) {
value = (String) obj;
} else {
value = obj.toString();
}
Xpp3Dom property = createElement(properties, "property");
property.setAttribute("name", key);
property.setAttribute("value", value);
}
}
Xpp3Dom bundle = createElement(properties, "property");
Bundle[] bundles = bc.getBundles();
for (int i = 0; i < bundles.length; i++) {
String sn = bundles[i].getSymbolicName();
String state = "UNKNOWN";
switch(bundles[i].getState()) {
case Bundle.ACTIVE:
state = "ACTIVE";
break;
case Bundle.INSTALLED:
state = "INSTALLED";
break;
case Bundle.RESOLVED:
state = "RESOLVED";
break;
case Bundle.UNINSTALLED:
state = "UNINSTALLED";
break;
default:
break;
}
bundle.setAttribute("name", "bundle-" + sn);
bundle.setAttribute("value", state);
}
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project felix by apache.
the class XMLReport method createTestElement.
/**
* Creates a XML test case element.
* @param test the test
* @param runTime the elapsed time to execute the test.
* @return the XML element describing the given test.
*/
private Xpp3Dom createTestElement(Test test, long runTime) {
Xpp3Dom testCase = new Xpp3Dom("testcase");
testCase.setAttribute("name", getReportName(test));
double time = (double) runTime / (double) 1000;
testCase.setAttribute("time", Double.toString(time));
testCase.setAttribute("classname", test.getClass().getName());
return testCase;
}
use of org.codehaus.plexus.util.xml.Xpp3Dom in project meecrowave by apache.
the class MeecrowaveRunMojoTest method run.
@Test
public void run() throws Exception {
final File moduleBase = jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" + getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
final ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
final DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(repositorySession, new LocalRepository(new File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project = mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
final MavenSession session = mojo.newMavenSession(project);
final int port;
try (final ServerSocket serverSocket = new ServerSocket(0)) {
port = serverSocket.getLocalPort();
}
final MojoExecution execution = mojo.newMojoExecution("run");
execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {
{
setValue(Integer.toString(port));
}
});
final InputStream in = System.in;
final CountDownLatch latch = new CountDownLatch(1);
System.setIn(new InputStream() {
// just to not return nothing
private int val = 2;
@Override
public int read() throws IOException {
try {
latch.await();
} catch (final InterruptedException e) {
Thread.interrupted();
fail(e.getMessage());
}
return val--;
}
});
final Thread runner = new Thread() {
@Override
public void run() {
try {
mojo.executeMojo(session, project, execution);
} catch (final Exception e) {
fail(e.getMessage());
}
}
};
try {
runner.start();
for (int i = 0; i < 120; i++) {
try {
assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + port + "/api/test")));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("first_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("last_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("firstname"));
assertTrue(IOUtils.toString(new URL("http://localhost:" + port + "/api/test/model")).contains("null"));
latch.countDown();
break;
} catch (final Exception | AssertionError e) {
Thread.sleep(500);
}
}
} finally {
runner.join(TimeUnit.MINUTES.toMillis(1));
System.setIn(in);
if (runner.isAlive()) {
runner.interrupt();
fail("Runner didn't terminate properly");
}
}
}
Aggregations