1  package com.palantir.blog.processspawner;
2  /*
3   * All source code and information in this file is made
4   * available under the following licensing terms:
5   *
6   * Copyright (c) 2009, Palantir Technologies, Inc.
7   * All rights reserved.
8   *
9   * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are
11  * met:
12  *
13  *     * Redistributions of source code must retain the above copyright
14  *       notice, this list of conditions and the following disclaimer.
15  *
16  *     * Redistributions in binary form must reproduce the above
17  *       copyright notice, this list of conditions and the following
18  *       disclaimer in the documentation and/or other materials provided
19  *       with the distribution.
20  *
21  *     * Neither the name of Palantir Technologies, Inc. nor the names of its
22  *       contributors may be used to endorse or promote products derived
23  *       from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  *
38  */ 
39 import org.apache.log4j.Appender;
40 import org.apache.log4j.ConsoleAppender;
41 import org.apache.log4j.Layout;
42 import org.apache.log4j.Level;
43 import org.apache.log4j.LogManager;
44 import org.apache.log4j.Logger;
45 import org.apache.log4j.PatternLayout;
46 import org.junit.runner.JUnitCore;
47 import org.junit.runner.Result;
48 import org.junit.runner.notification.Failure;
49 
50 /**
51  * A simple main() wrapper around JUnit to avoid some formatting issues with the default runner.
52  * @author regs
53  *
54  */
55 public class Example {
56 
57    public static void main(String[] args) {
58       
59       /*
60        * Set up log4j logging
61        */
62       final Layout layout = new PatternLayout("%p [%t] %c{1} - %m%n");
63       Appender a = new ConsoleAppender(layout);
64       Logger palantirLogger = LogManager.getLogger("com.palantir");
65       palantirLogger.setLevel(Level.INFO);
66       palantirLogger.addAppender(a);
67       
68       /*
69        *  run junit ourselves to avoid the default TextListener output
70        */
71       final Result r = JUnitCore.runClasses(ServerSpawningTest.class);
72       if(r.getFailureCount() == 0) {
73          System.out.println("SUCCESS: all " + r.getRunCount() + " tests passed");
74       } else {
75          System.out.println("FAILURE: " + r.getFailureCount() + 
76                             "/" + r.getRunCount() + " failed");
77          for(Failure f : r.getFailures()) {
78             System.out.println("\t" + f.getTestHeader() + ": " + f.getMessage());
79          }
80       }
81    }
82 }
83