001/* 002 * Copyright 2017-2022 original authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.micronaut.maven.testresources; 017 018import org.apache.maven.plugins.annotations.Parameter; 019 020/** 021 * Base configuration class for Test Resources. 022 * 023 * @author Álvaro Sánchez-Mariscal 024 * @since 3.5.1 025 */ 026public class TestResourcesConfiguration { 027 028 public static final String DISABLED = "false"; 029 public static final String CONFIG_PROPERTY_PREFIX = "micronaut.test.resources."; 030 031 private static final String PROPERTY_ENABLED = "enabled"; 032 public static final String TEST_RESOURCES_ENABLED_PROPERTY = CONFIG_PROPERTY_PREFIX + PROPERTY_ENABLED; 033 034 /** 035 * Whether to enable or disable Micronaut test resources support. 036 */ 037 @Parameter(property = TEST_RESOURCES_ENABLED_PROPERTY, defaultValue = DISABLED) 038 protected boolean testResourcesEnabled; 039 040 /** 041 * Whether the test resources service should be shared between independent builds 042 * (e.g. different projects, even built with different build tools). 043 */ 044 @Parameter(property = CONFIG_PROPERTY_PREFIX + "shared", defaultValue = DISABLED) 045 protected boolean shared; 046 047 /** 048 * Allows configuring a namespace for the shared test-resources server. This can be used in case it makes sense to 049 * have different instances of shared services, for example when independent builds sets share different services. 050 * 051 * @since 3.5.1 052 */ 053 @Parameter(property = CONFIG_PROPERTY_PREFIX + "namespace") 054 protected String sharedServerNamespace; 055 056 /** 057 * Allows starting the test resources server in debug mode. The server will be started with the ability 058 * to attach a remote debugger on port 8000. 059 * 060 * @since 4.2.0 061 */ 062 @Parameter(property = CONFIG_PROPERTY_PREFIX + "debug-server", defaultValue = DISABLED) 063 protected boolean debugServer; 064 065 /** 066 * Whether the test resources server should be started in the foreground. 067 * 068 * @since 4.7.0 069 */ 070 @Parameter(property = CONFIG_PROPERTY_PREFIX + "foreground", defaultValue = DISABLED) 071 protected boolean foreground; 072 073 /** 074 * @return Whether to enable or disable Micronaut test resources support. 075 */ 076 public boolean isTestResourcesEnabled() { 077 return testResourcesEnabled; 078 } 079 080 /** 081 * @return Whether the test resources service should be shared between independent builds. 082 */ 083 public boolean isShared() { 084 return shared; 085 } 086 087 /** 088 * @return The shared server namespace (if any). 089 */ 090 public String getSharedServerNamespace() { 091 return sharedServerNamespace; 092 } 093 094 /** 095 * Whether to enable or disable Micronaut test resources support. 096 * 097 * @param testResourcesEnabled enabled flag 098 */ 099 public void setTestResourcesEnabled(boolean testResourcesEnabled) { 100 this.testResourcesEnabled = testResourcesEnabled; 101 } 102 103 /** 104 * Whether the test resources service should be shared between independent builds. 105 * 106 * @param shared shared flag 107 */ 108 public void setShared(boolean shared) { 109 this.shared = shared; 110 } 111 112 /** 113 * The shared server namespace (if any). 114 * 115 * @param sharedServerNamespace the shared server namespace to be set 116 */ 117 public void setSharedServerNamespace(String sharedServerNamespace) { 118 this.sharedServerNamespace = sharedServerNamespace; 119 } 120 121 /** 122 * Whether to start the test resources server in debug mode. 123 * 124 * @param debugServer debug flag 125 */ 126 public void setDebugServer(boolean debugServer) { 127 this.debugServer = debugServer; 128 } 129}