View Javadoc
1   /*
2    * Copyright 2017-2022 original authors
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    * You may obtain a copy of the License at
7    *
8    * https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package io.micronaut.build.testresources;
17  
18  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
19  import com.fasterxml.jackson.annotation.JsonProperty;
20  import com.fasterxml.jackson.annotation.JsonRootName;
21  import org.apache.maven.plugins.annotations.Parameter;
22  
23  import static io.micronaut.build.testresources.StopTestResourcesServerMojo.MICRONAUT_TEST_RESOURCES_KEEPALIVE;
24  
25  /**
26   * Base configuration class for Test Resources.
27   *
28   * @author Álvaro Sánchez-Mariscal
29   * @since 3.5.1
30   */
31  @JsonRootName("configuration")
32  @JsonIgnoreProperties(ignoreUnknown = true)
33  public class TestResourcesConfiguration {
34  
35      public static final String DISABLED = "false";
36      public static final String CONFIG_PROPERTY_PREFIX = "micronaut.test.resources.";
37  
38      private static final String PROPERTY_ENABLED = "enabled";
39  
40      /**
41       * Whether to enable or disable Micronaut test resources support.
42       */
43      @Parameter(property =  CONFIG_PROPERTY_PREFIX + PROPERTY_ENABLED, defaultValue = DISABLED)
44      @JsonProperty(PROPERTY_ENABLED)
45      protected boolean testResourcesEnabled;
46  
47      /**
48       * Whether the test resources service should be shared between independent builds
49       * (e.g different projects, even built with different build tools).
50       */
51      @Parameter(property = CONFIG_PROPERTY_PREFIX + "shared", defaultValue = DISABLED)
52      protected boolean shared;
53  
54      /**
55       * Whether the test resources service should be kept alive after the build.
56       */
57      @Parameter(property = MICRONAUT_TEST_RESOURCES_KEEPALIVE, defaultValue = DISABLED)
58      protected boolean keepAlive;
59  
60      /**
61       * Allows configuring a namespace for the shared test resources server. This can be used in case it makes sense to
62       * have different instances of shared services, for example when independent builds sets share different services.
63       *
64       * @since 3.5.1
65       */
66      @Parameter(property = CONFIG_PROPERTY_PREFIX + "namespace")
67      protected String sharedServerNamespace;
68  
69      /**
70       * @return Whether to enable or disable Micronaut test resources support.
71       */
72      public boolean isTestResourcesEnabled() {
73          return testResourcesEnabled;
74      }
75  
76      /**
77       * @return Whether the test resources service should be shared between independent builds.
78       */
79      public boolean isShared() {
80          return shared;
81      }
82  
83      /**
84       * @return Whether the test resources service should be kept alive after the build.
85       */
86      public boolean isKeepAlive() {
87          return keepAlive;
88      }
89  
90      /**
91       * @return The shared server namespace (if any).
92       */
93      public String getSharedServerNamespace() {
94          return sharedServerNamespace;
95      }
96  }