001package org.atteo.moonshine.tests; 002 003import java.lang.annotation.ElementType; 004import java.lang.annotation.Retention; 005import java.lang.annotation.RetentionPolicy; 006import java.lang.annotation.Target; 007 008import org.atteo.moonshine.Moonshine; 009 010/** 011 * Can be specified on a test class extending {@link MoonshineTest}. Allows to 012 * specify configuration resources to use when starting {@link Moonshine} 013 * framework. 014 */ 015@Retention(RetentionPolicy.RUNTIME) 016@Target(ElementType.TYPE) 017public @interface MoonshineConfiguration { 018 019 /** 020 * Represents one possible configuration. 021 */ 022 public @interface Config { 023 /** 024 * Configuration name. 025 */ 026 String id(); 027 028 /** 029 * List of resources to use as configuration for {@link Moonshine}. 030 */ 031 String[] value() default {}; 032 033 /** 034 * In-place configuration. 035 */ 036 String fromString() default ""; 037 } 038 039 /** 040 * Represents a list of configurations from which at most only one will be used at given time. 041 */ 042 public @interface Alternatives { 043 Config[] value() default {}; 044 } 045 046 /** 047 * List of resources to use as configuration for {@link Moonshine}. 048 */ 049 String[] value() default {}; 050 051 /** 052 * Executes the test multiple times. Once for each provided {@link Config}. 053 * <p> 054 * <pre> 055 * For instance: 056 * @MoonshineConfiguration(forEach = 057 * @Config("/a.xml"), 058 * @Config("/b.xml") 059 * ) 060 * </pre> 061 * This will execute the test 2 times. Once with a.xml and the second tiem with b.xml configuration file. 062 * </p> 063 */ 064 Config[] forEach() default {}; 065 066 /** 067 * Executes the test multiple times. For each execution one {@link Config} will be taken from 068 * each {@link Alternatives} list. The test will be run for every possible combination of Configs. 069 * <p> 070 * For instance: 071 * <pre> 072 * @MoonshineConfiguration(forCartesianProductOf = 073 * @Alternatives( 074 * @Config("/a.xml"), 075 * @Config("/b.xml") 076 * ), 077 * @Alternatives( 078 * @Config("/1.xml"), 079 * @Config("/2.xml"), 080 * @Config("/3.xml") 081 * ) 082 * ) 083 * </pre> 084 * 085 * This will execute the test 6 times for 086 * <ol> 087 * <li>a.xml combined with 1.xml</li> 088 * <li>a.xml combined with 2.xml</li> 089 * <li>a.xml combined with 3.xml</li> 090 * <li>b.xml combined with 1.xml</li> 091 * <li>b.xml combined with 2.xml</li> 092 * <li>b.xml combined with 3.xml</li> 093 * </p> 094 * 095 */ 096 Alternatives[] forCartesianProductOf() default {}; 097 098 /** 099 * In-place configuration. 100 */ 101 String fromString() default ""; 102 103 /** 104 * Allows to enable auto-configuration. 105 * <p> 106 * Auto configuration is automatically generated and consists of every top-level service found on classpath 107 * which does not require any configuration. It is always stored in ${configHome}/auto-config.xml 108 * file. 109 * </p> 110 */ 111 boolean autoConfiguration() default false; 112 113 /** 114 * Skip reading default configuration from '/default-config.xml' classpath resource. 115 */ 116 boolean skipDefault() default false; 117 118 /** 119 * If true, a request (scope) per entire test class will be created, 120 * default means that a request is created per method. 121 */ 122 boolean oneRequestPerClass() default false; 123 124 /** 125 * Command line arguments. 126 */ 127 String[] arguments() default {}; 128 129 /** 130 * Specifies external configurator for Moonshine. 131 */ 132 Class<? extends MoonshineConfigurator> configurator() default MoonshineConfigurator.class; 133}