mirror of https://github.com/apache/jclouds.git
Issue 857:formatted report for vcloud api coverage
This commit is contained in:
parent
d7ceaa2ac2
commit
88cff6372d
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you 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.jclouds.vcloud.director.testng;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.ITestListener;
|
||||
import org.testng.ITestResult;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Outputs test status to the logger {@code jclouds.vcloud.api}
|
||||
*
|
||||
* adapted from the following class:
|
||||
*
|
||||
* @see org.jclouds.test.testng.UnitTestTestNGListener
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class FormatApiResultsListener implements ITestListener {
|
||||
|
||||
public static final Logger logger = LoggerFactory.getLogger("jclouds.vcloud.api");
|
||||
|
||||
public static final Set<String> apis = ImmutableSet.of("admin", "user");
|
||||
|
||||
private ThreadLocal<Long> threadTestStart = new ThreadLocal<Long>();
|
||||
|
||||
public void onTestStart(ITestResult res) {
|
||||
if (methodInApiGroup(res)) {
|
||||
threadTestStart.set(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean methodInApiGroup(ITestResult res) {
|
||||
return Iterables.any(Arrays.asList(res.getMethod().getGroups()), Predicates.in(apis));
|
||||
}
|
||||
|
||||
synchronized public void onTestSuccess(ITestResult res) {
|
||||
if (methodInApiGroup(res)) {
|
||||
String statusLine = resultForState(res, "succeeded");
|
||||
logger.info(statusLine);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public void onTestFailure(ITestResult res) {
|
||||
if (methodInApiGroup(res)) {
|
||||
String statusLine = resultForState(res, "failed");
|
||||
logger.info(statusLine);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public void onTestSkipped(ITestResult res) {
|
||||
if (methodInApiGroup(res)) {
|
||||
String statusLine = resultForState(res, "skipped");
|
||||
logger.info(statusLine);
|
||||
}
|
||||
}
|
||||
|
||||
public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
|
||||
}
|
||||
|
||||
public void onStart(ITestContext arg0) {
|
||||
}
|
||||
|
||||
public void onFinish(ITestContext arg0) {
|
||||
}
|
||||
|
||||
private String resultForState(ITestResult res, String state) {
|
||||
return Joiner.on(',').join(getApi(res), getOperation(res), getDuration(), state);
|
||||
}
|
||||
|
||||
private String getApi(ITestResult res) {
|
||||
return Iterables.find(Arrays.asList(res.getMethod().getGroups()), Predicates.in(apis));
|
||||
}
|
||||
|
||||
private String getOperation(ITestResult res) {
|
||||
return res.getMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class).testName();
|
||||
}
|
||||
|
||||
private String getDuration() {
|
||||
return (System.currentTimeMillis() - threadTestStart.get()) + "";
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.jclouds.predicates.RetryablePredicate;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
|
@ -40,6 +41,7 @@ import org.jclouds.vcloud.director.v1_5.domain.Task;
|
|||
import org.jclouds.vcloud.director.v1_5.predicates.ReferenceTypePredicates;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.TaskSuccess;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Listeners;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -56,6 +58,7 @@ import com.google.inject.Module;
|
|||
* @author Adrian Cole
|
||||
* @author grkvlt@apache.org
|
||||
*/
|
||||
@Listeners(FormatApiResultsListener.class)
|
||||
@Test(groups = "live")
|
||||
public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServiceLiveTest {
|
||||
|
||||
|
|
|
@ -1,34 +1,16 @@
|
|||
<?xml version="1.0"?>
|
||||
<configuration scan="false">
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>target/test-data/jclouds.log</file>
|
||||
<appender name="API" class="ch.qos.logback.core.FileAppender">
|
||||
<file>target/test-data/api.log</file>
|
||||
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
|
||||
<Pattern>%m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="WIREFILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>target/test-data/jclouds-wire.log</file>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="COMPUTEFILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>target/test-data/jclouds-compute.log</file>
|
||||
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="SSHFILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>target/test-data/jclouds-ssh.log</file>
|
||||
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
|
||||
<Pattern>%d %-5p [%c] %m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
|
@ -36,29 +18,10 @@
|
|||
<level value="warn" />
|
||||
</root>
|
||||
|
||||
<logger name="org.jclouds">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="FILE" />
|
||||
</logger>
|
||||
|
||||
<logger name="jclouds.wire">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="WIREFILE" />
|
||||
</logger>
|
||||
|
||||
<logger name="jclouds.headers">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="WIREFILE" />
|
||||
</logger>
|
||||
|
||||
<logger name="jclouds.compute">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="COMPUTEFILE" />
|
||||
</logger>
|
||||
|
||||
<logger name="jclouds.ssh">
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="SSHFILE" />
|
||||
<logger name="jclouds.vcloud.api">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="API" />
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
</configuration>
|
||||
|
|
Loading…
Reference in New Issue