• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package utils.resources;
17 
18 import java.lang.annotation.ElementType;
19 import java.lang.annotation.Retention;
20 import java.lang.annotation.RetentionPolicy;
21 import java.lang.annotation.Target;
22 
23 /**
24  * Annotation for resources required for the test case. It could be applied to
25  * either a type (test class) or a method (test method).
26  */
27 @Retention(RetentionPolicy.RUNTIME)
28 @Target({ElementType.METHOD, ElementType.TYPE})
29 public @interface RequiredResources {
30 
31     /**
32      * An array of RequiredResource annotations
33      */
value()34     RequiredResource[] value() default {};
35 
36     enum ResourceCreationPolicy {
37         /**
38          * Existing resource will be reused if it matches the required resource
39          * definition (i.e. TestResource.getResourceStatus() returns AVAILABLE).
40          */
41         REUSE_EXISTING,
42         /**
43          * Always destroy existing resources (if any) and then recreate new ones for test.
44          */
45         ALWAYS_RECREATE;
46     }
47 
48     enum ResourceRetentionPolicy {
49         /**
50          * Do not delete the created resource after test.
51          */
52         KEEP,
53         /**
54          * When used for @RequiredAnnota
55          */
56         DESTROY_IMMEDIATELY,
57         DESTROY_AFTER_ALL_TESTS;
58     }
59 
60     @interface RequiredResource {
61 
62         /**
63          * The Class object of the TestResource class
64          */
resource()65         Class<? extends TestResource> resource();
66 
67         /**
68          * How the resource should be created before the test starts.
69          */
creationPolicy()70         ResourceCreationPolicy creationPolicy();
71 
72         /**
73          * Retention policy after the test is done.
74          */
retentionPolicy()75         ResourceRetentionPolicy retentionPolicy();
76     }
77 
78 }
79