diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/testng/FormatApiResultsListener.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/testng/FormatApiResultsListener.java new file mode 100644 index 0000000000..b4ed515d09 --- /dev/null +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/testng/FormatApiResultsListener.java @@ -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 apis = ImmutableSet.of("admin", "user"); + + private ThreadLocal threadTestStart = new ThreadLocal(); + + 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()) + ""; + } + +} diff --git a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java index 44083294cf..e153e4e221 100644 --- a/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java +++ b/labs/vcloud-director/src/test/java/org/jclouds/vcloud/director/v1_5/internal/BaseVCloudDirectorClientLiveTest.java @@ -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 { diff --git a/labs/vcloud-director/src/test/resources/logback.xml b/labs/vcloud-director/src/test/resources/logback.xml index c1bb1b78c4..660584a450 100644 --- a/labs/vcloud-director/src/test/resources/logback.xml +++ b/labs/vcloud-director/src/test/resources/logback.xml @@ -1,64 +1,27 @@ - - target/test-data/jclouds.log + + target/test-data/api.log - %d %-5p [%c] (%t) %m%n - - - - - target/test-data/jclouds-wire.log - - - %d %-5p [%c] (%t) %m%n - - - - - target/test-data/jclouds-compute.log - - - %d %-5p [%c] (%t) %m%n + %m%n - - target/test-data/jclouds-ssh.log - + - %d %-5p [%c] (%t) %m%n + %d %-5p [%c] %m%n - + - - - - - - - - - - - - - - - - - - - - - - - + + + +