View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package de.softwareforge.testing.postgres.junit5;
15  
16  import de.softwareforge.testing.postgres.embedded.DatabaseManager;
17  import de.softwareforge.testing.postgres.embedded.DatabasePreparer;
18  import de.softwareforge.testing.postgres.embedded.EmbeddedPostgres;
19  import de.softwareforge.testing.postgres.embedded.EmbeddedPostgresPreparer;
20  
21  import javax.sql.DataSource;
22  
23  import edu.umd.cs.findbugs.annotations.NonNull;
24  
25  
26  /**
27   * Create a new PostgreSQL server that supports a single database.
28   */
29  public final class SingleDatabaseBuilder {
30  
31      private SingleDatabaseBuilder() {
32          throw new AssertionError("SingleDatabaseBuilder can not be instantiated");
33      }
34  
35      /**
36       * Create a builder without any customizations applied.
37       *
38       * @return A {@link DatabaseManager.Builder<EmbeddedPgExtension>} instance that can be customized further.
39       */
40      @NonNull
41      public static DatabaseManager.Builder<EmbeddedPgExtension> instance() {
42          return EmbeddedPgExtension.singleDatabase();
43      }
44  
45      /**
46       * Create a builder with standard initializations ({@link EmbeddedPostgres.Builder#withDefaults()}) applied.
47       *
48       * @return A {@link DatabaseManager.Builder<EmbeddedPgExtension>} instance that can be customized further.
49       */
50      @NonNull
51      public static DatabaseManager.Builder<EmbeddedPgExtension> instanceWithDefaults() {
52          return EmbeddedPgExtension.singleDatabase().withInstancePreparer(EmbeddedPostgres.Builder::withDefaults);
53      }
54  
55      /**
56       * @deprecated Use {@link #preparedInstance(EmbeddedPostgresPreparer)}.
57       */
58      @Deprecated
59      @NonNull
60      public static DatabaseManager.Builder<EmbeddedPgExtension> preparedInstance(@NonNull DatabasePreparer preparer) {
61          return EmbeddedPgExtension.singleDatabase().withPreparer(preparer);
62      }
63  
64      /**
65       * @deprecated Use {@link #preparedInstanceWithDefaults(EmbeddedPostgresPreparer)}.
66       */
67      @Deprecated
68      @NonNull
69      public static DatabaseManager.Builder<EmbeddedPgExtension> preparedInstanceWithDefaults(@NonNull DatabasePreparer preparer) {
70          return EmbeddedPgExtension.singleDatabase().withPreparer(preparer).withCustomizer(EmbeddedPostgres.Builder::withDefaults);
71      }
72  
73      /**
74       * Create a builder and register a {@link EmbeddedPostgresPreparer<DataSource>} to set up the database.
75       *
76       * @param databasePreparer A {@link EmbeddedPostgresPreparer<DataSource>} instance. Must not be null.
77       * @return A {@link DatabaseManager.Builder<EmbeddedPgExtension>} instance that can be customized further.
78       */
79      @NonNull
80      public static DatabaseManager.Builder<EmbeddedPgExtension> preparedInstance(@NonNull EmbeddedPostgresPreparer<DataSource> databasePreparer) {
81          return EmbeddedPgExtension.singleDatabase().withDatabasePreparer(databasePreparer);
82      }
83  
84      /**
85       * Create a builder with standard initializations ({@link EmbeddedPostgres.Builder#withDefaults()}) applied and register a {@link
86       * EmbeddedPostgresPreparer<DataSource>} to set up the database.
87       *
88       * @param databasePreparer A {@link EmbeddedPostgresPreparer<DataSource>} instance. Must not be null.
89       * @return A {@link DatabaseManager.Builder<EmbeddedPgExtension>} instance that can be customized further.
90       */
91      @NonNull
92      public static DatabaseManager.Builder<EmbeddedPgExtension> preparedInstanceWithDefaults(@NonNull EmbeddedPostgresPreparer<DataSource> databasePreparer) {
93          return EmbeddedPgExtension.singleDatabase().withDatabasePreparer(databasePreparer).withInstancePreparer(EmbeddedPostgres.Builder::withDefaults);
94      }
95  }