diff --git a/configuration-parent/configuration-jar/README.md b/configuration-parent/configuration-jar/README.md index dad46aff6..12b0e23a6 100644 --- a/configuration-parent/configuration-jar/README.md +++ b/configuration-parent/configuration-jar/README.md @@ -1,7 +1,7 @@ The module is packaged as the uber jar that ables to generated DDL scripts that create the shared schema strategy based on configuration. Currently, the module supports only the YAML file extensions. -To see how to prepare a configuration file, please check the [configuration-yaml-interpreter](../configuration-yaml-interpreter) module. +To see how to prepare a configuration file, please check the [configuration-yaml-interpreter](../configuration-yaml-interpreter-parent/configuration-yaml-interpreter) module. The jar file required JAVA version 8 or newer. ### Usage diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/pom.xml b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/pom.xml similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/pom.xml rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/pom.xml diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DataSourceConfiguration.java b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DataSourceConfiguration.java similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DataSourceConfiguration.java rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DataSourceConfiguration.java diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationTest.java b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationTest.java similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationTest.java rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationTest.java diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationWithConnectionExecutionTest.java b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationWithConnectionExecutionTest.java similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationWithConnectionExecutionTest.java rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/DefaultYamlConfigurationWithConnectionExecutionTest.java diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestApplication.java b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestApplication.java similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestApplication.java rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestApplication.java diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/User.java b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/User.java similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/User.java rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/java/com/github/starnowski/posmulten/configuration/yaml/User.java diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application-docker.properties b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application-docker.properties similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application-docker.properties rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application-docker.properties diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application.properties b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application.properties similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application.properties rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/application.properties diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/clean-database.sql b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/clean-database.sql similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/clean-database.sql rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/clean-database.sql diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml diff --git a/configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/testng.xml b/configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/testng.xml similarity index 100% rename from configuration-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/testng.xml rename to configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter-functional-tests/src/test/resources/testng.xml diff --git a/configuration-parent/configuration-yaml-interpreter-parent/pom.xml b/configuration-parent/configuration-yaml-interpreter-parent/pom.xml new file mode 100644 index 000000000..bb22c0653 --- /dev/null +++ b/configuration-parent/configuration-yaml-interpreter-parent/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + com.github.starnowski.posmulten.configuration + configuration-parent + 0.9.0-SNAPSHOT + + + configuration-yaml-interpreter-parent + + configuration-yaml-interpreter + configuration-yaml-interpreter-functional-tests + + + \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/README.md b/configuration-parent/configuration-yaml-interpreter/README.md deleted file mode 100644 index 8cf45094c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/README.md +++ /dev/null @@ -1,500 +0,0 @@ -# Configuration-yaml-interpreter -The configuration-yaml-interpreter module can interpreted configuration file in yaml format and based on that it creates -DDL statements that allows to create the shared schema strategy. -The YAML schema description is below. - -* [Simple example](#simple-example) -* [Root properties](#root-properties) -* [Setting a list of invalid tenant identifier values](#setting-a-list-of-invalid-tenant-identifier-values) -* [Tables configuration](#tables-configuration) -* [SQL definitions validation](#sql-definitions-validation) -* [Custom SQL definitions](#custom-sql-definitions) -* [Details](#details) - -## Simple example: -Bellow, there is a configuration example for a schema with the name "public". -The schema contains four tables, users, posts, groups, and users_groups (many-to-many relation). -All generated changes are going to be applied for the database user with the name "application-user". - -```yaml -default_schema: public -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - tenant_identifiers_blacklist: - - invalid_tenant - - "wrong tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - create_tenant_column_for_table: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - create_tenant_column_for_table: true - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: groups - rls_policy: - name: groups_table_rls_policy - create_tenant_column_for_table: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_group_exists" - pk_columns_name_to_type: - uuid: UUID - - name: users_groups - rls_policy: - name: groups_table_rls_policy - create_tenant_column_for_table: true - foreign_keys: - - constraint_name: "users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "groups_tenant_constraint" - table_name: "groups" - foreign_key_primary_key_columns_mappings: - group_id: uuid -``` - -## Root properties -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| -|[default_schema](#default_schema) | String | Yes | Yes | Name of the database schema for which changes should be applied. | -|[current_tenant_id_property_type](#current_tenant_id_property_type) | String | No | No | Type of column that stores tenant identifier and it is also the type of parameters for some generated functions. | -|[current_tenant_id_property](#current_tenant_id_property) | String | No | No | Property name that stores the value of tenant identifier in the database connection. | -|[get_current_tenant_id_function_name](#get_current_tenant_id_function_name) | String | No | No | Name of the function that returns the current tenant identifier. | -|[set_current_tenant_id_function_name](#set_current_tenant_id_function_name) | String | No | No | Name of the function that sets the current tenant identifier. | -|[tenant_has_authorities_function_name](#tenant_has_authorities_function_name) | String | No | No | Name of the function name that checks if the current tenant has authority to a table row. | -|[force_row_level_security_for_table_owner](#force_row_level_security_for_table_owner) | Boolean | No | Yes | Option that force RLS policy for table owner. | -|[default_tenant_id_column](#default_tenant_id_column) | String | No | No | Default name of column that stores tenant identifier. | -|[grantee](#grantee) | String | Yes | No | Database user for which RLS policy is going to be created. | -|[create_foreignkey_constraint_with_tenant_column](#create_foreignkey_constraint_with_tenant_column) | Boolean | No | Yes | Create the foreign key constraint that tenant column is part of composite key. Instead of function that check if reference key exist for specific tenant. | - -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|[equals_current_tenant_identifier_function_name](#equals_current_tenant_identifier_function_name) | String | No | No | Name of the function name that checks if passed identifier is the same as the current tenant identifier. | -|[set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables](#set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables) | Boolean | No | Yes | Generate a statement that sets a default value for the tenant column in all tables. | - -## Setting a list of invalid tenant identifier values -The __valid_tenant_value_constraint__ object is used to configure constraint that will be added to all tenant column in all tables. -Constraint keeps tenant column value valid. - -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|tenant_identifiers_blacklist| Array of strings | Yes | No | An array of invalid values for tenant identifier. Array need have at least one element | -|[is_tenant_valid_function_name](#is_tenant_valid_function_name)| String | No | No | Name of the function that checks if passed tenant identifier is valid | -|[is_tenant_valid_constraint_name](#is_tenant_valid_constraint_name)| String | No | No | Name of the constraint that checks if the tenant column has a valid value | - -For example, if we want to specify "ROOT", "some_id" as invalid values for tenant identifier, the configuration should look just like below: - -```yaml -valid_tenant_value_constraint: - tenant_identifiers_blacklist: - - ROOT - - "some_id" -``` - -For more information please check [setting a list of invalid tenant identifier values](https://github.com/starnowski/posmulten#setting-a-list-of-invalid-tenant-identifier-values). - -## Tables configuration -The __tables__ property is an array of objects that each references to a single table. -The table object ables to configure things like the RLS policy or the constraint that checks if the foreign key belongs to the same tenant as a current logged tenant. -It is not mandatory to configure all tables. In some cases, there is no sense to create an entry for the table. -For example, tables that are supposed to use by all tenants, like dictionary tables, do not need to have a configured RLS policy. - -__Table object__ - -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|name | String | Yes | No | Name of table | -|schema | String | No | Yes | Name of schema. This property overrides the value of the [default_schema](#default_schema) for its table | -|[rls_policy](#rls_policy) | Object | No | No | Object that defines RLS for table | -|[foreign_keys](#foreign_keys) | Array of objects | No | No | An array of objects that defines foreign key constraint for a table with RLS policy | - -### rls_policy -The rls_policy entry is required to specify the RLS policy for table. - -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|name | String | Yes | No | Name of the RLS policy | -|tenant_column | String | No | No | Name of the column that stores tenant identifier. This property overrides the value of the [default_tenant_id_column](#default_tenant_id_column) for its table | -|[create_tenant_column_for_table](#create_tenant_column_for_table) | Boolean | No | No | Option force to create tenant column for table | -|valid_tenant_value_constraint_name | String | No | No | Name of the constraint that checks if the tenant column has a valid value. This property overrides the value of the [is_tenant_valid_constraint_name](#is_tenant_valid_constraint_name) for its table | -|[skip_adding_of_tenant_column_default_value](#skip_adding_of_tenant_column_default_value) | Boolean | No | No | Option force to skip adding default value to tenant column for a table | -|[primary_key_definition](#primary_key_definition) | Object | No | No | Object that defines primary keys for a table | - -### primary_key_definition -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|------------------------------------------------------------------------------------------------------------------------------|---------------|---------------| -|[pk_columns_name_to_type](#pk_columns_name_to_type) | Map | No | Yes | Map of primary key columns where the key is column name and value is its type | -|[name_for_function_that_checks_if_record_exists_in_table](#name_for_function_that_checks_if_record_exists_in_table) | String | if flag [create_foreignkey_constraint_with_tenant_column](#create_foreignkey_constraint_with_tenant_column) is null or false | Yes | Function name that checks if passed primary key for a specific table exists for the current tenant | - -### foreign_keys -An array of objects that defines foreign key constraint for a table with RLS policy. -Based on each array object, there is going to be created constraint that checks if a foreign key value refers to a record that exists for the current logged tenant. -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|constraint_name | String | Yes | No | Name of the constraint | -|table_name | String | Yes | No | Name of table that foreign key refers to | -|table_schema | String | No | Yes | Name of schema. This property overrides the value of the [default_schema](#default_schema) for its table | -|foreign_key_primary_key_columns_mappings | Map | Yes | No | The map that defines reference between foreign key and primary key columns. The map key is the foreign key column name and the value is the primary key column name | - -Below there are two examples of foreign keys configuration: -First is a simple example where we have table "users" and table "posts" that has a reference (foreign key) to the "users" table (user_id -> id) - -```yaml -default_schema: public -grantee: "application-user" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id -``` - -The second example shows a table that has a foreign key with two columns but also it has reference to itself (we assume that comment can have parent comment). - -```yaml -default_schema: public -grantee: "application-user" -tables: - - name: "comments" - rls_policy: - name: comments_table_rls_policy - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - random_uuid: UUID - foreign_keys: - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_random_uuid: random_uuid -``` - -## SQL definitions validation -The **sql_definitions_validation** property is used to configure the validation of generated sql definitions. -It is a complex type. - -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|disabled | Boolean | No | No | Validation toggle, by default property has value **false** which means that validation is enabled | -|identifier_max_length | Integer | No | No | Maximum allowed length for the identifier | -|identifier_min_length | Integer | No | No | Minimum allowed length for the identifier | - -Example: - -```yaml -sql_definitions_validation: - identifier_max_length: 76 - identifier_min_length: 5 - disabled: false -``` - -## Custom SQL Definitions - -The __custom_sql_definitions__ property is an array of objects that purpose is to define custom SQL definitions that should be added to the generated script. -Just like the [__tables__](#tables-configuration) property, it is also a top element of the configuration file just like in the below example. - -Example: -```yaml -tables: - - name: groups - -... - -custom_sql_definitions: - - position: AT_END - creation_script: | - ALTER TABLE groups ADD COLUMN text_col text; - drop_script: | - ALTER TABLE groups DROP COLUMN text_col; - validation_scripts: - - | - SELECT COUNT(1) FROM information_schema.columns WHERE table_catalog = 'postgresql_core' AND table_schema = 'public' AND table_name = 'groups' AND column_name = 'text_col'; - - position: CUSTOM - custom_position: "Some custom position" - creation_script: | - ALTER ... - validation_scripts: - - | - SELECT (371) FROM ... -``` - -__custom_sql_definitions__ object - -| Property name | Type | Required | Nullable | Description | -|---------------|-----------|---------------|---------------|---------------| -|position | String | Yes | No | Specify where definition should be added in generated script. Available values are AT_END (at the end), AT_BEGINNING (at the beginning) and CUSTOM. For the CUSTOM the __custom_position__ property has to be also specified | -|creation_script | String | Yes | No | SQL statement added to creation script | -|drop_script | String | No | No | SQL statement added to dropping script | -|validation_scripts | Array of strings | Yes | No | SQL statements that check if changes made by __creation_script__ were added. Each statement as result should return one integer column, value bigger than zero means that changes were applied correctly otherwise the changes were not applied | -|custom_position | String | Only if __position__ has the CUSTOM value | No | Custom position of the script. This does not have to be an integer value. There might be a case that some custom component was added in the code and it handles the definition with a specific position | - -## Details - -### default_schema -Name of the database schema for which changes should be applied. - -```yaml -default_schema: my_db_schema -``` - -Value can be null, in such case the changes are going to be applied to default schema (public). - -```yaml -default_schema: -``` - -For more information please check [setting default schema](https://github.com/starnowski/posmulten/tree/master#setting-default-database-schema). - -### current_tenant_id_property_type -Type of column that stores tenant identifier and it is also the type of parameters for some generated functions. -For example, for the below entries: - -```yaml -current_tenant_id_property_type: "VARCHAR(255)" -get_current_tenant_id_function_name: "get_ten_id" -``` - -the framework generates the below function: - -```sql -CREATE OR REPLACE FUNCTION get_current_tenant_id() RETURNS UUID AS $$ -SELECT current_setting('c.c_ten') -$$ LANGUAGE sql -STABLE -PARALLEL SAFE; -``` - -For more information please check [setting of type for tenant identifier value](https://github.com/starnowski/posmulten/tree/master#setting-of-type-for-tenant-identifier-value). - -### current_tenant_id_property -Property name that stores the value of tenant identifier in the database connection. -Example: -```yaml -current_tenant_id_property: "pos.c.ten" -``` -For more information please check [setting the property name that stores tenant identifier value](https://github.com/starnowski/posmulten#setting-the-property-name-that-stores-tenant-identifier-value). - -### get_current_tenant_id_function_name -Name of the function that returns the current tenant identifier. -For example, for the below entries: - -```yaml -get_current_tenant_id_function_name: "what_is_current_tenant" -``` - -the framework generates the below function: - -```sql -CREATE OR REPLACE FUNCTION what_is_current_tenant() RETURNS VARCHAR(255) AS $$ -SELECT current_setting('c.c_ten') -$$ LANGUAGE sql -STABLE -PARALLEL SAFE; -``` - -### set_current_tenant_id_function_name -Name of the function that sets the current tenant identifier. -For example, for the below entries: - -```yaml -set_current_tenant_id_function_name: "this_will_be_tenant" -``` - -the framework generates the below function: - -```sql -CREATE OR REPLACE FUNCTION this_will_be_tenant(VARCHAR(255)) RETURNS VOID AS $$ -BEGIN -PERFORM set_config('c.c_ten', $1, false); -END -$$ LANGUAGE plpgsql -VOLATILE; -``` - -### equals_current_tenant_identifier_function_name -Name of the function name that checks if passed identifier is the same as the current tenant identifier. -For example, for the below entries: - -```yaml -equals_current_tenant_identifier_function_name: "is_tenant_equals" -``` - -the framework generates the below function: - -```sql -CREATE OR REPLACE FUNCTION is_tenant_equals(VARCHAR(255)) RETURNS BOOLEAN AS $$ -SELECT $1 = get_current_tenant_id() -$$ LANGUAGE sql -STABLE -PARALLEL SAFE; -``` - -### tenant_has_authorities_function_name -Name of the function name that checks if the current tenant has authority to a table row. -For example, for the below entries: - -```yaml -tenant_has_authorities_function_name: "ten_has_auth" -``` - -the framework generates the below function: - -```sql -CREATE OR REPLACE FUNCTION ten_has_auth(VARCHAR(255), VARCHAR(255), VARCHAR(255), VARCHAR(255), VARCHAR(255)) RETURNS BOOLEAN AS $$ -SELECT is_id_equals_current_tenant_id($1) -$$ LANGUAGE sql -STABLE -PARALLEL SAFE; -``` - -### force_row_level_security_for_table_owner -Option that force RLS policy for table owner. -This option is required if the database user for which RLS is created is also a table owner. -By default option is turned off. -Example: -```yaml -force_row_level_security_for_table_owner: true -``` -For more information please check [force RLS Policy for table owner](https://github.com/starnowski/posmulten#force-rls-policy-for-table-owner). - -### default_tenant_id_column -The default name of the column that stores the tenant identifier. -This name is used when the table does not have a specified custom name for the column that stores the tenant identifier. -Example: -```yaml -default_tenant_id_column: "tenant_uuid" -``` -For more information please check [setting default tenant column name](https://github.com/starnowski/posmulten#setting-default-tenant-column-name). - -### grantee -Database user for which RLS policy is going to be created. -Example: -```yaml -grantee: "application-user" -``` -For more information please check [setting default database user for RLS policy](https://github.com/starnowski/posmulten#setting-default-database-user-for-rls-policy). - -### create_foreignkey_constraint_with_tenant_column - -Create the foreign key constraint that tenant column is part of composite key. -Instead of function that check if reference key exist for specific tenant. - -Example: -```yaml -create_foreignkey_constraint_with_tenant_column: true -``` -For more information please check [setting foreign key constraint where tenant column is part of composite key](https://github.com/starnowski/posmulten#setting-foreign-key-constraint-where-tenant-column-is-part-of-composite-key). - -### set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables -Generate a statement that sets a default value for the tenant column in all tables. -This functionality is useful when we don't always want to specified tenant id value in the insert statement. -By default option is turned off. -Example: -```yaml -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -``` -For more information please check [adding default value for tenant column](https://github.com/starnowski/posmulten#adding-default-value-for-tenant-column). - -### is_tenant_valid_function_name -Name of the function that checks if passed tenant identifier is valid. -For example, for the below entries: - -```yaml -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_this_tenant_valid - tenant_identifiers_blacklist: - - DUMMMY_TENANT - - "XXX-INVAlid_tenant" -``` - -the framework generates the below function: - -```sql -CREATE OR REPLACE FUNCTION is_this_tenant_valid(VARCHAR(255)) RETURNS BOOLEAN AS $$ -SELECT $1 <> CAST ('DUMMMY_TENANT' AS VARCHAR(255)) AND $1 <> CAST ('XXX-INVAlid_tenant' AS VARCHAR(255)) -$$ LANGUAGE sql -IMMUTABLE -PARALLEL SAFE; -``` - -For more information please check [setting a list of invalid tenant identifier values](https://github.com/starnowski/posmulten#setting-a-list-of-invalid-tenant-identifier-values). - -### is_tenant_valid_constraint_name -Name of the constraint that checks if the tenant column has a valid value. -For example, for the below entries: - -```yaml -valid_tenant_value_constraint: - is_tenant_valid_constraint_name: tenant_must_be_valid - is_tenant_valid_function_name: is_this_tenant_valid - tenant_identifiers_blacklist: - - ..... -``` - -the framework generates the below function: - -```sql -ALTER TABLE "posts" ADD CONSTRAINT tenant_must_be_valid CHECK (tenant_id IS NULL OR is_this_tenant_valid(tenant_id)); -``` - -For more information please check [setting a list of invalid tenant identifier values](https://github.com/starnowski/posmulten#setting-a-list-of-invalid-tenant-identifier-values). - -### create_tenant_column_for_table -Option force to create tenant column for the table. -By default, the Posmulten library assumes that the tenant column exists. -To check what kind of DDL statements are generated for tenant column definition please check the [adding tenant column to tenant table](https://github.com/starnowski/posmulten#adding-tenant-column-to-tenant-table). - -### skip_adding_of_tenant_column_default_value -Option force to skip adding default value to tenant column for table. -This option make sense to use when the [set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables](#set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables) option is turned on. -It simply allows to skip adding default value definition for tenant column is specified table. -For more information please check [skipping adding default value for tenant column for a single table](https://github.com/starnowski/posmulten#skipping-adding-default-value-for-tenant-column-for-a-single-table). - -### pk_columns_name_to_type -Map of primary key columns where the key is column name and value is its type. -The map can be empty or even null. -This is a valid case for example for a many-to-many relation table without any primary key, just with foreign keys for tables that it refers to. - -### name_for_function_that_checks_if_record_exists_in_table -Function name that checks if passed primary key for a specific table exists for the current tenant. -This function is generated only when some other table has a [foreign key](#foreign_keys) that refers to the primary key table. -if flag [create_foreignkey_constraint_with_tenant_column](#create_foreignkey_constraint_with_tenant_column) is null or false then value is mandatory. - -For more information please check: -* [adding constraints for foreign key columns](https://github.com/starnowski/posmulten#adding-constraints-for-foreign-key-columns) -* [setting function name that checks if passed primary key for a specific table exists for the current tenant](https://github.com/starnowski/posmulten#setting-function-name-that-checks-if-passed-primary-key-for-a-specific-table-exists-for-the-current-tenant) diff --git a/configuration-parent/configuration-yaml-interpreter/pom.xml b/configuration-parent/configuration-yaml-interpreter/pom.xml deleted file mode 100644 index 8f55309cc..000000000 --- a/configuration-parent/configuration-yaml-interpreter/pom.xml +++ /dev/null @@ -1,175 +0,0 @@ - - - - configuration-parent - com.github.starnowski.posmulten.configuration - 0.9.0-SNAPSHOT - - 4.0.0 - - com.github.starnowski.posmulten.configuration - configuration-yaml-interpreter - - - 2.11.1 - 6.0.20.Final - ${project.parent.basedir}/.. - - - - - com.github.starnowski.posmulten.configuration - configuration-core - ${project.version} - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - ${com.fasterxml.jackson.dataformat.jackson-dataformat-yaml.version} - - - com.fasterxml.jackson.datatype - jackson-datatype-jdk8 - ${com.fasterxml.jackson.dataformat.jackson-dataformat-yaml.version} - - - org.hibernate.validator - hibernate-validator - ${org.hibernate.validator.version} - - - javax.el - javax.el-api - 3.0.0 - - - org.glassfish.web - javax.el - 2.2.6 - - - org.spockframework - spock-core - - - org.projectlombok - lombok - - - com.github.starnowski.posmulten - test-utils - ${project.version} - test - - - org.codehaus.groovy - groovy-all - - - org.jeasy - easy-random-core - - - net.bytebuddy - byte-buddy - - - - - - cobertura - - - cobertura.active - true - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - - pitest - - false - - - - - org.pitest - pitest-maven - 1.9.9 - - - STRONGER - - 95 - - com.github.starnowski.posmulten.configuration.yaml.model.* - - - - - - - - - - - - org.codehaus.gmavenplus - gmavenplus-plugin - 1.5 - - - - compile - testCompile - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.1 - - once - -Duser.language=en - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - - \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/IConfigurationMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/IConfigurationMapper.java deleted file mode 100644 index 83b5c8d1d..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/IConfigurationMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml; - -public interface IConfigurationMapper{ - - O map(I input); - - I unmap(O output); -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactory.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactory.java deleted file mode 100644 index 9e22cad8e..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.context; - -import com.github.starnowski.posmulten.configuration.core.context.AbstractDefaultSharedSchemaContextBuilderFactory; -import com.github.starnowski.posmulten.configuration.core.exceptions.InvalidConfigurationException; -import com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration; -import com.github.starnowski.posmulten.configuration.yaml.dao.SharedSchemaContextConfigurationYamlDao; -import com.github.starnowski.posmulten.configuration.yaml.exceptions.YamlInvalidSchema; -import com.github.starnowski.posmulten.configuration.yaml.mappers.SharedSchemaContextConfigurationMapper; - -import java.io.IOException; - -public class YamlConfigurationDefaultSharedSchemaContextBuilderFactory extends AbstractDefaultSharedSchemaContextBuilderFactory { - - private final SharedSchemaContextConfigurationYamlDao dao = new SharedSchemaContextConfigurationYamlDao(); - private final SharedSchemaContextConfigurationMapper mapper = new SharedSchemaContextConfigurationMapper(); - - @Override - protected SharedSchemaContextConfiguration prepareConfigurationBasedOnContent(String content) throws InvalidConfigurationException { - com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration yamlConfiguration = null; - try { - yamlConfiguration = dao.readFromContent(content); - } catch (IOException e) { - throw new RuntimeException(e); - } - return mapper.unmap(yamlConfiguration); - } - - @Override - protected SharedSchemaContextConfiguration prepareConfigurationBasedOnFile(String filePath) throws YamlInvalidSchema { - com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration yamlConfiguration = null; - try { - yamlConfiguration = dao.read(filePath); - } catch (IOException e) { - throw new RuntimeException(e); - } - return mapper.unmap(yamlConfiguration); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplier.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplier.java deleted file mode 100644 index 00506cf52..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplier.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.context; - -import com.github.starnowski.posmulten.configuration.core.context.AbstractDefaultSharedSchemaContextBuilderFactorySupplier; -import com.github.starnowski.posmulten.configuration.core.context.IDefaultSharedSchemaContextBuilderFactory; - -import java.util.List; -import java.util.function.Supplier; - -import static java.util.Arrays.asList; - -public class YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplier extends AbstractDefaultSharedSchemaContextBuilderFactorySupplier { - @Override - public Supplier getFactorySupplier() { - return YamlConfigurationDefaultSharedSchemaContextBuilderFactory::new; - } - - @Override - public List getSupportedFileExtensions() { - return asList("yaml", "yml"); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDao.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDao.java deleted file mode 100644 index dff7b3658..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDao.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.dao; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.github.starnowski.posmulten.configuration.yaml.exceptions.YamlInvalidSchema; -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration; -import com.github.starnowski.posmulten.configuration.yaml.validation.groups.ValidatorGroupsResolver; -import org.hibernate.validator.internal.engine.path.NodeImpl; -import org.hibernate.validator.internal.engine.path.PathImpl; - -import javax.validation.*; -import javax.validation.groups.Default; -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.*; - -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; -import static javax.validation.ElementKind.CONTAINER_ELEMENT; -import static javax.validation.ElementKind.PROPERTY; - -public class SharedSchemaContextConfigurationYamlDao { - - private final ObjectMapper mapper; - - public SharedSchemaContextConfigurationYamlDao() { - mapper = new ObjectMapper(new YAMLFactory()); - mapper.registerModule(new Jdk8Module()); - } - - public SharedSchemaContextConfiguration read(String filePath) throws IOException, YamlInvalidSchema { - SharedSchemaContextConfiguration result = mapper.readValue(new File(filePath), SharedSchemaContextConfiguration.class); - validateConfigurationObject(result); - return result; - } - - public SharedSchemaContextConfiguration readFromContent(String content) throws IOException, YamlInvalidSchema { - SharedSchemaContextConfiguration result = mapper.readValue(content, SharedSchemaContextConfiguration.class); - validateConfigurationObject(result); - return result; - } - - public void save(SharedSchemaContextConfiguration configuration, String filePath) throws IOException, YamlInvalidSchema { - validateConfigurationObject(configuration); - mapper.writeValue(new File(filePath), configuration); - } - - private void validateConfigurationObject(SharedSchemaContextConfiguration configuration) throws YamlInvalidSchema { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - Validator validator = factory.getValidator(); - ValidatorGroupsResolver validatorGroupsResolver = new ValidatorGroupsResolver(); - List validationGroupsList = validatorGroupsResolver.resolveForSharedSchemaContextConfiguration(configuration, null); - validationGroupsList.add(Default.class); - Class[] validationGroups = validationGroupsList.stream().filter(Objects::nonNull).collect(toList()).toArray(new Class[0]); - Set> errors = validator.validate(configuration, validationGroups); - if (!errors.isEmpty()) { - throw new YamlInvalidSchema(prepareErrorsMessages(errors)); - } - } - - private List prepareErrorsMessages(Set> errors) { - return errors.stream().map(error -> prepareErrorMessage(error)).collect(toList()); - } - - private String prepareErrorMessage(ConstraintViolation error) { - StringBuilder sb = new StringBuilder(); - sb.append(resolvePropertyPath(error)); - sb.append(" "); - sb.append(error.getMessage()); - return sb.toString(); - } - - private String resolvePropertyPath(ConstraintViolation error) { - StringBuilder sb = new StringBuilder(); - Path path = error.getPropertyPath(); - if (path instanceof PathImpl) { - List nodes = new ArrayList<>(); - PathImpl pathImpl = (PathImpl) path; - Iterator it = pathImpl.iterator(); - Path.Node parent = null; - for (; it.hasNext(); ) { - Path.Node node = it.next(); - if (parent == null) { - Class keyClass = SharedSchemaContextConfiguration.class; - prepareNodePathBasedOnParentNodeClass(nodes, node, keyClass); - } else { - NodeImpl parentImpl = (NodeImpl) parent; - if (PROPERTY.equals(parentImpl.getKind())) { - Class keyClass = parentImpl.getValue().getClass(); - prepareNodePathBasedOnParentNodeClass(nodes, node, keyClass); - } - } - parent = node; - } - sb.append(nodes.stream().collect(joining("."))); - } else { - sb.append(error.getPropertyPath()); - } - return sb.toString(); - } - - private void prepareNodePathBasedOnParentNodeClass(List nodes, Path.Node node, Class parentNodeClass) { - try { - if (node.getName() == null) { - return; - } - Field field = parentNodeClass.getDeclaredField(node.getName()); - JsonProperty annotation = field.getAnnotation(JsonProperty.class); - if (annotation != null) { - StringBuilder sb = new StringBuilder(); - sb.append(annotation.value() == null ? node.getName() : annotation.value()); - NodeImpl nodeImpl = (NodeImpl) node; - if (nodeImpl.isIterable() && returnNodeIndex(nodeImpl) != null) { - sb.append("["); - sb.append(returnNodeIndex(nodeImpl)); - sb.append("]"); - } - nodes.add(sb.toString()); - } - } catch (NoSuchFieldException e) { - if (CONTAINER_ELEMENT.equals(node.getKind())) { - if (node.getKey() != null) { - NodeImpl nodeImpl = (NodeImpl) node; - //nodeImpl.getTypeArgumentIndex() == 0 <- map key, nodeImpl.getTypeArgumentIndex() == 1 <- map value - if (nodeImpl.getTypeArgumentIndex() != null && nodeImpl.getTypeArgumentIndex() != 0) { - nodes.add(node.getKey().toString()); - return; - } - } - } - nodes.add(node.getName()); - } - } - - private Integer returnNodeIndex(NodeImpl nodeImpl) { - NodeImpl tmpNode = NodeImpl.createBeanNode(nodeImpl); - return tmpNode.getIndex(); - } - - -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/exceptions/YamlInvalidSchema.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/exceptions/YamlInvalidSchema.java deleted file mode 100644 index 09cb12b13..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/exceptions/YamlInvalidSchema.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.exceptions; - -import com.github.starnowski.posmulten.configuration.core.exceptions.InvalidConfigurationException; - -import java.util.List; - -import static java.util.Collections.unmodifiableList; -import static java.util.stream.Collectors.joining; - -public class YamlInvalidSchema extends InvalidConfigurationException { - - private final List errorMessages; - - public YamlInvalidSchema(List errorMessages) { - super(prepareExceptionMessage(errorMessages)); - this.errorMessages = unmodifiableList(errorMessages); - } - - public List getErrorMessages() { - return errorMessages; - } - - private static String prepareExceptionMessage(List errorMessages) { - return errorMessages.stream().collect(joining(", ")); - } - -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/CustomDefinitionEntryMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/CustomDefinitionEntryMapper.java deleted file mode 100644 index 40fbcf1be..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/CustomDefinitionEntryMapper.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry; - -public class CustomDefinitionEntryMapper implements IConfigurationMapper { - @Override - public CustomDefinitionEntry map(com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry input) { - return input == null ? null : new CustomDefinitionEntry().setCreationScript(input.getCreationScript()).setDropScript(input.getDropScript()) - .setPosition(input.getPosition()).setCustomPosition(input.getCustomPosition()).setValidationScripts(input.getValidationScripts()); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry unmap(CustomDefinitionEntry output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry().setCreationScript(output.getCreationScript()) - .setDropScript(output.getDropScript()).setPosition(output.getPosition()).setCustomPosition(output.getCustomPosition()) - .setValidationScripts(output.getValidationScripts()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/ForeignKeyConfigurationMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/ForeignKeyConfigurationMapper.java deleted file mode 100644 index bbbd690a6..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/ForeignKeyConfigurationMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration; - -public class ForeignKeyConfigurationMapper implements IConfigurationMapper { - @Override - public ForeignKeyConfiguration map(com.github.starnowski.posmulten.configuration.core.model.ForeignKeyConfiguration input) { - return input == null ? null : new ForeignKeyConfiguration() - .setConstraintName(input.getConstraintName()) - .setTableName(input.getTableName()) - .setTableSchema(input.getTableSchema()) - .setForeignKeyPrimaryKeyColumnsMappings(input.getForeignKeyPrimaryKeyColumnsMappings()); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.ForeignKeyConfiguration unmap(ForeignKeyConfiguration output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.ForeignKeyConfiguration() - .setConstraintName(output.getConstraintName()) - .setTableName(output.getTableName()) - .setTableSchema(output.getTableSchema()) - .setForeignKeyPrimaryKeyColumnsMappings(output.getForeignKeyPrimaryKeyColumnsMappings()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/PrimaryKeyDefinitionMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/PrimaryKeyDefinitionMapper.java deleted file mode 100644 index b9f90f2b4..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/PrimaryKeyDefinitionMapper.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition; - -public class PrimaryKeyDefinitionMapper implements IConfigurationMapper { - @Override - public PrimaryKeyDefinition map(com.github.starnowski.posmulten.configuration.core.model.PrimaryKeyDefinition input) { - return input == null ? null : new PrimaryKeyDefinition() - .setNameForFunctionThatChecksIfRecordExistsInTable(input.getNameForFunctionThatChecksIfRecordExistsInTable()) - .setPrimaryKeyColumnsNameToTypeMap(input.getPrimaryKeyColumnsNameToTypeMap()); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.PrimaryKeyDefinition unmap(PrimaryKeyDefinition output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.PrimaryKeyDefinition() - .setNameForFunctionThatChecksIfRecordExistsInTable(output.getNameForFunctionThatChecksIfRecordExistsInTable()) - .setPrimaryKeyColumnsNameToTypeMap(output.getPrimaryKeyColumnsNameToTypeMap()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/RLSPolicyMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/RLSPolicyMapper.java deleted file mode 100644 index dd87b0bdf..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/RLSPolicyMapper.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy; -import com.github.starnowski.posmulten.configuration.yaml.model.StringWrapperWithNotBlankValue; - -public class RLSPolicyMapper implements IConfigurationMapper { - - private final PrimaryKeyDefinitionMapper primaryKeyDefinitionMapper = new PrimaryKeyDefinitionMapper(); - - @Override - public RLSPolicy map(com.github.starnowski.posmulten.configuration.core.model.RLSPolicy input) { - return input == null ? null : new RLSPolicy() - .setName(input.getName()) - .setCreateTenantColumnForTable(input.getCreateTenantColumnForTable()) - .setPrimaryKeyDefinition(primaryKeyDefinitionMapper.map(input.getPrimaryKeyDefinition())) - .setSkipAddingOfTenantColumnDefaultValue(input.getSkipAddingOfTenantColumnDefaultValue()) - .setTenantColumn(input.getTenantColumn() == null ? null : new StringWrapperWithNotBlankValue(input.getTenantColumn())) - .setValidTenantValueConstraintName(input.getValidTenantValueConstraintName() == null ? null : new StringWrapperWithNotBlankValue(input.getValidTenantValueConstraintName())); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.RLSPolicy unmap(RLSPolicy output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.RLSPolicy() - .setName(output.getName()) - .setCreateTenantColumnForTable(output.getCreateTenantColumnForTable()) - .setPrimaryKeyDefinition(primaryKeyDefinitionMapper.unmap(output.getPrimaryKeyDefinition())) - .setSkipAddingOfTenantColumnDefaultValue(output.getSkipAddingOfTenantColumnDefaultValue()) - .setTenantColumn(output.getTenantColumn() == null ? null : output.getTenantColumn().getValue()) - .setValidTenantValueConstraintName(output.getValidTenantValueConstraintName() == null ? null : output.getValidTenantValueConstraintName().getValue()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/SharedSchemaContextConfigurationMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/SharedSchemaContextConfigurationMapper.java deleted file mode 100644 index aa866223c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/SharedSchemaContextConfigurationMapper.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration; - -import static com.github.starnowski.posmulten.configuration.yaml.model.StringWrapperWithNotBlankValue.valueOf; -import static java.util.stream.Collectors.toList; - -public class SharedSchemaContextConfigurationMapper implements IConfigurationMapper { - - private final TableEntryMapper tableEntryMapper = new TableEntryMapper(); - private final ValidTenantValueConstraintConfigurationMapper validTenantValueConstraintConfigurationMapper = new ValidTenantValueConstraintConfigurationMapper(); - private final SqlDefinitionsValidationMapper sqlDefinitionsValidationMapper = new SqlDefinitionsValidationMapper(); - private final CustomDefinitionEntryMapper customDefinitionEntryMapper = new CustomDefinitionEntryMapper(); - - @Override - public SharedSchemaContextConfiguration map(com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration input) { - return input == null ? null : new SharedSchemaContextConfiguration() - .setCreateForeignKeyConstraintWithTenantColumn(input.getCreateForeignKeyConstraintWithTenantColumn()) - .setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(input.getCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables()) - .setCurrentTenantIdProperty(input.getCurrentTenantIdProperty() == null ? null : valueOf(input.getCurrentTenantIdProperty())) - .setCurrentTenantIdPropertyType(input.getCurrentTenantIdPropertyType() == null ? null : valueOf(input.getCurrentTenantIdPropertyType())) - .setDefaultSchema(input.getDefaultSchema()) - .setDefaultTenantIdColumn(input.getDefaultTenantIdColumn() == null ? null : valueOf(input.getDefaultTenantIdColumn())) - .setEqualsCurrentTenantIdentifierFunctionName(input.getEqualsCurrentTenantIdentifierFunctionName() == null ? null : valueOf(input.getEqualsCurrentTenantIdentifierFunctionName())) - .setForceRowLevelSecurityForTableOwner(input.getForceRowLevelSecurityForTableOwner()) - .setGetCurrentTenantIdFunctionName(input.getGetCurrentTenantIdFunctionName() == null ? null : valueOf(input.getGetCurrentTenantIdFunctionName())) - .setGrantee(input.getGrantee()) - .setSetCurrentTenantIdFunctionName(input.getSetCurrentTenantIdFunctionName() == null ? null : valueOf(input.getSetCurrentTenantIdFunctionName())) - .setTenantHasAuthoritiesFunctionName(input.getTenantHasAuthoritiesFunctionName() == null ? null : valueOf(input.getTenantHasAuthoritiesFunctionName())) - .setTables(input.getTables() == null ? null : input.getTables().stream().map(tableEntry -> tableEntryMapper.map(tableEntry)).collect(toList())) - .setValidTenantValueConstraint(validTenantValueConstraintConfigurationMapper.map(input.getValidTenantValueConstraint())) - .setSqlDefinitionsValidation(sqlDefinitionsValidationMapper.map(input.getSqlDefinitionsValidation())) - .setCustomSQLDefinitions(input.getCustomDefinitions() == null ? null : input.getCustomDefinitions().stream().map(customDefinitionEntry -> customDefinitionEntryMapper.map(customDefinitionEntry)).collect(toList())); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration unmap(SharedSchemaContextConfiguration output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration() - .setCreateForeignKeyConstraintWithTenantColumn(output.getCreateForeignKeyConstraintWithTenantColumn()) - .setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(output.getCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables()) - .setCurrentTenantIdProperty(output.getCurrentTenantIdProperty() == null ? null : output.getCurrentTenantIdProperty().getValue()) - .setCurrentTenantIdPropertyType(output.getCurrentTenantIdPropertyType() == null ? null : output.getCurrentTenantIdPropertyType().getValue()) - .setDefaultSchema(output.getDefaultSchema()) - .setDefaultTenantIdColumn(output.getDefaultTenantIdColumn() == null ? null : output.getDefaultTenantIdColumn().getValue()) - .setEqualsCurrentTenantIdentifierFunctionName(output.getEqualsCurrentTenantIdentifierFunctionName() == null ? null : output.getEqualsCurrentTenantIdentifierFunctionName().getValue()) - .setForceRowLevelSecurityForTableOwner(output.getForceRowLevelSecurityForTableOwner()) - .setGetCurrentTenantIdFunctionName(output.getGetCurrentTenantIdFunctionName() == null ? null : output.getGetCurrentTenantIdFunctionName().getValue()) - .setGrantee(output.getGrantee()) - .setSetCurrentTenantIdFunctionName(output.getSetCurrentTenantIdFunctionName() == null ? null : output.getSetCurrentTenantIdFunctionName().getValue()) - .setTenantHasAuthoritiesFunctionName(output.getTenantHasAuthoritiesFunctionName() == null ? null : output.getTenantHasAuthoritiesFunctionName().getValue()) - .setTables(output.getTables() == null ? null : output.getTables().stream().map(tableEntry -> tableEntryMapper.unmap(tableEntry)).collect(toList())) - .setValidTenantValueConstraint(validTenantValueConstraintConfigurationMapper.unmap(output.getValidTenantValueConstraint())) - .setSqlDefinitionsValidation(sqlDefinitionsValidationMapper.unmap(output.getSqlDefinitionsValidation())) - .setCustomDefinitions(output.getCustomSQLDefinitions() == null ? null : output.getCustomSQLDefinitions().stream().map(customDefinitionEntry -> customDefinitionEntryMapper.unmap(customDefinitionEntry)).collect(toList())); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/SqlDefinitionsValidationMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/SqlDefinitionsValidationMapper.java deleted file mode 100644 index 7b93b7995..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/SqlDefinitionsValidationMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation; - -public class SqlDefinitionsValidationMapper implements IConfigurationMapper { - @Override - public SqlDefinitionsValidation map(com.github.starnowski.posmulten.configuration.core.model.SqlDefinitionsValidation input) { - return input == null ? null : new SqlDefinitionsValidation().setDisabled(input.getDisabled()).setIdentifierMaxLength(input.getIdentifierMaxLength()).setIdentifierMinLength(input.getIdentifierMinLength()); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.SqlDefinitionsValidation unmap(SqlDefinitionsValidation output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.SqlDefinitionsValidation().setDisabled(output.getDisabled()).setIdentifierMaxLength(output.getIdentifierMaxLength()).setIdentifierMinLength(output.getIdentifierMinLength()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/TableEntryMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/TableEntryMapper.java deleted file mode 100644 index 3491290bf..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/TableEntryMapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.TableEntry; - -import static java.util.stream.Collectors.toList; - -public class TableEntryMapper implements IConfigurationMapper { - - private final RLSPolicyMapper rlsPolicyMapper = new RLSPolicyMapper(); - private final ForeignKeyConfigurationMapper foreignKeyConfigurationMapper = new ForeignKeyConfigurationMapper(); - - @Override - public TableEntry map(com.github.starnowski.posmulten.configuration.core.model.TableEntry input) { - return input == null ? null : new TableEntry().setName(input.getName()) - .setSchema(input.getSchema()) - .setRlsPolicy(rlsPolicyMapper.map(input.getRlsPolicy())) - .setForeignKeys(input.getForeignKeys() == null ? null : input.getForeignKeys().stream().map(key -> foreignKeyConfigurationMapper.map(key)).collect(toList())); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.TableEntry unmap(TableEntry output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.TableEntry().setName(output.getName()).setRlsPolicy(rlsPolicyMapper.unmap(output.getRlsPolicy())) - .setSchema(output.getSchema()) - .setForeignKeys(output.getForeignKeys() == null ? null : output.getForeignKeys().stream().map(key -> foreignKeyConfigurationMapper.unmap(key)).collect(toList())); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/ValidTenantValueConstraintConfigurationMapper.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/ValidTenantValueConstraintConfigurationMapper.java deleted file mode 100644 index fcbdf7f35..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/mappers/ValidTenantValueConstraintConfigurationMapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.mappers; - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper; -import com.github.starnowski.posmulten.configuration.yaml.model.StringWrapperWithNotBlankValue; -import com.github.starnowski.posmulten.configuration.yaml.model.ValidTenantValueConstraintConfiguration; - -public class ValidTenantValueConstraintConfigurationMapper implements IConfigurationMapper { - @Override - public ValidTenantValueConstraintConfiguration map(com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration input) { - return input == null ? null : new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName(input.getIsTenantValidConstraintName() == null ? null : new StringWrapperWithNotBlankValue(input.getIsTenantValidConstraintName())) - .setIsTenantValidFunctionName(input.getIsTenantValidFunctionName() == null ? null : new StringWrapperWithNotBlankValue(input.getIsTenantValidFunctionName())) - .setTenantIdentifiersBlacklist(input.getTenantIdentifiersBlacklist()); - } - - @Override - public com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration unmap(ValidTenantValueConstraintConfiguration output) { - return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration() - .setIsTenantValidConstraintName(output.getIsTenantValidConstraintName() == null ? null : output.getIsTenantValidConstraintName().getValue()) - .setIsTenantValidFunctionName(output.getIsTenantValidFunctionName() == null ? null : output.getIsTenantValidFunctionName().getValue()) - .setTenantIdentifiersBlacklist(output.getTenantIdentifiersBlacklist()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/CustomDefinitionEntry.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/CustomDefinitionEntry.java deleted file mode 100644 index 9f92ab8ad..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/CustomDefinitionEntry.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.github.starnowski.posmulten.configuration.yaml.validation.CustomPositionValidValue; -import com.github.starnowski.posmulten.configuration.yaml.validation.EnumNamePattern; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - -import static java.util.stream.Collectors.toSet; - -@CustomPositionValidValue -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class CustomDefinitionEntry { - - private final static Set correctCustomPositionValues = Stream.of(com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.values()).map(Enum::name).collect(toSet());; - - @NotNull - @JsonProperty(value = "position", required = true) - @EnumNamePattern(enumType = com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.class) - private String position; - @NotBlank - @JsonProperty(value = "creation_script", required = true) - private String creationScript; - @JsonProperty(value = "drop_script") - private String dropScript; - @JsonProperty(value = "custom_position") - private String customPosition; - @NotEmpty - @JsonProperty(value = "validation_scripts", required = true) - private List validationScripts; - - public com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition getPosition() { - return isValidCustomDefinitionPosition(position) ? com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.valueOf(position) : null; - } - - public CustomDefinitionEntry setPosition(com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition position) { - this.position = position == null ? null : position.name(); - return this; - } - - public CustomDefinitionEntry setPosition(String position) { - this.position = position; - return this; - } - - private boolean isValidCustomDefinitionPosition(String value){ - return correctCustomPositionValues.contains(value); - } - -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/ForeignKeyConfiguration.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/ForeignKeyConfiguration.java deleted file mode 100644 index ec05bea8c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/ForeignKeyConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.util.Map; -import java.util.Optional; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class ForeignKeyConfiguration { - - @JsonProperty(value = "constraint_name", required = true) - @NotBlank - private String constraintName; - @NotBlank - @JsonProperty(value = "table_name", required = true) - private String tableName; - @JsonProperty(value = "table_schema") - private Optional tableSchema; - @JsonProperty(value = "foreign_key_primary_key_columns_mappings", required = true) - @NotNull - @Size(min = 1, message = "must have at least one element") - private Map<@NotBlank String, @NotBlank String> foreignKeyPrimaryKeyColumnsMappings; -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/PrimaryKeyDefinition.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/PrimaryKeyDefinition.java deleted file mode 100644 index bd0e102ba..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/PrimaryKeyDefinition.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotBlank; -import java.util.Map; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class PrimaryKeyDefinition { - - @JsonProperty(value = "pk_columns_name_to_type") - private Map<@NotBlank String, @NotBlank String> primaryKeyColumnsNameToTypeMap; - @NotBlank(groups = NameForFunctionThatChecksIfRecordExistsInTableNotBlank.class) - @JsonProperty(value = "name_for_function_that_checks_if_record_exists_in_table") - private String nameForFunctionThatChecksIfRecordExistsInTable; - - public interface NameForFunctionThatChecksIfRecordExistsInTableNotBlank {} -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/RLSPolicy.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/RLSPolicy.java deleted file mode 100644 index c67c45e9d..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/RLSPolicy.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class RLSPolicy { - @NotBlank - @JsonProperty(value = "name", required = true) - private String name; - @Valid - @JsonProperty(value = "tenant_column") - private StringWrapperWithNotBlankValue tenantColumn; - @JsonProperty(value = "create_tenant_column_for_table") - private Boolean createTenantColumnForTable; - @Valid - @JsonProperty(value = "valid_tenant_value_constraint_name") - private StringWrapperWithNotBlankValue validTenantValueConstraintName; - @JsonProperty(value = "skip_adding_of_tenant_column_default_value") - private Boolean skipAddingOfTenantColumnDefaultValue; - @Valid - @JsonProperty(value = "primary_key_definition") - private PrimaryKeyDefinition primaryKeyDefinition; - public RLSPolicy setTenantColumn(String tenantColumn) { - this.tenantColumn = new StringWrapperWithNotBlankValue(tenantColumn); - return this; - } - - public RLSPolicy setValidTenantValueConstraintName(String validTenantValueConstraintName) { - this.validTenantValueConstraintName = new StringWrapperWithNotBlankValue(validTenantValueConstraintName); - return this; - } - - public RLSPolicy setTenantColumn(StringWrapperWithNotBlankValue tenantColumn) { - this.tenantColumn = tenantColumn; - return this; - } - - public RLSPolicy setValidTenantValueConstraintName(StringWrapperWithNotBlankValue validTenantValueConstraintName) { - this.validTenantValueConstraintName = validTenantValueConstraintName; - return this; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/SharedSchemaContextConfiguration.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/SharedSchemaContextConfiguration.java deleted file mode 100644 index 35059a2ef..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/SharedSchemaContextConfiguration.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - *

- * Copyright (C) 2020 Szymon Tarnowski - *

- * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - *

- * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - *

- * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import java.util.List; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class SharedSchemaContextConfiguration { - - @NotBlank - @JsonProperty(value = "default_schema", required = true) - private String defaultSchema; - @Valid - @JsonProperty(value = "current_tenant_id_property_type") - private StringWrapperWithNotBlankValue currentTenantIdPropertyType; - @Valid - @JsonProperty(value = "current_tenant_id_property") - private StringWrapperWithNotBlankValue currentTenantIdProperty; - @Valid - @JsonProperty(value = "get_current_tenant_id_function_name") - private StringWrapperWithNotBlankValue getCurrentTenantIdFunctionName; - @Valid - @JsonProperty(value = "set_current_tenant_id_function_name") - private StringWrapperWithNotBlankValue setCurrentTenantIdFunctionName; - @Valid - @JsonProperty(value = "equals_current_tenant_identifier_function_name") - private StringWrapperWithNotBlankValue equalsCurrentTenantIdentifierFunctionName; - @Valid - @JsonProperty(value = "tenant_has_authorities_function_name") - private StringWrapperWithNotBlankValue tenantHasAuthoritiesFunctionName; - @JsonProperty(value = "force_row_level_security_for_table_owner") - private Boolean forceRowLevelSecurityForTableOwner; - @Valid - @JsonProperty(value = "default_tenant_id_column") - private StringWrapperWithNotBlankValue defaultTenantIdColumn; - @NotBlank - @JsonProperty(value = "grantee", required = true) - private String grantee; - @JsonProperty(value = "set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables") - private Boolean currentTenantIdentifierAsDefaultValueForTenantColumnInAllTables; - @Valid - @JsonProperty(value = "valid_tenant_value_constraint") - private ValidTenantValueConstraintConfiguration validTenantValueConstraint; - @JsonProperty(value = "tables") - private List<@Valid TableEntry> tables; - @Valid - @JsonProperty(value = "sql_definitions_validation") - private SqlDefinitionsValidation sqlDefinitionsValidation; - @Valid - @JsonProperty(value = "custom_sql_definitions") - private List customSQLDefinitions; - @JsonProperty(value = "create_foreignkey_constraint_with_tenant_column") - private Boolean createForeignKeyConstraintWithTenantColumn; - - public SharedSchemaContextConfiguration setCreateForeignKeyConstraintWithTenantColumn(Boolean createForeignKeyConstraintWithTenantColumn) { - this.createForeignKeyConstraintWithTenantColumn = createForeignKeyConstraintWithTenantColumn; - return this; - } - - public SharedSchemaContextConfiguration setCurrentTenantIdPropertyType(String currentTenantIdPropertyType) { - this.currentTenantIdPropertyType = new StringWrapperWithNotBlankValue(currentTenantIdPropertyType); - return this; - } - - public SharedSchemaContextConfiguration setCurrentTenantIdProperty(String currentTenantIdProperty) { - this.currentTenantIdProperty = new StringWrapperWithNotBlankValue(currentTenantIdProperty); - return this; - } - - public SharedSchemaContextConfiguration setGetCurrentTenantIdFunctionName(String getCurrentTenantIdFunctionName) { - this.getCurrentTenantIdFunctionName = new StringWrapperWithNotBlankValue(getCurrentTenantIdFunctionName); - return this; - } - - public SharedSchemaContextConfiguration setSetCurrentTenantIdFunctionName(String setCurrentTenantIdFunctionName) { - this.setCurrentTenantIdFunctionName = new StringWrapperWithNotBlankValue(setCurrentTenantIdFunctionName); - return this; - } - - public SharedSchemaContextConfiguration setEqualsCurrentTenantIdentifierFunctionName(String equalsCurrentTenantIdentifierFunctionName) { - this.equalsCurrentTenantIdentifierFunctionName = new StringWrapperWithNotBlankValue(equalsCurrentTenantIdentifierFunctionName); - return this; - } - - public SharedSchemaContextConfiguration setDefaultTenantIdColumn(String defaultTenantIdColumn) { - this.defaultTenantIdColumn = new StringWrapperWithNotBlankValue(defaultTenantIdColumn); - return this; - } - - public SharedSchemaContextConfiguration setCurrentTenantIdPropertyType(StringWrapperWithNotBlankValue currentTenantIdPropertyType) { - this.currentTenantIdPropertyType = currentTenantIdPropertyType; - return this; - } - - public SharedSchemaContextConfiguration setCurrentTenantIdProperty(StringWrapperWithNotBlankValue currentTenantIdProperty) { - this.currentTenantIdProperty = currentTenantIdProperty; - return this; - } - - public SharedSchemaContextConfiguration setGetCurrentTenantIdFunctionName(StringWrapperWithNotBlankValue getCurrentTenantIdFunctionName) { - this.getCurrentTenantIdFunctionName = getCurrentTenantIdFunctionName; - return this; - } - - public SharedSchemaContextConfiguration setSetCurrentTenantIdFunctionName(StringWrapperWithNotBlankValue setCurrentTenantIdFunctionName) { - this.setCurrentTenantIdFunctionName = setCurrentTenantIdFunctionName; - return this; - } - - public SharedSchemaContextConfiguration setEqualsCurrentTenantIdentifierFunctionName(StringWrapperWithNotBlankValue equalsCurrentTenantIdentifierFunctionName) { - this.equalsCurrentTenantIdentifierFunctionName = equalsCurrentTenantIdentifierFunctionName; - return this; - } - - public SharedSchemaContextConfiguration setTenantHasAuthoritiesFunctionName(StringWrapperWithNotBlankValue tenantHasAuthoritiesFunctionName) { - this.tenantHasAuthoritiesFunctionName = tenantHasAuthoritiesFunctionName; - return this; - } - - public SharedSchemaContextConfiguration setDefaultTenantIdColumn(StringWrapperWithNotBlankValue defaultTenantIdColumn) { - this.defaultTenantIdColumn = defaultTenantIdColumn; - return this; - } - - public SharedSchemaContextConfiguration withCustomSQLDefinitions(List customSQLDefinitions) { - this.customSQLDefinitions = customSQLDefinitions; - return this; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/SqlDefinitionsValidation.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/SqlDefinitionsValidation.java deleted file mode 100644 index e469bade9..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/SqlDefinitionsValidation.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.constraints.Min; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class SqlDefinitionsValidation { - - @Min(1) - @JsonProperty(value = "identifier_max_length") - private Integer identifierMaxLength; - @Min(1) - @JsonProperty(value = "identifier_min_length") - private Integer identifierMinLength; - @JsonProperty(value = "disabled") - private Boolean disabled; -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/StringWrapperWithNotBlankValue.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/StringWrapperWithNotBlankValue.java deleted file mode 100644 index 9dc9a5338..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/StringWrapperWithNotBlankValue.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotBlank; - -@EqualsAndHashCode -public final class StringWrapperWithNotBlankValue { - - @NotBlank - private final String value; - - @JsonCreator - public StringWrapperWithNotBlankValue(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } - - @Override - public String toString() { - return value; - } - - public static StringWrapperWithNotBlankValue valueOf(String value) - { - return new StringWrapperWithNotBlankValue(value); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/StringWrapperWithNullValue.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/StringWrapperWithNullValue.java deleted file mode 100644 index f223bf09c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/StringWrapperWithNullValue.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode -public final class StringWrapperWithNullValue { - - private final String value; - - @JsonCreator - public StringWrapperWithNullValue(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } - - @Override - public String toString() { - return value; - } - - public static StringWrapperWithNullValue valueOf(String value) - { - return new StringWrapperWithNullValue(value); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/TableEntry.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/TableEntry.java deleted file mode 100644 index cc0e63430..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/TableEntry.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import java.util.List; -import java.util.Optional; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class TableEntry { - - /** - * Table name - */ - @NotBlank - @JsonProperty(value = "name", required = true) - private String name; - @JsonProperty(value = "schema") - private Optional schema; - @Valid - @JsonProperty(value = "rls_policy") - private RLSPolicy rlsPolicy; - @JsonProperty(value = "foreign_keys") - private List<@Valid ForeignKeyConfiguration> foreignKeys; -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/ValidTenantValueConstraintConfiguration.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/ValidTenantValueConstraintConfiguration.java deleted file mode 100644 index 6d8826af4..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/model/ValidTenantValueConstraintConfiguration.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; - -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.util.List; - -@Accessors(chain = true) -@Getter -@Setter -@EqualsAndHashCode -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class ValidTenantValueConstraintConfiguration { - - @JsonProperty(value = "tenant_identifiers_blacklist", required = true) - @Size(min = 1, message = "must have at least one element") - @NotNull - private List tenantIdentifiersBlacklist; - @Valid - @JsonProperty(value = "is_tenant_valid_function_name") - private StringWrapperWithNotBlankValue isTenantValidFunctionName; - @Valid - @JsonProperty(value = "is_tenant_valid_constraint_name") - private StringWrapperWithNotBlankValue isTenantValidConstraintName; - public ValidTenantValueConstraintConfiguration setIsTenantValidFunctionName(String isTenantValidFunctionName) { - this.isTenantValidFunctionName = new StringWrapperWithNotBlankValue(isTenantValidFunctionName); - return this; - } - - public ValidTenantValueConstraintConfiguration setIsTenantValidConstraintName(String isTenantValidConstraintName) { - this.isTenantValidConstraintName = new StringWrapperWithNotBlankValue(isTenantValidConstraintName); - return this; - } - - public ValidTenantValueConstraintConfiguration setIsTenantValidFunctionName(StringWrapperWithNotBlankValue isTenantValidFunctionName) { - this.isTenantValidFunctionName = isTenantValidFunctionName; - return this; - } - - public ValidTenantValueConstraintConfiguration setIsTenantValidConstraintName(StringWrapperWithNotBlankValue isTenantValidConstraintName) { - this.isTenantValidConstraintName = isTenantValidConstraintName; - return this; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidValue.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidValue.java deleted file mode 100644 index 4c8fddfbb..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidValue.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.validation; - -import javax.validation.Constraint; -import javax.validation.Payload; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Constraint(validatedBy = CustomPositionValidator.class) -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface CustomPositionValidValue { - String message() default "{error.custom.definition.custom.position.value}"; - Class[] groups() default { }; - Class[] payload() default { }; -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidator.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidator.java deleted file mode 100644 index fb2cf204a..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidator.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.validation; - -import com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - -public class CustomPositionValidator implements ConstraintValidator { - @Override - public boolean isValid(CustomDefinitionEntry customDefinitionEntry, ConstraintValidatorContext constraintValidatorContext) { - if (customDefinitionEntry.getPosition() == null) { - return true; - } - boolean result = true; - switch (customDefinitionEntry.getPosition()) { - case AT_END: - case AT_BEGINNING: - result = true; - break; - case CUSTOM: - result = customDefinitionEntry.getCustomPosition() != null && !customDefinitionEntry.getCustomPosition().trim().isEmpty(); - } - return result; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePattern.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePattern.java deleted file mode 100644 index 6831c8a7c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePattern.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.validation; - -import javax.validation.Constraint; -import javax.validation.Payload; -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Implementation used code from article https://www.baeldung.com/javax-validations-enums - */ -@Target({FIELD}) -@Retention(RUNTIME) -@Documented -@Constraint(validatedBy = EnumNamePatternValidator.class) -public @interface EnumNamePattern { - - Class enumType(); - - String message() default "{error.enum.values}"; - - Class[] groups() default {}; - - Class[] payload() default {}; -} \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePatternValidator.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePatternValidator.java deleted file mode 100644 index a89934607..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePatternValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Posmulten library is an open-source project for the generation - * of SQL DDL statements that make it easy for implementation of - * Shared Schema Multi-tenancy strategy via the Row Security - * Policies in the Postgres database. - * - * Copyright (C) 2020 Szymon Tarnowski - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ -package com.github.starnowski.posmulten.configuration.yaml.validation; - -import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class EnumNamePatternValidator implements ConstraintValidator { - - private Class enumClass; - - @Override - public void initialize(EnumNamePattern constraintAnnotation) { - this.enumClass = constraintAnnotation.enumType(); - } - - @Override - public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { - if (value == null) { - return true; - } - if (Stream.of(this.enumClass.getEnumConstants()).map(e -> ((Enum) e).name()).noneMatch(name -> name.equals(value))) { - HibernateConstraintValidatorContext hibernateContext = constraintValidatorContext.unwrap( - HibernateConstraintValidatorContext.class ); - hibernateContext.addExpressionVariable("enumValues", Stream.of(this.enumClass.getEnumConstants()).map(e -> ((Enum) e).name()).collect(Collectors.joining(", "))); - return false; - } - return true; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver.java deleted file mode 100644 index 2341a6c3a..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation.groups; - -import com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition; -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration; - -public class NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver implements ValidatorGroupResolver { - - - @Override - public Class resolveForSharedSchemaContextConfiguration(SharedSchemaContextConfiguration sharedSchemaContextConfiguration, ValidatorGroupResolverContext context) { - return Boolean.TRUE.equals(sharedSchemaContextConfiguration.getCreateForeignKeyConstraintWithTenantColumn()) ? null : PrimaryKeyDefinition.NameForFunctionThatChecksIfRecordExistsInTableNotBlank.class; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupResolver.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupResolver.java deleted file mode 100644 index 3fa09ead2..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupResolver.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation.groups; - -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration; - -public interface ValidatorGroupResolver { - - Class resolveForSharedSchemaContextConfiguration(SharedSchemaContextConfiguration sharedSchemaContextConfiguration, ValidatorGroupResolverContext context); - - interface ValidatorGroupResolverContext { - - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupsResolver.java b/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupsResolver.java deleted file mode 100644 index cef73d0c5..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/java/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupsResolver.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation.groups; - -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration; - -import java.util.Collections; -import java.util.List; - -import static java.util.stream.Collectors.toList; - -public class ValidatorGroupsResolver { - - private final List validatorGroupResolvers; - - public ValidatorGroupsResolver() { - this(Collections.singletonList(new NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver())); - } - - public ValidatorGroupsResolver(List validatorGroupResolvers) { - this.validatorGroupResolvers = validatorGroupResolvers; - } - - List getValidatorGroupResolvers() { - return validatorGroupResolvers; - } - - public List resolveForSharedSchemaContextConfiguration(SharedSchemaContextConfiguration sharedSchemaContextConfiguration, ValidatorGroupResolver.ValidatorGroupResolverContext validatorGroupResolverContext) { - return validatorGroupResolvers.stream().map(resolver -> resolver.resolveForSharedSchemaContextConfiguration(sharedSchemaContextConfiguration, validatorGroupResolverContext)).collect(toList()); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/main/resources/ValidationMessages.properties b/configuration-parent/configuration-yaml-interpreter/src/main/resources/ValidationMessages.properties deleted file mode 100644 index f1270f685..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/main/resources/ValidationMessages.properties +++ /dev/null @@ -1,2 +0,0 @@ -error.custom.definition.custom.position.value=for definition with position 'CUSTOM' the property 'custom_position' is required -error.enum.values=available values are ${enumValues} \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/AbstractSpecification.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/AbstractSpecification.groovy deleted file mode 100644 index d22aff212..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/AbstractSpecification.groovy +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml - -import java.nio.file.Paths - -abstract class AbstractSpecification extends spock.lang.Specification { - - protected String resolveFilePath(String filePath) { - Paths.get(this.class.getResource(filePath).toURI()).toFile().getPath() - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplierTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplierTest.groovy deleted file mode 100644 index 7eabd8cf0..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplierTest.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.context - -import spock.lang.Specification - -import static java.util.Arrays.asList - -class YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplierTest extends Specification { - - def tested = new YamlConfigurationDefaultSharedSchemaContextBuilderFactorySupplier() - - def "should return priority with value zero"() - { - expect: - tested.getPriority() == 0 - } - - def "should return extensions related to YAML language"() - { - given: - def expectedExtensions = asList("yaml", "yml") - - when: - def results = tested.getSupportedFileExtensions() - - then: - results - results.size() == expectedExtensions.size() - results.containsAll(expectedExtensions) - } - - def "should return factory supplier"() - { - when: - def supplier = tested.getFactorySupplier() - - then: - supplier - - and: "supplier creates object of correct type" - YamlConfigurationDefaultSharedSchemaContextBuilderFactory.class.equals(supplier.get().getClass()) - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactoryTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactoryTest.groovy deleted file mode 100644 index 04722ac77..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/context/YamlConfigurationDefaultSharedSchemaContextBuilderFactoryTest.groovy +++ /dev/null @@ -1,130 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.context - -import com.github.starnowski.posmulten.configuration.yaml.AbstractSpecification -import com.github.starnowski.posmulten.configuration.yaml.exceptions.YamlInvalidSchema -import spock.lang.Unroll - -import java.nio.file.Files -import java.nio.file.Paths - -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.ALL_FIELDS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_LIST_NODES_BLANK_FIELDS_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_MAP_BLANK_FIELDS_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.ONLY_MANDATORY_FIELDS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.MANY_TO_MANY_TABLES_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.DISABLED_SQL_DEFINITIONS_VALIDATION_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.SQL_DEFINITIONS_VALIDATION_WITH_CUSTOM_CONSTRAINTS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.SQL_DEFINITIONS_VALIDATION_WITH_INVALID_CONSTRAINTS_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.SQL_DEFINITIONS_VALIDATION_WITH_NULL_VALUES_PATH - -class YamlConfigurationDefaultSharedSchemaContextBuilderFactoryTest extends AbstractSpecification { - - def tested = new YamlConfigurationDefaultSharedSchemaContextBuilderFactory() - - @Unroll - def "should create builder component based on file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def builder = tested.build(resolvedPath) - - then: - builder - - and: "builder should return a non-empty list of DDL statements" - !builder.build().getSqlDefinitions().isEmpty() - - where: - filePath << [ALL_FIELDS_FILE_PATH, ONLY_MANDATORY_FIELDS_FILE_PATH, MANY_TO_MANY_TABLES_FILE_PATH, DISABLED_SQL_DEFINITIONS_VALIDATION_FILE_PATH, SQL_DEFINITIONS_VALIDATION_WITH_CUSTOM_CONSTRAINTS_FILE_PATH, SQL_DEFINITIONS_VALIDATION_WITH_NULL_VALUES_PATH] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - tested.build(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - filePath || errorMessage - INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH || "grantee must not be blank" - INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH || "equals_current_tenant_identifier_function_name must not be blank" - INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH || "valid_tenant_value_constraint.is_tenant_valid_function_name must not be blank" - INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH || "valid_tenant_value_constraint.tenant_identifiers_blacklist must not be null" - INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH || "valid_tenant_value_constraint.tenant_identifiers_blacklist must have at least one element" - INVALID_LIST_NODES_BLANK_FIELDS_PATH || "tables[3].rls_policy.primary_key_definition.name_for_function_that_checks_if_record_exists_in_table must not be blank" - INVALID_LIST_NODES_BLANK_FIELDS_PATH || "tables[0].name must not be blank" - INVALID_MAP_BLANK_FIELDS_PATH || "tables[0].foreign_keys[0].foreign_key_primary_key_columns_mappings must have at least one element" - INVALID_MAP_BLANK_FIELDS_PATH || "tables[2].foreign_keys[2].foreign_key_primary_key_columns_mappings. must not be blank" - SQL_DEFINITIONS_VALIDATION_WITH_INVALID_CONSTRAINTS_PATH || "sql_definitions_validation.identifier_min_length must be greater than or equal to 1" - } - - @Unroll - def "should throw exception when there is no such file for configuration"() - { - when: - tested.build("no_such_file") - - then: - def ex = thrown(RuntimeException) - } - - @Unroll - def "should create builder component based on the content file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def builder = tested.buildForContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - builder - - and: "builder should return a non-empty list of DDL statements" - !builder.build().getSqlDefinitions().isEmpty() - - where: - filePath << [ALL_FIELDS_FILE_PATH, ONLY_MANDATORY_FIELDS_FILE_PATH, MANY_TO_MANY_TABLES_FILE_PATH, DISABLED_SQL_DEFINITIONS_VALIDATION_FILE_PATH, SQL_DEFINITIONS_VALIDATION_WITH_CUSTOM_CONSTRAINTS_FILE_PATH, SQL_DEFINITIONS_VALIDATION_WITH_NULL_VALUES_PATH] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - tested.buildForContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - filePath || errorMessage - INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH || "grantee must not be blank" - INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH || "equals_current_tenant_identifier_function_name must not be blank" - INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH || "valid_tenant_value_constraint.is_tenant_valid_function_name must not be blank" - INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH || "valid_tenant_value_constraint.tenant_identifiers_blacklist must not be null" - INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH || "valid_tenant_value_constraint.tenant_identifiers_blacklist must have at least one element" - INVALID_LIST_NODES_BLANK_FIELDS_PATH || "tables[3].rls_policy.primary_key_definition.name_for_function_that_checks_if_record_exists_in_table must not be blank" - INVALID_LIST_NODES_BLANK_FIELDS_PATH || "tables[0].name must not be blank" - INVALID_MAP_BLANK_FIELDS_PATH || "tables[0].foreign_keys[0].foreign_key_primary_key_columns_mappings must have at least one element" - INVALID_MAP_BLANK_FIELDS_PATH || "tables[2].foreign_keys[2].foreign_key_primary_key_columns_mappings. must not be blank" - SQL_DEFINITIONS_VALIDATION_WITH_INVALID_CONSTRAINTS_PATH || "sql_definitions_validation.identifier_min_length must be greater than or equal to 1" - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDaoTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDaoTest.groovy deleted file mode 100644 index e499ec918..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDaoTest.groovy +++ /dev/null @@ -1,410 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.dao - -import com.github.starnowski.posmulten.configuration.yaml.AbstractSpecification -import com.github.starnowski.posmulten.configuration.yaml.IntegerRandomizer -import com.github.starnowski.posmulten.configuration.yaml.OptionalRandomizer -import com.github.starnowski.posmulten.configuration.yaml.exceptions.YamlInvalidSchema -import com.github.starnowski.posmulten.configuration.yaml.model.* -import org.jeasy.random.EasyRandom -import org.jeasy.random.EasyRandomParameters -import org.jeasy.random.FieldPredicates -import org.jeasy.random.randomizers.misc.EnumRandomizer -import org.jeasy.random.randomizers.text.StringDelegatingRandomizer -import org.junit.Rule -import org.junit.rules.TemporaryFolder -import spock.lang.Unroll - -import java.nio.file.Files -import java.nio.file.Paths - -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.* -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder -import static java.util.Arrays.asList -import static java.util.stream.Collectors.toList - -class SharedSchemaContextConfigurationYamlDaoTest extends AbstractSpecification { - - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder() - - def tested = new SharedSchemaContextConfigurationYamlDao() - - @Unroll - def "should return non null object based on file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.read(resolvedPath) - - then: - result - - where: - filePath << [ALL_FIELDS_FILE_PATH, ONLY_MANDATORY_FIELDS_FILE_PATH, INTEGRATION_TESTS_FILE_PATH, ONLY_MANDATORY_FIELDS_WITH_TEMPLATE_VALUES_FILE_PATH, ALL_FIELDS_WITH_FOREIGN_KEY_CONSTRAINT_FILE_PATH] - } - - @Unroll - def "should return non null object based on content of file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - result - - where: - filePath << [ALL_FIELDS_FILE_PATH, ONLY_MANDATORY_FIELDS_FILE_PATH, INTEGRATION_TESTS_FILE_PATH, ONLY_MANDATORY_FIELDS_WITH_TEMPLATE_VALUES_FILE_PATH] - } - - @Unroll - def "should return object based on file which was created by other test file #filePath"() - { - given: - def resolvedPath = resolveFilePath(filePath) - def testObject = tested.read(resolvedPath) - def tmpFile = tempFolder.newFile("temp-config.yaml") - tested.save(testObject, tmpFile.getAbsoluteFile().getAbsolutePath()) - - when: - def result = tested.read(tmpFile.getAbsoluteFile().getAbsolutePath()) - - then: - result - - and: "tests object should be equal" - result == testObject - - where: - filePath << [ALL_FIELDS_FILE_PATH, ONLY_MANDATORY_FIELDS_FILE_PATH] - } - - @Unroll - def "should not save file when trying to save invalid object based on schema"() - { - given: - def resolvedPath = resolveFilePath(filePath) - def testObject = tested.read(resolvedPath) - def tmpFile = tempFolder.newFile("temp-config.yaml") - testObject.setGrantee(null) - - when: - tested.save(testObject, tmpFile.getAbsoluteFile().getAbsolutePath()) - - then: - def ex = thrown(YamlInvalidSchema) - - where: - filePath << [ALL_FIELDS_FILE_PATH, ONLY_MANDATORY_FIELDS_FILE_PATH] - } - - @Unroll - def "for file '#filePath' should return object with expected fields : defaultSchema (#defaultSchema), currentTenantIdPropertyType (#currentTenantIdPropertyType), currentTenantIdProperty (#currentTenantIdProperty), getCurrentTenantIdFunctionName (#getCurrentTenantIdFunctionName), setCurrentTenantIdFunctionName (#setCurrentTenantIdFunctionName)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.read(resolvedPath) - - then: - result.getDefaultSchema() == defaultSchema - result.getCurrentTenantIdProperty() == currentTenantIdProperty - result.getCurrentTenantIdPropertyType() == currentTenantIdPropertyType - result.getGetCurrentTenantIdFunctionName() == getCurrentTenantIdFunctionName - result.getSetCurrentTenantIdFunctionName() == setCurrentTenantIdFunctionName - - where: - filePath | defaultSchema | currentTenantIdProperty | currentTenantIdPropertyType | getCurrentTenantIdFunctionName | setCurrentTenantIdFunctionName - ALL_FIELDS_FILE_PATH | "public" | stringWrapper("pos.c.ten") | stringWrapper("VARCHAR(255)") | stringWrapper("get_ten_id") | stringWrapper("set_tenant") - ONLY_MANDATORY_FIELDS_FILE_PATH | "non_public" | null | null | null | null - } - - @Unroll - def "for the content of file '#filePath' should return object with expected fields : defaultSchema (#defaultSchema), currentTenantIdPropertyType (#currentTenantIdPropertyType), currentTenantIdProperty (#currentTenantIdProperty), getCurrentTenantIdFunctionName (#getCurrentTenantIdFunctionName), setCurrentTenantIdFunctionName (#setCurrentTenantIdFunctionName)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - result.getDefaultSchema() == defaultSchema - result.getCurrentTenantIdProperty() == currentTenantIdProperty - result.getCurrentTenantIdPropertyType() == currentTenantIdPropertyType - result.getGetCurrentTenantIdFunctionName() == getCurrentTenantIdFunctionName - result.getSetCurrentTenantIdFunctionName() == setCurrentTenantIdFunctionName - - where: - filePath | defaultSchema | currentTenantIdProperty | currentTenantIdPropertyType | getCurrentTenantIdFunctionName | setCurrentTenantIdFunctionName - ALL_FIELDS_FILE_PATH | "public" | stringWrapper("pos.c.ten") | stringWrapper("VARCHAR(255)") | stringWrapper("get_ten_id") | stringWrapper("set_tenant") - ONLY_MANDATORY_FIELDS_FILE_PATH | "non_public" | null | null | null | null - } - - @Unroll - def "for file '#filePath' should return object with expected fields : defaultSchema (#defaultSchema), grantee (#grantee)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.read(resolvedPath) - - then: - result.getDefaultSchema() == defaultSchema - result.getGrantee() == grantee - - where: - filePath | defaultSchema | grantee - ONLY_MANDATORY_FIELDS_WITH_TEMPLATE_VALUES_FILE_PATH | "{{db_schema}}" | "{{db_grantee}}" - CONFIGURATION_WITH_TEMPLATE_VALUES_FILE_PATH | "{{db_schema}}" | "{{db_rls_grantee}}" - } - - @Unroll - def "for the content of file '#filePath' should return object with expected fields : defaultSchema (#defaultSchema), grantee (#grantee)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - result.getDefaultSchema() == defaultSchema - result.getGrantee() == grantee - - where: - filePath | defaultSchema | grantee - ONLY_MANDATORY_FIELDS_WITH_TEMPLATE_VALUES_FILE_PATH | "{{db_schema}}" | "{{db_grantee}}" - CONFIGURATION_WITH_TEMPLATE_VALUES_FILE_PATH | "{{db_schema}}" | "{{db_rls_grantee}}" - } - - @Unroll - def "for file '#filePath' should return object with expected fields : equalsCurrentTenantIdentifierFunctionName (#equalsCurrentTenantIdentifierFunctionName), tenantHasAuthoritiesFunctionName (#tenantHasAuthoritiesFunctionName), forceRowLevelSecurityForTableOwner (#forceRowLevelSecurityForTableOwner), defaultTenantIdColumn (#defaultTenantIdColumn), grantee (#grantee), setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables (#setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.read(resolvedPath) - - then: - result.getEqualsCurrentTenantIdentifierFunctionName() == equalsCurrentTenantIdentifierFunctionName - result.getTenantHasAuthoritiesFunctionName() == tenantHasAuthoritiesFunctionName - result.getForceRowLevelSecurityForTableOwner() == forceRowLevelSecurityForTableOwner - result.getDefaultTenantIdColumn() == defaultTenantIdColumn - result.getGrantee() == grantee - result.getCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables() == setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables - - where: - filePath | equalsCurrentTenantIdentifierFunctionName | tenantHasAuthoritiesFunctionName | forceRowLevelSecurityForTableOwner | defaultTenantIdColumn | grantee | setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables - ALL_FIELDS_FILE_PATH | stringWrapper("equals_cur_tenant") | stringWrapper("_tenant_hast_auth") | true | stringWrapper("tenant_id") | "application-user" | true - ONLY_MANDATORY_FIELDS_FILE_PATH | null | null | null | null | "db-user" | null - } - - @Unroll - def "for the content of file '#filePath' should return object with expected fields : equalsCurrentTenantIdentifierFunctionName (#equalsCurrentTenantIdentifierFunctionName), tenantHasAuthoritiesFunctionName (#tenantHasAuthoritiesFunctionName), forceRowLevelSecurityForTableOwner (#forceRowLevelSecurityForTableOwner), defaultTenantIdColumn (#defaultTenantIdColumn), grantee (#grantee), setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables (#setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - result.getEqualsCurrentTenantIdentifierFunctionName() == equalsCurrentTenantIdentifierFunctionName - result.getTenantHasAuthoritiesFunctionName() == tenantHasAuthoritiesFunctionName - result.getForceRowLevelSecurityForTableOwner() == forceRowLevelSecurityForTableOwner - result.getDefaultTenantIdColumn() == defaultTenantIdColumn - result.getGrantee() == grantee - result.getCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables() == setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables - - where: - filePath | equalsCurrentTenantIdentifierFunctionName | tenantHasAuthoritiesFunctionName | forceRowLevelSecurityForTableOwner | defaultTenantIdColumn | grantee | setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables - ALL_FIELDS_FILE_PATH | stringWrapper("equals_cur_tenant") | stringWrapper("_tenant_hast_auth") | true | stringWrapper("tenant_id") | "application-user" | true - ONLY_MANDATORY_FIELDS_FILE_PATH | null | null | null | null | "db-user" | null - } - - @Unroll - def "for file '#filePath' should return object with expected fields related to valid tenant value constraint #properties"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.read(resolvedPath) - - then: - result.getValidTenantValueConstraint() == properties - - where: - filePath | properties - ONLY_MANDATORY_FIELDS_FILE_PATH | null - ALL_FIELDS_FILE_PATH | new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("is_tenant_valid_constraint_SDFA").setIsTenantValidFunctionName("is_t_valid").setTenantIdentifiersBlacklist(asList("invalid_tenant", "Some strange tenant ID", "'; DROP ALL TABLES")) - } - - @Unroll - def "for the content of file '#filePath' should return object with expected fields related to valid tenant value constraint #properties"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def result = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - result.getValidTenantValueConstraint() == properties - - where: - filePath | properties - ONLY_MANDATORY_FIELDS_FILE_PATH | null - ALL_FIELDS_FILE_PATH | new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("is_tenant_valid_constraint_SDFA").setIsTenantValidFunctionName("is_t_valid").setTenantIdentifiersBlacklist(asList("invalid_tenant", "Some strange tenant ID", "'; DROP ALL TABLES")) - } - - @Unroll - def "for file '#filePath' should return object that contains expected table configuration #tableEntry (without comparing foreign keys entries)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def results = tested.read(resolvedPath).getTables().stream().map({table -> table.setForeignKeys(null) }).collect(toList()) - - then: - results.contains(tableEntry) - - where: - filePath | tableEntry - ALL_FIELDS_FILE_PATH | new TableEntry().setName("users").setRlsPolicy(new RLSPolicy().setName("users_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_user_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("posts").setRlsPolicy(new RLSPolicy().setName("posts_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_post_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build())).setSkipAddingOfTenantColumnDefaultValue(false)) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("comments").setRlsPolicy(new RLSPolicy().setName("comments_table_rls_policy").setTenantColumn("tenant").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_comment_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").put("user_id", "bigint").build())).setSkipAddingOfTenantColumnDefaultValue(true)) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("notifications").setRlsPolicy(new RLSPolicy().setName("notifications_table_rls_policy").setTenantColumn("tenant").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_notification_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("uuid", "uuid").build())).setCreateTenantColumnForTable(true).setValidTenantValueConstraintName("is_tenant_id_valid")) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("dictionary").setSchema(Optional.of("no_other_schema")).setRlsPolicy(new RLSPolicy().setName("dictionary_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_dictionary_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("dictionary_1").setSchema(Optional.ofNullable(null)).setRlsPolicy(new RLSPolicy().setName("dictionary_1_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_dictionary_1_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("dictionary_2").setSchema(Optional.ofNullable(null)).setRlsPolicy(new RLSPolicy().setName("dictionary_2_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_dictionary_2_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - } - - @Unroll - def "for content of file '#filePath' should return object that contains expected table configuration #tableEntry (without comparing foreign keys entries)"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def results = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))).getTables().stream().map({table -> table.setForeignKeys(null) }).collect(toList()) - - then: - results.contains(tableEntry) - - where: - filePath | tableEntry - ALL_FIELDS_FILE_PATH | new TableEntry().setName("users").setRlsPolicy(new RLSPolicy().setName("users_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_user_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("posts").setRlsPolicy(new RLSPolicy().setName("posts_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_post_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build())).setSkipAddingOfTenantColumnDefaultValue(false)) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("comments").setRlsPolicy(new RLSPolicy().setName("comments_table_rls_policy").setTenantColumn("tenant").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_comment_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").put("user_id", "bigint").build())).setSkipAddingOfTenantColumnDefaultValue(true)) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("notifications").setRlsPolicy(new RLSPolicy().setName("notifications_table_rls_policy").setTenantColumn("tenant").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_notification_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("uuid", "uuid").build())).setCreateTenantColumnForTable(true).setValidTenantValueConstraintName("is_tenant_id_valid")) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("dictionary").setSchema(Optional.of("no_other_schema")).setRlsPolicy(new RLSPolicy().setName("dictionary_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_dictionary_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("dictionary_1").setSchema(Optional.ofNullable(null)).setRlsPolicy(new RLSPolicy().setName("dictionary_1_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_dictionary_1_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - ALL_FIELDS_FILE_PATH | new TableEntry().setName("dictionary_2").setSchema(Optional.ofNullable(null)).setRlsPolicy(new RLSPolicy().setName("dictionary_2_table_rls_policy").setTenantColumn("tenant_id").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_dictionary_2_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").build()))) - } - - @Unroll - def "for file '#filePath' should return object that contains expected foreign key configuration #foreignKey for table #table"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def results = tested.read(resolvedPath).getTables().stream().filter({t -> (table == t.getName()) }).flatMap({t -> t.getForeignKeys().stream()}).collect(toList()) - - then: - results.contains(foreignKey) - - where: - filePath | table | foreignKey - ALL_FIELDS_FILE_PATH | "posts" | new ForeignKeyConfiguration().setTableName("users").setConstraintName("posts_users_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()) - ALL_FIELDS_FILE_PATH | "comments" | new ForeignKeyConfiguration().setTableName("users").setConstraintName("comments_users_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()) - ALL_FIELDS_FILE_PATH | "comments" | new ForeignKeyConfiguration().setTableName("posts").setConstraintName("comments_posts_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("post_id", "id").build()) - ALL_FIELDS_FILE_PATH | "comments" | new ForeignKeyConfiguration().setTableName("comments").setConstraintName("comments_comment_parent_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("parent_comment_id", "id").put("parent_comment_user_id", "user_id").build()) - ALL_FIELDS_FILE_PATH | "notifications" | new ForeignKeyConfiguration().setTableName("users").setConstraintName("notifications_users_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()) - ALL_FIELDS_FILE_PATH | "notifications_1" | new ForeignKeyConfiguration().setTableName("dictionary").setTableSchema(Optional.of("no_other_schema")).setConstraintName("notifications_1_dictionary_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("dictionary_id", "id").build()) - } - - @Unroll - def "for the content of file '#filePath' should return object that contains expected foreign key configuration #foreignKey for table #table"() - { - given: - def resolvedPath = resolveFilePath(filePath) - - when: - def results = tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))).getTables().stream().filter({t -> (table == t.getName()) }).flatMap({t -> t.getForeignKeys().stream()}).collect(toList()) - - then: - results.contains(foreignKey) - - where: - filePath | table | foreignKey - ALL_FIELDS_FILE_PATH | "posts" | new ForeignKeyConfiguration().setTableName("users").setConstraintName("posts_users_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()) - ALL_FIELDS_FILE_PATH | "comments" | new ForeignKeyConfiguration().setTableName("users").setConstraintName("comments_users_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()) - ALL_FIELDS_FILE_PATH | "comments" | new ForeignKeyConfiguration().setTableName("posts").setConstraintName("comments_posts_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("post_id", "id").build()) - ALL_FIELDS_FILE_PATH | "comments" | new ForeignKeyConfiguration().setTableName("comments").setConstraintName("comments_comment_parent_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("parent_comment_id", "id").put("parent_comment_user_id", "user_id").build()) - ALL_FIELDS_FILE_PATH | "notifications" | new ForeignKeyConfiguration().setTableName("users").setConstraintName("notifications_users_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()) - ALL_FIELDS_FILE_PATH | "notifications_1" | new ForeignKeyConfiguration().setTableName("dictionary").setTableSchema(Optional.of("no_other_schema")).setConstraintName("notifications_1_dictionary_tenant_constraint").setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("dictionary_id", "id").build()) - } - - @Unroll - def "should return object based on file which was created based on test object #testObject"() - { - given: - def tmpFile = tempFolder.newFile("spec-temp-config.yaml") - tested.save(testObject, tmpFile.getAbsoluteFile().getAbsolutePath()) - - when: - def result = tested.read(tmpFile.getAbsoluteFile().getAbsolutePath()) - - then: - result - - and: "tests objects should be equal" - result == testObject - - where: - testObject << [ new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("shema1").setTables(asList(new TableEntry().setName("tab1"))).setGrantee("db-user"), - new SharedSchemaContextConfiguration().setDefaultSchema("public").setTables(asList(new TableEntry().setName("users"))).setGrantee("ps-user") - ] - } - - def "should return object based on file which was created based on random generated object"() - { - given: - EasyRandomParameters parameters = new EasyRandomParameters() - .randomize(FieldPredicates.named("identifierMaxLength").and(FieldPredicates.ofType(Integer.class)).and(FieldPredicates.inClass(SqlDefinitionsValidation.class)), new IntegerRandomizer(1, 255)) - .randomize(FieldPredicates.named("identifierMinLength").and(FieldPredicates.ofType(Integer.class)).and(FieldPredicates.inClass(SqlDefinitionsValidation.class)), new IntegerRandomizer(1, 255)) - .randomize(FieldPredicates.named("schema").and(FieldPredicates.ofType(Optional.class)).and(FieldPredicates.inClass(TableEntry.class)), new OptionalRandomizer(StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new IntegerRandomizer(1, 255)), true)) - .randomize(FieldPredicates.named("tableSchema").and(FieldPredicates.ofType(Optional.class)).and(FieldPredicates.inClass(ForeignKeyConfiguration.class)), new OptionalRandomizer(StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new IntegerRandomizer(1, 255)), true)) - .randomize(FieldPredicates.named("position").and(FieldPredicates.ofType(String.class)).and(FieldPredicates.inClass(CustomDefinitionEntry.class)), StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new EnumRandomizer(com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition))) - EasyRandom easyRandom = new EasyRandom(parameters) - def randomObject = easyRandom.nextObject(SharedSchemaContextConfiguration) - def tmpFile = tempFolder.newFile("rand-temp-config.yaml") - tested.save(randomObject, tmpFile.getAbsoluteFile().getAbsolutePath()) - - when: - def result = tested.read(tmpFile.getAbsoluteFile().getAbsolutePath()) - - then: - result - - and: "tests objects should be equal" - result == randomObject - } - - private StringWrapperWithNotBlankValue stringWrapper(String value) - { - new StringWrapperWithNotBlankValue(value) - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDaoValidationTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDaoValidationTest.groovy deleted file mode 100644 index 9ef268adb..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/dao/SharedSchemaContextConfigurationYamlDaoValidationTest.groovy +++ /dev/null @@ -1,260 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.dao - -import com.github.starnowski.posmulten.configuration.yaml.AbstractSpecification -import com.github.starnowski.posmulten.configuration.yaml.exceptions.YamlInvalidSchema -import spock.lang.Unroll - -import java.nio.file.Files -import java.nio.file.Paths - -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_LIST_NODES_BLANK_FIELDS_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_MAP_BLANK_FIELDS_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH -import static com.github.starnowski.posmulten.configuration.yaml.TestProperties.INVALID_CUSTOM_DEFINITIONS_FIELDS_PATH - -class SharedSchemaContextConfigurationYamlDaoValidationTest extends AbstractSpecification { - - def tested = new SharedSchemaContextConfigurationYamlDao() - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file invalid-root-node-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH) - - when: - tested.read(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["grantee must not be blank", "default_schema must not be blank", "get_current_tenant_id_function_name must not be blank", "set_current_tenant_id_function_name must not be blank", "equals_current_tenant_identifier_function_name must not be blank"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file invalid-nested-node-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH) - - when: - tested.read(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["valid_tenant_value_constraint.is_tenant_valid_function_name must not be blank", "valid_tenant_value_constraint.is_tenant_valid_constraint_name must not be blank", "valid_tenant_value_constraint.tenant_identifiers_blacklist must not be null"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file invalid-nested-node-empty-list.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH) - - when: - tested.read(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["valid_tenant_value_constraint.tenant_identifiers_blacklist must have at least one element"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file invalid-list-nodes-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_LIST_NODES_BLANK_FIELDS_PATH) - - when: - tested.read(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["tables[3].rls_policy.primary_key_definition.name_for_function_that_checks_if_record_exists_in_table must not be blank", "tables[2].rls_policy.name must not be blank", "tables[0].name must not be blank"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file invalid-map-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_MAP_BLANK_FIELDS_PATH) - - when: - tested.read(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["tables[0].foreign_keys[0].foreign_key_primary_key_columns_mappings must have at least one element", - "tables[1].foreign_keys[0].foreign_key_primary_key_columns_mappings.user_id must not be blank", - "tables[2].foreign_keys[1].constraint_name must not be blank", - "tables[3].foreign_keys[0].foreign_key_primary_key_columns_mappings.user_identi must not be blank", - "tables[2].foreign_keys[0].foreign_key_primary_key_columns_mappings must not be null", - "tables[2].foreign_keys[2].foreign_key_primary_key_columns_mappings.parent_comment_id must not be blank", - "tables[2].foreign_keys[2].foreign_key_primary_key_columns_mappings. must not be blank", - "tables[1].foreign_keys[0].constraint_name must not be blank" - ] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for file invalid-custom-definitions.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_CUSTOM_DEFINITIONS_FIELDS_PATH) - - when: - tested.read(resolvedPath) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["custom_sql_definitions[1].position must not be null", - "custom_sql_definitions[3].position available values are AT_END, AT_BEGINNING, CUSTOM", - "custom_sql_definitions[0].position must not be null", - "custom_sql_definitions[2] for definition with position 'CUSTOM' the property 'custom_position' is required" - ] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content of file invalid-root-node-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH) - - when: - tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["grantee must not be blank", "default_schema must not be blank", "get_current_tenant_id_function_name must not be blank", "set_current_tenant_id_function_name must not be blank", "equals_current_tenant_identifier_function_name must not be blank"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content of file invalid-nested-node-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH) - - when: - tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["valid_tenant_value_constraint.is_tenant_valid_function_name must not be blank", "valid_tenant_value_constraint.is_tenant_valid_constraint_name must not be blank", "valid_tenant_value_constraint.tenant_identifiers_blacklist must not be null"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content of file invalid-nested-node-empty-list.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH) - - when: - tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["valid_tenant_value_constraint.tenant_identifiers_blacklist must have at least one element"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content of file invalid-list-nodes-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_LIST_NODES_BLANK_FIELDS_PATH) - - when: - tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["tables[3].rls_policy.primary_key_definition.name_for_function_that_checks_if_record_exists_in_table must not be blank", "tables[2].rls_policy.name must not be blank", "tables[0].name must not be blank"] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content of file invalid-map-blank-fields.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_MAP_BLANK_FIELDS_PATH) - - when: - tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["tables[0].foreign_keys[0].foreign_key_primary_key_columns_mappings must have at least one element", - "tables[1].foreign_keys[0].foreign_key_primary_key_columns_mappings.user_id must not be blank", - "tables[2].foreign_keys[1].constraint_name must not be blank", - "tables[3].foreign_keys[0].foreign_key_primary_key_columns_mappings.user_identi must not be blank", - "tables[2].foreign_keys[0].foreign_key_primary_key_columns_mappings must not be null", - "tables[2].foreign_keys[2].foreign_key_primary_key_columns_mappings.parent_comment_id must not be blank", - "tables[2].foreign_keys[2].foreign_key_primary_key_columns_mappings. must not be blank", - "tables[1].foreign_keys[0].constraint_name must not be blank" - ] - } - - @Unroll - def "should throw exception that contains error message (#errorMessage) for the content of file invalid-custom-definitions.yaml"() - { - given: - def resolvedPath = resolveFilePath(INVALID_CUSTOM_DEFINITIONS_FIELDS_PATH) - - when: - tested.readFromContent(new String(Files.readAllBytes(Paths.get(resolvedPath)))) - - then: - def ex = thrown(YamlInvalidSchema) - ex - ex.getErrorMessages().contains(errorMessage) - - where: - errorMessage << ["custom_sql_definitions[1].position must not be null", - "custom_sql_definitions[3].position available values are AT_END, AT_BEGINNING, CUSTOM", - "custom_sql_definitions[0].position must not be null", - "custom_sql_definitions[2] for definition with position 'CUSTOM' the property 'custom_position' is required" - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/AbstractConfigurationMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/AbstractConfigurationMapperTest.groovy deleted file mode 100644 index 1e52e2ae5..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/AbstractConfigurationMapperTest.groovy +++ /dev/null @@ -1,113 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.yaml.IConfigurationMapper -import com.github.starnowski.posmulten.configuration.yaml.IntegerRandomizer -import com.github.starnowski.posmulten.configuration.yaml.OptionalRandomizer -import com.github.starnowski.posmulten.configuration.yaml.model.TableEntry -import com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration -import org.jeasy.random.EasyRandom -import org.jeasy.random.EasyRandomParameters -import org.jeasy.random.FieldPredicates -import org.jeasy.random.randomizers.text.StringDelegatingRandomizer -import spock.lang.Specification - -import static java.util.stream.Collectors.toList - -abstract class AbstractConfigurationMapperTest> extends Specification { - - def "should unmap yaml objects to expected configuration objects"() { - given: - T tested = getTestedObject() - List yamlObjects = prepareExpectedMappedObjectsList() - List expectedObjects = prepareExpectedUnmappeddObjectsList() - - when: - def actualObjects = yamlObjects.stream().map({ yamlObject -> tested.unmap(yamlObject) }).collect(toList()) - - then: - actualObjects == expectedObjects - } - - def "should map yaml objects to expected configuration objects"() { - given: - T tested = getTestedObject() - List expectedYamlObjects = prepareExpectedMappedObjectsList() - List configurationObjects = prepareExpectedUnmappeddObjectsList() - - when: - def actualObjects = configurationObjects.stream().map({ configurationObject -> tested.map(configurationObject) }).collect(toList()) - - then: - actualObjects == expectedYamlObjects - } - - def "should unmap random generated yaml configuration object"() - { - given: - T tested = getTestedObject() - EasyRandomParameters parameters = new EasyRandomParameters() - .randomize(FieldPredicates.named("schema").and(FieldPredicates.ofType(Optional.class)).and(FieldPredicates.inClass(TableEntry.class)), new OptionalRandomizer(StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new IntegerRandomizer(1, 255)), true)) - .randomize(FieldPredicates.named("tableSchema").and(FieldPredicates.ofType(Optional.class)).and(FieldPredicates.inClass(ForeignKeyConfiguration.class)), new OptionalRandomizer(StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new IntegerRandomizer(1, 255)), true)) - EasyRandom easyRandom = new EasyRandom(parameters) - O yamlConfiguration = easyRandom.nextObject(getYamlConfigurationObjectClass()) - - when: - def configuration = tested.unmap(yamlConfiguration) - - then: - configuration - - and: "unmapped object should be able to map to an equal object" - yamlConfiguration == tested.map(configuration) - } - - def "should map random generated configuration object"() - { - given: - T tested = getTestedObject() - EasyRandomParameters parameters = new EasyRandomParameters() - .randomize(FieldPredicates.named("schema").and(FieldPredicates.ofType(Optional.class)).and(FieldPredicates.inClass(com.github.starnowski.posmulten.configuration.core.model.TableEntry.class)), new OptionalRandomizer(StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new IntegerRandomizer(1, 255)), true)) - .randomize(FieldPredicates.named("tableSchema").and(FieldPredicates.ofType(Optional.class)).and(FieldPredicates.inClass(com.github.starnowski.posmulten.configuration.core.model.ForeignKeyConfiguration.class)), new OptionalRandomizer(StringDelegatingRandomizer.aNewStringDelegatingRandomizer(new IntegerRandomizer(1, 255)), true)) - EasyRandom easyRandom = new EasyRandom(parameters) - I configuration = easyRandom.nextObject(getConfigurationObjectClass()) - - when: - def yamlConfiguration = tested.map(configuration) - - then: - yamlConfiguration - - and: "mapped object should be able to unmap to an equal object" - configuration == tested.unmap(yamlConfiguration) - } - - def "should map null object where parameter is null"() - { - given: - T tested = getTestedObject() - - expect: - null == tested.map(null) - - } - - def "should unmap null object where parameter is null"() - { - given: - T tested = getTestedObject() - - expect: - null == tested.unmap(null) - - } - - abstract protected Class getConfigurationObjectClass() - - abstract protected Class getYamlConfigurationObjectClass() - - abstract protected T getTestedObject() - - abstract protected List prepareExpectedMappedObjectsList() - - abstract protected List prepareExpectedUnmappeddObjectsList() -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/CustomDefinitionEntryMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/CustomDefinitionEntryMapperTest.groovy deleted file mode 100644 index 631dfe601..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/CustomDefinitionEntryMapperTest.groovy +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry - -import static com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.AT_BEGINNING -import static com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.CUSTOM - -class CustomDefinitionEntryMapperTest extends AbstractConfigurationMapperTest { - @Override - protected Class getConfigurationObjectClass() { - CustomDefinitionEntry.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry.class - } - - @Override - protected CustomDefinitionEntryMapper getTestedObject() { - new CustomDefinitionEntryMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [new com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry(), - new com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry().setCreationScript("C1"), - new com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry().setCreationScript("DDS").setDropScript("Script"), - new com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry().setCreationScript("DDS").setDropScript("Script").setValidationScripts(["select", "drop"]), - new com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry().setPosition(AT_BEGINNING), - new com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry().setPosition(CUSTOM).setCustomPosition("0") - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [new CustomDefinitionEntry(), - new CustomDefinitionEntry().setCreationScript("C1"), - new CustomDefinitionEntry().setCreationScript("DDS").setDropScript("Script"), - new CustomDefinitionEntry().setCreationScript("DDS").setDropScript("Script").setValidationScripts(["select", "drop"]), - new CustomDefinitionEntry().setPosition(AT_BEGINNING), - new CustomDefinitionEntry().setPosition(CUSTOM).setCustomPosition("0") - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/ForeignKeyConfigurationMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/ForeignKeyConfigurationMapperTest.groovy deleted file mode 100644 index 983afe8f8..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/ForeignKeyConfigurationMapperTest.groovy +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.ForeignKeyConfiguration - -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder - -class ForeignKeyConfigurationMapperTest extends AbstractConfigurationMapperTest { - - @Override - protected Class getConfigurationObjectClass() { - ForeignKeyConfiguration.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration.class - } - - @Override - protected ForeignKeyConfigurationMapper getTestedObject() { - new ForeignKeyConfigurationMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration(), - new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration(), - new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration().setConstraintName("asfxzvz") - .setTableName("ccc"), - new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration().setConstraintName("fk_constraint") - .setTableName("some_table") - .setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()), - new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration().setConstraintName("users_fk") - .setTableName("users_po_table") - .setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("sss", "uuid").put("some_id", "primary_key_col_id").build()) - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [ - new ForeignKeyConfiguration(), - new ForeignKeyConfiguration().setConstraintName(null) - .setTableName(null), - new ForeignKeyConfiguration().setConstraintName("asfxzvz") - .setTableName("ccc"), - new ForeignKeyConfiguration().setConstraintName("fk_constraint") - .setTableName("some_table") - .setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("user_id", "id").build()), - new ForeignKeyConfiguration().setConstraintName("users_fk") - .setTableName("users_po_table") - .setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("sss", "uuid").put("some_id", "primary_key_col_id").build()) - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/PrimaryKeyDefinitionMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/PrimaryKeyDefinitionMapperTest.groovy deleted file mode 100644 index 694dd83ed..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/PrimaryKeyDefinitionMapperTest.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.PrimaryKeyDefinition - -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder - -class PrimaryKeyDefinitionMapperTest extends AbstractConfigurationMapperTest { - @Override - protected Class getConfigurationObjectClass() { - PrimaryKeyDefinition.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition.class - } - - @Override - protected PrimaryKeyDefinitionMapper getTestedObject() { - new PrimaryKeyDefinitionMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition(), - new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_for_table_exists"), - new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").build()), - new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").put("some_uuid", "UUID").build()) - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [ - new PrimaryKeyDefinition(), - new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_for_table_exists"), - new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").build()), - new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_exists").setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").put("some_uuid", "UUID").build()) - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/RLSPolicyMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/RLSPolicyMapperTest.groovy deleted file mode 100644 index 0db0070e0..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/RLSPolicyMapperTest.groovy +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.PrimaryKeyDefinition -import com.github.starnowski.posmulten.configuration.core.model.RLSPolicy - -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder - -class RLSPolicyMapperTest extends AbstractConfigurationMapperTest { - - @Override - protected Class getConfigurationObjectClass() { - RLSPolicy.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy.class - } - - @Override - protected RLSPolicyMapper getTestedObject() { - new RLSPolicyMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy(), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setName("_some_policy"), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setName("rls_1").setSkipAddingOfTenantColumnDefaultValue(true), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setName("policy_2").setSkipAddingOfTenantColumnDefaultValue(false), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setValidTenantValueConstraintName("constr_1").setCreateTenantColumnForTable(true), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setValidTenantValueConstraintName("wrong_tenant_const").setPrimaryKeyDefinition(new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("record_is_valid")), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setTenantColumn("ten_col").setName("posts").setPrimaryKeyDefinition(new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").build())), - new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setName("posts").setPrimaryKeyDefinition(new com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").put("some_uuid", "UUID").build())) - - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [ - new RLSPolicy(), - new RLSPolicy().setName("_some_policy"), - new RLSPolicy().setName("rls_1").setSkipAddingOfTenantColumnDefaultValue(true), - new RLSPolicy().setName("policy_2").setSkipAddingOfTenantColumnDefaultValue(false), - new RLSPolicy().setValidTenantValueConstraintName("constr_1").setCreateTenantColumnForTable(true), - new RLSPolicy().setValidTenantValueConstraintName("wrong_tenant_const").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("record_is_valid")), - new RLSPolicy().setTenantColumn("ten_col").setName("posts").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").build())), - new RLSPolicy().setName("posts").setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "int").put("some_uuid", "UUID").build())) - - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/SharedSchemaContextConfigurationMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/SharedSchemaContextConfigurationMapperTest.groovy deleted file mode 100644 index 219255e13..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/SharedSchemaContextConfigurationMapperTest.groovy +++ /dev/null @@ -1,62 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration -import com.github.starnowski.posmulten.configuration.core.model.TableEntry -import com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration - -import static java.util.Arrays.asList - -class SharedSchemaContextConfigurationMapperTest extends AbstractConfigurationMapperTest { - @Override - protected Class getConfigurationObjectClass() { - SharedSchemaContextConfiguration.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration.class - } - - @Override - protected SharedSchemaContextConfigurationMapper getTestedObject() { - new SharedSchemaContextConfigurationMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration(), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setSetCurrentTenantIdFunctionName("set_current_f_t_id_fun_na"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setSetCurrentTenantIdFunctionName("ggxx").setGrantee("db-user"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setGrantee("db-user").setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(true), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(false).setCurrentTenantIdProperty("ccte.property"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setCurrentTenantIdProperty("posmulten.property").setDefaultTenantIdColumn("tenant_col_id"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setDefaultTenantIdColumn("tenant").setCurrentTenantIdPropertyType("VARCHAR(127)"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("VARCHAR(127)").setEqualsCurrentTenantIdentifierFunctionName("equals_cur_t"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setEqualsCurrentTenantIdentifierFunctionName("equals_cur_t").setGetCurrentTenantIdFunctionName("get_tenant"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setGetCurrentTenantIdFunctionName("get_tenant").setSetCurrentTenantIdFunctionName("this_is_a_tenant"), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setSetCurrentTenantIdFunctionName("set_cur_tenant").setForceRowLevelSecurityForTableOwner(true), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setForceRowLevelSecurityForTableOwner(false).setValidTenantValueConstraint(new com.github.starnowski.posmulten.configuration.yaml.model.ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(asList("Invalid"))), - new com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration().setTables(asList(new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry().setName("table_1"))), - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [ - new SharedSchemaContextConfiguration(), - new SharedSchemaContextConfiguration().setSetCurrentTenantIdFunctionName("set_current_f_t_id_fun_na"), - new SharedSchemaContextConfiguration().setSetCurrentTenantIdFunctionName("ggxx").setGrantee("db-user"), - new SharedSchemaContextConfiguration().setGrantee("db-user").setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(true), - new SharedSchemaContextConfiguration().setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(false).setCurrentTenantIdProperty("ccte.property"), - new SharedSchemaContextConfiguration().setCurrentTenantIdProperty("posmulten.property").setDefaultTenantIdColumn("tenant_col_id"), - new SharedSchemaContextConfiguration().setDefaultTenantIdColumn("tenant").setCurrentTenantIdPropertyType("VARCHAR(127)"), - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("VARCHAR(127)").setEqualsCurrentTenantIdentifierFunctionName("equals_cur_t"), - new SharedSchemaContextConfiguration().setEqualsCurrentTenantIdentifierFunctionName("equals_cur_t").setGetCurrentTenantIdFunctionName("get_tenant"), - new SharedSchemaContextConfiguration().setGetCurrentTenantIdFunctionName("get_tenant").setSetCurrentTenantIdFunctionName("this_is_a_tenant"), - new SharedSchemaContextConfiguration().setSetCurrentTenantIdFunctionName("set_cur_tenant").setForceRowLevelSecurityForTableOwner(true), - new SharedSchemaContextConfiguration().setForceRowLevelSecurityForTableOwner(false).setValidTenantValueConstraint(new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(asList("Invalid"))), - new SharedSchemaContextConfiguration().setTables(asList(new TableEntry().setName("table_1"))), - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/SqlDefinitionsValidationMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/SqlDefinitionsValidationMapperTest.groovy deleted file mode 100644 index 5aa9a7594..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/SqlDefinitionsValidationMapperTest.groovy +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.SqlDefinitionsValidation - -class SqlDefinitionsValidationMapperTest extends AbstractConfigurationMapperTest { - @Override - protected Class getConfigurationObjectClass() { - SqlDefinitionsValidation.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation.class - } - - @Override - protected SqlDefinitionsValidationMapper getTestedObject() { - new SqlDefinitionsValidationMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation(), - new com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation().setDisabled(true), - new com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation().setDisabled(false), - new com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation().setIdentifierMaxLength(1), - new com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation().setIdentifierMinLength(5), - new com.github.starnowski.posmulten.configuration.yaml.model.SqlDefinitionsValidation().setIdentifierMinLength(3).setIdentifierMaxLength(11) - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [ - new SqlDefinitionsValidation(), - new SqlDefinitionsValidation().setDisabled(true), - new SqlDefinitionsValidation().setDisabled(false), - new SqlDefinitionsValidation().setIdentifierMaxLength(1), - new SqlDefinitionsValidation().setIdentifierMinLength(5), - new SqlDefinitionsValidation().setIdentifierMinLength(3).setIdentifierMaxLength(11) - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/TableEntryMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/TableEntryMapperTest.groovy deleted file mode 100644 index a3b79a685..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/TableEntryMapperTest.groovy +++ /dev/null @@ -1,50 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.core.model.TableEntry -import com.github.starnowski.posmulten.configuration.core.model.ForeignKeyConfiguration -import com.github.starnowski.posmulten.configuration.core.model.RLSPolicy - -import static java.util.Arrays.asList - -class TableEntryMapperTest extends AbstractConfigurationMapperTest { - @Override - protected Class getConfigurationObjectClass() { - TableEntry.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.yaml.model.TableEntry.class - } - - @Override - protected TableEntryMapper getTestedObject() { - new TableEntryMapper() - } - - @Override - protected List prepareExpectedMappedObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry(), - new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry().setName("table_1"), - new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry().setName("users_t").setRlsPolicy(new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy()), - new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry().setName("users_t").setForeignKeys(new ArrayList()), - new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry().setName("users_t").setForeignKeys(asList(new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration().setTableName("tabXXX"))), - new com.github.starnowski.posmulten.configuration.yaml.model.TableEntry().setName("posts").setRlsPolicy(new com.github.starnowski.posmulten.configuration.yaml.model.RLSPolicy().setName("rls_users_policy")) - .setForeignKeys(asList(new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration().setTableName("tabXXX"), new com.github.starnowski.posmulten.configuration.yaml.model.ForeignKeyConfiguration().setTableName("comments"))), - ] - } - - @Override - protected List prepareExpectedUnmappeddObjectsList() { - [ - new TableEntry(), - new TableEntry().setName("table_1"), - new TableEntry().setName("users_t").setRlsPolicy(new RLSPolicy()), - new TableEntry().setName("users_t").setForeignKeys(new ArrayList()), - new TableEntry().setName("users_t").setForeignKeys(asList(new ForeignKeyConfiguration().setTableName("tabXXX"))), - new TableEntry().setName("posts").setRlsPolicy(new RLSPolicy().setName("rls_users_policy")) - .setForeignKeys(asList(new ForeignKeyConfiguration().setTableName("tabXXX"), new ForeignKeyConfiguration().setTableName("comments"))), - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/ValidTenantValueConstraintConfigurationMapperTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/ValidTenantValueConstraintConfigurationMapperTest.groovy deleted file mode 100644 index 2a991ce5e..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/mappers/ValidTenantValueConstraintConfigurationMapperTest.groovy +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.mappers - -import com.github.starnowski.posmulten.configuration.yaml.model.ValidTenantValueConstraintConfiguration - -import static java.util.Arrays.asList - -class ValidTenantValueConstraintConfigurationMapperTest extends AbstractConfigurationMapperTest { - - @Override - protected Class getConfigurationObjectClass() { - com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration.class - } - - @Override - protected Class getYamlConfigurationObjectClass() { - ValidTenantValueConstraintConfiguration.class - } - - @Override - protected ValidTenantValueConstraintConfigurationMapper getTestedObject() { - new ValidTenantValueConstraintConfigurationMapper() - } - - protected List prepareExpectedMappedObjectsList() { - [ - new ValidTenantValueConstraintConfiguration(), - new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("tenant_x_id"), - new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_t_v_constraint"), - new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_t_v_constraint") - .setIsTenantValidFunctionName("function_name_is_tenant_valid") - .setTenantIdentifiersBlacklist(asList("XXX", "invalid_tenant")) - ] - } - - protected List prepareExpectedUnmappeddObjectsList() { - [ - new com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration(), - new com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("tenant_x_id"), - new com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_t_v_constraint"), - new com.github.starnowski.posmulten.configuration.core.model.ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_t_v_constraint") - .setIsTenantValidFunctionName("function_name_is_tenant_valid") - .setTenantIdentifiersBlacklist(asList("XXX", "invalid_tenant")) - ] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/ForeignKeyConfigurationTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/ForeignKeyConfigurationTest.groovy deleted file mode 100644 index 3ff5cbaae..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/ForeignKeyConfigurationTest.groovy +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.model - -import spock.lang.Specification -import spock.lang.Unroll - -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder - -class ForeignKeyConfigurationTest extends Specification { - - @Unroll - def "equals method should return true for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() { - expect: - ob1.equals(ob2) && ob2.equals(ob1) - - where: - ob1 | ob2 - new ForeignKeyConfiguration() | new ForeignKeyConfiguration() - new ForeignKeyConfiguration().setConstraintName("constraint_x") | new ForeignKeyConfiguration().setConstraintName("constraint_x") - new ForeignKeyConfiguration().setTableName("tab_1") | new ForeignKeyConfiguration().setTableName("tab_1") - new ForeignKeyConfiguration().setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("id", "tab_id").put("tab_uuid", "uuid").build()) | new ForeignKeyConfiguration().setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("id", "tab_id").put("tab_uuid", "uuid").build()) - } - - @Unroll - def "hashCode method should return same result for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() { - expect: - ob1.hashCode() == ob2.hashCode() - - where: - ob1 | ob2 - new ForeignKeyConfiguration() | new ForeignKeyConfiguration() - new ForeignKeyConfiguration().setConstraintName("constraint_x") | new ForeignKeyConfiguration().setConstraintName("constraint_x") - new ForeignKeyConfiguration().setTableName("tab_1") | new ForeignKeyConfiguration().setTableName("tab_1") - new ForeignKeyConfiguration().setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("id", "tab_id").put("tab_uuid", "uuid").build()) | new ForeignKeyConfiguration().setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("id", "tab_id").put("tab_uuid", "uuid").build()) - } - - @Unroll - def "equals method should return false for objects with different values [ob1 (#ob1), ob2 (#ob2)]"() { - expect: - !ob1.equals(ob2) && !ob2.equals(ob1) - - where: - ob1 | ob2 - new ForeignKeyConfiguration().setConstraintName("constraint_x") | new ForeignKeyConfiguration().setConstraintName("constraint_y") - new ForeignKeyConfiguration().setTableName("tab_1") | new ForeignKeyConfiguration().setTableName("tab_2") - new ForeignKeyConfiguration().setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("id", "tab_id").put("tab_uuid", "uuid").build()) | new ForeignKeyConfiguration().setForeignKeyPrimaryKeyColumnsMappings(mapBuilder().put("id", "tab_id").put("tab_xuid", "uuid").build()) - - } -} \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/PrimaryKeyDefinitionTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/PrimaryKeyDefinitionTest.groovy deleted file mode 100644 index cba6ef313..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/PrimaryKeyDefinitionTest.groovy +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.model - -import spock.lang.Specification -import spock.lang.Unroll - -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder - -class PrimaryKeyDefinitionTest extends Specification { - - @Unroll - def "equals method should return true for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.equals(ob2) && ob2.equals(ob1) - - where: - ob1 | ob2 - new PrimaryKeyDefinition() | new PrimaryKeyDefinition() - new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists") | new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists") - new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build()) | new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build()) - - } - - @Unroll - def "hashCode method should return same result for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.hashCode() == ob2.hashCode() - - where: - ob1 | ob2 - new PrimaryKeyDefinition() | new PrimaryKeyDefinition() - new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists") | new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists") - new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build()) | new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build()) - } - - @Unroll - def "equals method should return false for objects with different values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - !ob1.equals(ob2) && !ob2.equals(ob1) - - where: - ob1 | ob2 - new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists") | new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_exists") - new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "VARCHAR(255)").put("record_uuid", "UUID").build()) | new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build()) - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/RLSPolicyTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/RLSPolicyTest.groovy deleted file mode 100644 index 2a58587e8..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/RLSPolicyTest.groovy +++ /dev/null @@ -1,63 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.model - -import spock.lang.Specification -import spock.lang.Unroll - -import static com.github.starnowski.posmulten.postgresql.test.utils.MapBuilder.mapBuilder - -class RLSPolicyTest extends Specification { - - @Unroll - def "equals method should return true for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.equals(ob2) && ob2.equals(ob1) - - where: - ob1 | ob2 - new RLSPolicy() | new RLSPolicy() - new RLSPolicy().setName("table_rls_policy") | new RLSPolicy().setName("table_rls_policy") - new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(true) | new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(true) - new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(false) | new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(false) - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("t_valid") | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("t_valid") - new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(true) | new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(true) - new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(false) | new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(false) - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build())) | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build())) - - } - - @Unroll - def "hashCode method should return same result for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.hashCode() == ob2.hashCode() - - where: - ob1 | ob2 - new RLSPolicy() | new RLSPolicy() - new RLSPolicy().setName("table_rls_policy") | new RLSPolicy().setName("table_rls_policy") - new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(true) | new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(true) - new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(false) | new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(false) - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("t_valid") | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("t_valid") - new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(true) | new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(true) - new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(false) | new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(false) - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build())) | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build())) - } - - @Unroll - def "equals method should return false for objects with different values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - !ob1.equals(ob2) && !ob2.equals(ob1) - - where: - ob1 | ob2 - new RLSPolicy().setName("table_rls_policy") | new RLSPolicy().setName("tab_rls_policy") - new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(true) | new RLSPolicy().setTenantColumn("yyy_tenant").setCreateTenantColumnForTable(true) - new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(false) | new RLSPolicy().setTenantColumn("xxx_tenant").setCreateTenantColumnForTable(true) - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("t_valid") | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_exists")).setValidTenantValueConstraintName("t_valid") - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("t_valid") | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setNameForFunctionThatChecksIfRecordExistsInTable("is_record_exists")).setValidTenantValueConstraintName("tvalid") - new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(true) | new RLSPolicy().setSkipAddingOfTenantColumnDefaultValue(false) - new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "VARCHAR(255)").put("record_uuid", "UUID").build())) | new RLSPolicy().setPrimaryKeyDefinition(new PrimaryKeyDefinition().setPrimaryKeyColumnsNameToTypeMap(mapBuilder().put("id", "bigint").put("record_uuid", "UUID").build())) - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/SharedSchemaContextConfigurationTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/SharedSchemaContextConfigurationTest.groovy deleted file mode 100644 index c7934c756..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/SharedSchemaContextConfigurationTest.groovy +++ /dev/null @@ -1,55 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.model - -import spock.lang.Specification -import spock.lang.Unroll - -import static java.util.Arrays.asList - -class SharedSchemaContextConfigurationTest extends Specification { - - @Unroll - def "equals method should return true for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.equals(ob2) && ob2.equals(ob1) - - where: - ob1 | ob2 - new SharedSchemaContextConfiguration() | new SharedSchemaContextConfiguration() - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("shema1") | new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("shema1") - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx") | new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx") - new SharedSchemaContextConfiguration().setDefaultSchema("shema1") | new SharedSchemaContextConfiguration().setDefaultSchema("shema1") - new SharedSchemaContextConfiguration().setDefaultSchema("public") | new SharedSchemaContextConfiguration().setDefaultSchema("public") - new SharedSchemaContextConfiguration().setTables(asList(new TableEntry().setName("tab1"))) | new SharedSchemaContextConfiguration().setTables(asList(new TableEntry().setName("tab1"))) - } - - @Unroll - def "hashCode method should return same result for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.hashCode() == ob2.hashCode() - - where: - ob1 | ob2 - new SharedSchemaContextConfiguration() | new SharedSchemaContextConfiguration() - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("shema1") | new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("shema1") - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx") | new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx") - new SharedSchemaContextConfiguration().setDefaultSchema("shema1") | new SharedSchemaContextConfiguration().setDefaultSchema("shema1") - new SharedSchemaContextConfiguration().setDefaultSchema("public") | new SharedSchemaContextConfiguration().setDefaultSchema("public") - new SharedSchemaContextConfiguration().setTables(asList(new TableEntry().setName("tab1"))) | new SharedSchemaContextConfiguration().setTables(asList(new TableEntry().setName("tab1"))) - } - - @Unroll - def "equals method should return false for objects with different values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - !ob1.equals(ob2) && !ob2.equals(ob1) - - where: - ob1 | ob2 - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("shema1") | new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx").setDefaultSchema("public") - new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("xxx") | new SharedSchemaContextConfiguration().setCurrentTenantIdPropertyType("yyy") - new SharedSchemaContextConfiguration().setDefaultSchema("shema1") | new SharedSchemaContextConfiguration().setDefaultSchema("public") - new SharedSchemaContextConfiguration().setDefaultSchema("public") | new SharedSchemaContextConfiguration().setDefaultSchema("non_public") - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/TableEntryTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/TableEntryTest.groovy deleted file mode 100644 index 64498bd0d..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/TableEntryTest.groovy +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.model - -import spock.lang.Specification -import spock.lang.Unroll - -class TableEntryTest extends Specification { - - @Unroll - def "equals method should return true for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.equals(ob2) && ob2.equals(ob1) - - where: - ob1 | ob2 - new TableEntry() | new TableEntry() - new TableEntry().setName("table1") | new TableEntry().setName("table1") - new TableEntry().setRlsPolicy(new RLSPolicy().setName("rls_test_policy")) | new TableEntry().setRlsPolicy(new RLSPolicy().setName("rls_test_policy")) - new TableEntry().setForeignKeys(Arrays.asList(new ForeignKeyConfiguration().setTableName("tab2"))) | new TableEntry().setForeignKeys(Arrays.asList(new ForeignKeyConfiguration().setTableName("tab2"))) - } - - @Unroll - def "hashCode method should return same result for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.hashCode() == ob2.hashCode() - - where: - ob1 | ob2 - new TableEntry() | new TableEntry() - new TableEntry().setName("table1") | new TableEntry().setName("table1") - new TableEntry().setRlsPolicy(new RLSPolicy().setName("rls_test_policy")) | new TableEntry().setRlsPolicy(new RLSPolicy().setName("rls_test_policy")) - new TableEntry().setForeignKeys(Arrays.asList(new ForeignKeyConfiguration().setTableName("tab2"))) | new TableEntry().setForeignKeys(Arrays.asList(new ForeignKeyConfiguration().setTableName("tab2"))) - } - - @Unroll - def "equals method should return false for objects with different values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - !ob1.equals(ob2) && !ob2.equals(ob1) - - where: - ob1 | ob2 - new TableEntry().setName("tableN") | new TableEntry().setName("table1") - new TableEntry().setRlsPolicy(new RLSPolicy().setName("rls_test_policy")) | new TableEntry().setRlsPolicy(new RLSPolicy().setName("rls_tab_policy")) - new TableEntry().setForeignKeys(Arrays.asList(new ForeignKeyConfiguration().setTableName("tab2"))) | new TableEntry().setForeignKeys(Arrays.asList(new ForeignKeyConfiguration().setTableName("tabX"))) - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/ValidTenantValueConstraintConfigurationTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/ValidTenantValueConstraintConfigurationTest.groovy deleted file mode 100644 index baedacdca..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/model/ValidTenantValueConstraintConfigurationTest.groovy +++ /dev/null @@ -1,45 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.model - -import spock.lang.Specification -import spock.lang.Unroll - -class ValidTenantValueConstraintConfigurationTest extends Specification { - - @Unroll - def "equals method should return true for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.equals(ob2) && ob2.equals(ob1) - - where: - ob1 | ob2 - new ValidTenantValueConstraintConfiguration() | new ValidTenantValueConstraintConfiguration() - new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_f_v") | new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_f_v") - new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(Arrays.asList("invalid_t", "UUID-SOME-13")) | new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(Arrays.asList("invalid_t", "UUID-SOME-13")) - } - - @Unroll - def "hashCode method should return same result for objects with same values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - ob1.hashCode() == ob2.hashCode() - - where: - ob1 | ob2 - new ValidTenantValueConstraintConfiguration() | new ValidTenantValueConstraintConfiguration() - new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_f_v") | new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_f_v") - new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(Arrays.asList("invalid_t", "UUID-SOME-13")) | new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(Arrays.asList("invalid_t", "UUID-SOME-13")) - } - - @Unroll - def "equals method should return false for objects with different values [ob1 (#ob1), ob2 (#ob2)]"() - { - expect: - !ob1.equals(ob2) && !ob2.equals(ob1) - - where: - ob1 | ob2 - new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_f_v") | new ValidTenantValueConstraintConfiguration().setIsTenantValidConstraintName("i_xxx") - new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(Arrays.asList("invalid_t", "UUID-SOME-13")) | new ValidTenantValueConstraintConfiguration().setTenantIdentifiersBlacklist(Arrays.asList("invalid_t", "UXID-SOME-13")) - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidatorTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidatorTest.groovy deleted file mode 100644 index 0b6eacc12..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/CustomPositionValidatorTest.groovy +++ /dev/null @@ -1,72 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation - -import com.github.starnowski.posmulten.configuration.yaml.model.CustomDefinitionEntry -import spock.lang.Specification -import spock.lang.Unroll - -import static com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.AT_BEGINNING -import static com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.AT_END -import static com.github.starnowski.posmulten.configuration.core.model.CustomDefinitionEntry.CustomDefinitionPosition.CUSTOM - -class CustomPositionValidatorTest extends Specification { - - def "should return true when a position is null because the other validator is responsible for checking this"(){ - given: - def tested = new CustomPositionValidator() - def entry = new CustomDefinitionEntry() - - when: - def result = tested.isValid(entry, null) - - then: - result - } - - @Unroll - def "should return true when position is different than CUSTOM, #position"(){ - given: - def tested = new CustomPositionValidator() - def entry = new CustomDefinitionEntry().setPosition(position) - - when: - def result = tested.isValid(entry, null) - - then: - result - - where: - position << [AT_BEGINNING, AT_END] - } - - @Unroll - def "should return true when position is CUSTOM and custom position is not empty '#position'"(){ - given: - def tested = new CustomPositionValidator() - def entry = new CustomDefinitionEntry().setPosition(CUSTOM).setCustomPosition(position) - - when: - def result = tested.isValid(entry, null) - - then: - result - - where: - position << ["some value", "0", "137"] - } - - @Unroll - def "should return false when position is CUSTOM and custom position is invalid : '#position'"(){ - given: - def tested = new CustomPositionValidator() - def entry = new CustomDefinitionEntry().setPosition(CUSTOM).setCustomPosition(position) - - when: - def result = tested.isValid(entry, null) - - then: - !result - - where: - position << [null, "", " "] - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePatternValidatorTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePatternValidatorTest.groovy deleted file mode 100644 index 4bd5d9094..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/EnumNamePatternValidatorTest.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation - -import spock.lang.Specification - -class EnumNamePatternValidatorTest extends Specification { - - def "should return true when value is null"(){ - given: - def tested = new EnumNamePatternValidator() - - when: - def result = tested.isValid(null, null) - - then: - result - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/groups/NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolverTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/groups/NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolverTest.groovy deleted file mode 100644 index cd68448f7..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/groups/NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolverTest.groovy +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation.groups - -import com.github.starnowski.posmulten.configuration.yaml.model.PrimaryKeyDefinition -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration -import spock.lang.Specification -import spock.lang.Unroll - -class NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolverTest extends Specification { - - @Unroll - def "should return group validation class when createForeignKeyConstraintWithTenantColumn is #value"(){ - given: - def tested = new NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver() - def sharedContext = new SharedSchemaContextConfiguration().setCreateForeignKeyConstraintWithTenantColumn(value) - - when: - def result = tested.resolveForSharedSchemaContextConfiguration(sharedContext, null) - - then: - result == PrimaryKeyDefinition.NameForFunctionThatChecksIfRecordExistsInTableNotBlank - - where: - value << [null, false] - } - - def "should return null as group validation class when createForeignKeyConstraintWithTenantColumn is true"(){ - given: - def tested = new NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver() - def sharedContext = new SharedSchemaContextConfiguration().setCreateForeignKeyConstraintWithTenantColumn(true) - - when: - def result = tested.resolveForSharedSchemaContextConfiguration(sharedContext, null) - - then: - result == null - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupsResolverTest.groovy b/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupsResolverTest.groovy deleted file mode 100644 index 7626838b0..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/groovy/com/github/starnowski/posmulten/configuration/yaml/validation/groups/ValidatorGroupsResolverTest.groovy +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml.validation.groups - -import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration -import spock.lang.Specification - -import java.util.stream.Collectors - -class ValidatorGroupsResolverTest extends Specification { - - def"should have expected list of validator groups resolvers"() - { - given: - def tested = new ValidatorGroupsResolver() - - when: - def results = tested.getValidatorGroupResolvers() - - then: - results.stream().map {it -> it.getClass()}.collect(Collectors.toList()) == [NameForFunctionThatChecksIfRecordExistsInTableNotBlankGroupResolver.class] - } - - def"should return expected list of classed based on result from combined list of validator groups resolvers"() - { - given: - def vgr1 = Mock(ValidatorGroupResolver) - def vgr2 = Mock(ValidatorGroupResolver) - def tested = new ValidatorGroupsResolver([vgr1, vgr2]) - def sharedSchemaContextConfiguration = new SharedSchemaContextConfiguration() - def validatorGroupResolverContext = Mock(ValidatorGroupResolver.ValidatorGroupResolverContext) - - when: - def results = tested.resolveForSharedSchemaContextConfiguration(sharedSchemaContextConfiguration, validatorGroupResolverContext) - - then: - 1 * vgr1.resolveForSharedSchemaContextConfiguration(sharedSchemaContextConfiguration, validatorGroupResolverContext) >> ValidationClass1 - 1 * vgr2.resolveForSharedSchemaContextConfiguration(sharedSchemaContextConfiguration, validatorGroupResolverContext) >> ValidationClass2 - results == [ValidationClass1, ValidationClass2] - } - - class ValidationClass1 {} - - class ValidationClass2 {} -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/IntegerRandomizer.java b/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/IntegerRandomizer.java deleted file mode 100644 index d3805b22e..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/IntegerRandomizer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml; - -import org.jeasy.random.api.Randomizer; - -import java.util.Random; - -public class IntegerRandomizer implements Randomizer { - - private final int min; - private final int max; - - public IntegerRandomizer(int min, int max) { - this.min = min; - this.max = max; - } - - @Override - public Integer getRandomValue() { - return new Random().nextInt(max) + min; - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/OptionalRandomizer.java b/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/OptionalRandomizer.java deleted file mode 100644 index 633d7d65c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/OptionalRandomizer.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml; - -import org.jeasy.random.api.Randomizer; - -import java.util.Optional; -import java.util.Random; - -public class OptionalRandomizer implements Randomizer> { - - public OptionalRandomizer(Randomizer randomizer, boolean nullAble) { - this.randomizer = randomizer; - this.nullAble = nullAble; - } - - private final Randomizer randomizer; - private final boolean nullAble; - - @Override - public Optional getRandomValue() { - if (nullAble && new Random().nextBoolean()) { - return Optional.empty(); - } - T value = randomizer.getRandomValue(); - return Optional.of(value); - } -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestProperties.java b/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestProperties.java deleted file mode 100644 index 8ab0db4d5..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/java/com/github/starnowski/posmulten/configuration/yaml/TestProperties.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.starnowski.posmulten.configuration.yaml; - -public class TestProperties { - - public static final String ALL_FIELDS_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/all-fields.yaml"; - public static final String ALL_FIELDS_WITH_FOREIGN_KEY_CONSTRAINT_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/all-fields-with-foreign-key-constraint.yaml"; - public static final String INTEGRATION_TESTS_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml"; - public static final String DISABLED_SQL_DEFINITIONS_VALIDATION_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/disabled-sql-definitions-validation.yaml"; - public static final String SQL_DEFINITIONS_VALIDATION_WITH_CUSTOM_CONSTRAINTS_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-custom-constraints.yaml"; - public static final String ONLY_MANDATORY_FIELDS_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields.yaml"; - public static final String ONLY_MANDATORY_FIELDS_WITH_TEMPLATE_VALUES_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields-with-template-values.yaml"; - public static final String CONFIGURATION_WITH_TEMPLATE_VALUES_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/configuration-with-template-values.yaml"; - public static final String MANY_TO_MANY_TABLES_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/many-to-many-tables.yaml"; - public static final String INVALID_ROOT_NODE_BLANK_FIELDS_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/invalid-root-node-blank-fields.yaml"; - public static final String INVALID_NESTED_NODE_BLANK_FIELDS_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-blank-fields.yaml"; - public static final String INVALID_NESTED_NODE_EMPTY_LIST_FILE_PATH = "/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-empty-list.yaml"; - public static final String INVALID_LIST_NODES_BLANK_FIELDS_PATH = "/com/github/starnowski/posmulten/configuration/yaml/invalid-list-nodes-blank-fields.yaml"; - public static final String INVALID_MAP_BLANK_FIELDS_PATH = "/com/github/starnowski/posmulten/configuration/yaml/invalid-map-blank-fields.yaml"; - public static final String INVALID_CUSTOM_DEFINITIONS_FIELDS_PATH = "/com/github/starnowski/posmulten/configuration/yaml/invalid-custom-definitions.yaml"; - public static final String SQL_DEFINITIONS_VALIDATION_WITH_INVALID_CONSTRAINTS_PATH = "/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-invalid-constraints.yaml"; - public static final String SQL_DEFINITIONS_VALIDATION_WITH_NULL_VALUES_PATH = "/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-null-values.yaml"; -} diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/all-fields-with-foreign-key-constraint.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/all-fields-with-foreign-key-constraint.yaml deleted file mode 100644 index 0f4408f7c..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/all-fields-with-foreign-key-constraint.yaml +++ /dev/null @@ -1,137 +0,0 @@ -default_schema: public -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -create_foreignkey_constraint_with_tenant_column: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" - - "'; DROP ALL TABLES" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id - - name: notifications - rls_policy: - name: notifications_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - valid_tenant_value_constraint_name: "is_tenant_id_valid" - primary_key_definition: - pk_columns_name_to_type: - uuid: uuid - foreign_keys: - - constraint_name: "notifications_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - name: dictionary - schema: no_other_schema - rls_policy: - name: dictionary_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - pk_columns_name_to_type: - id: bigint - # table with blank (null) schema - - name: dictionary_1 - schema: - rls_policy: - name: dictionary_1_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - pk_columns_name_to_type: - id: bigint - # table with null schema - - name: dictionary_2 - schema: - rls_policy: - name: dictionary_2_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - pk_columns_name_to_type: - id: bigint - - name: notifications_1 - rls_policy: - name: notifications_1_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - foreign_keys: - - constraint_name: "notifications_1_dictionary_tenant_constraint" - table_name: dictionary - table_schema: no_other_schema - foreign_key_primary_key_columns_mappings: - dictionary_id: id -custom_sql_definitions: - - position: AT_END - creation_script: | - ALTER ... - validation_scripts: - - | - SELECT (6) FROM ... - - position: AT_BEGINNING - creation_script: | - ALTER COLUMN ... - drop_script: | - ALTER DROP ... - validation_scripts: - - | - SELECT (13) FROM ... - - "SELECT (1) ..... FROM DUAL" - - position: CUSTOM - custom_position: "Some custom position" - creation_script: | - ALTER ... - validation_scripts: - - | - SELECT (371) FROM ... \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/all-fields.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/all-fields.yaml deleted file mode 100644 index 1f90c78ff..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/all-fields.yaml +++ /dev/null @@ -1,143 +0,0 @@ -default_schema: public -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" - - "'; DROP ALL TABLES" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id - - name: notifications - rls_policy: - name: notifications_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - valid_tenant_value_constraint_name: "is_tenant_id_valid" - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_notification_exists" - pk_columns_name_to_type: - uuid: uuid - foreign_keys: - - constraint_name: "notifications_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - name: dictionary - schema: no_other_schema - rls_policy: - name: dictionary_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_dictionary_exists" - pk_columns_name_to_type: - id: bigint - # table with blank (null) schema - - name: dictionary_1 - schema: - rls_policy: - name: dictionary_1_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_dictionary_1_exists" - pk_columns_name_to_type: - id: bigint - # table with null schema - - name: dictionary_2 - schema: - rls_policy: - name: dictionary_2_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_dictionary_2_exists" - pk_columns_name_to_type: - id: bigint - - name: notifications_1 - rls_policy: - name: notifications_1_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - foreign_keys: - - constraint_name: "notifications_1_dictionary_tenant_constraint" - table_name: dictionary - table_schema: no_other_schema - foreign_key_primary_key_columns_mappings: - dictionary_id: id -custom_sql_definitions: - - position: AT_END - creation_script: | - ALTER ... - validation_scripts: - - | - SELECT (6) FROM ... - - position: AT_BEGINNING - creation_script: | - ALTER COLUMN ... - drop_script: | - ALTER DROP ... - validation_scripts: - - | - SELECT (13) FROM ... - - "SELECT (1) ..... FROM DUAL" - - position: CUSTOM - custom_position: "Some custom position" - creation_script: | - ALTER ... - validation_scripts: - - | - SELECT (371) FROM ... \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/configuration-with-template-values.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/configuration-with-template-values.yaml deleted file mode 100644 index 4b2221cdb..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/configuration-with-template-values.yaml +++ /dev/null @@ -1,10 +0,0 @@ -default_schema: "{{db_schema}}" -grantee: "{{db_rls_grantee}}" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/disabled-sql-definitions-validation.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/disabled-sql-definitions-validation.yaml deleted file mode 100644 index 1ec9fb93e..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/disabled-sql-definitions-validation.yaml +++ /dev/null @@ -1,65 +0,0 @@ -default_schema: non_public_schema -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -grantee: "postgresql-core-user" -sql_definitions_validation: - disabled: true -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml deleted file mode 100644 index 0d7b87e01..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/integration-tests-configuration.yaml +++ /dev/null @@ -1,99 +0,0 @@ -default_schema: non_public_schema -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "postgresql-core-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id - - name: notifications - rls_policy: - name: notifications_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - valid_tenant_value_constraint_name: "is_tenant_id_valid" - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_notification_exists" - pk_columns_name_to_type: - uuid: uuid - foreign_keys: - - constraint_name: "notifications_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - name: groups - rls_policy: - name: "groups_table_rls_policy" - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_groups_exists" - pk_columns_name_to_type: - uuid: uuid - - name: users_groups - rls_policy: - name: groups_table_rls_policy - foreign_keys: - - constraint_name: "users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "groups_tenant_constraint" - table_name: "groups" - foreign_key_primary_key_columns_mappings: - group_id: uuid \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-custom-definitions.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-custom-definitions.yaml deleted file mode 100644 index 66ca06b5a..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-custom-definitions.yaml +++ /dev/null @@ -1,24 +0,0 @@ -default_schema: non_public -grantee: "db-user" -custom_sql_definitions: - # Missing 'position' - - position: - creation_script: | - ALTER ... - # Missing 'position' - - creation_script: | - ALTER COLUMN ... - drop_script: | - ALTER DROP ... - validation_scripts: - - | - SELECT (13) FROM ... - - "SELECT (1) ..... FROM DUAL" - - position: CUSTOM - # Missing 'custom_position' - creation_script: | - ALTER ... - # Invalid 'position' - - position: NO_SUCH_POSITION - creation_script: | - ALTER ... \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-list-nodes-blank-fields.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-list-nodes-blank-fields.yaml deleted file mode 100644 index fa9bec2b3..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-list-nodes-blank-fields.yaml +++ /dev/null @@ -1,78 +0,0 @@ -default_schema: public -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" - - "'; DROP ALL TABLES" -tables: - - rls_policy: # Without name - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: # Without rls_policy.name - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id - - name: notifications - rls_policy: - name: notifications_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - valid_tenant_value_constraint_name: "is_tenant_id_valid" - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: " " # name_for_function_that_checks_if_record_exists_in_table can not be null - pk_columns_name_to_type: - uuid: uuid - foreign_keys: - - constraint_name: "notifications_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-map-blank-fields.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-map-blank-fields.yaml deleted file mode 100644 index 5d4e7ae52..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-map-blank-fields.yaml +++ /dev/null @@ -1,82 +0,0 @@ -default_schema: public -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" - - "'; DROP ALL TABLES" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "notifications_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: {} - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: " " - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: "" - " ": user_id - - name: notifications - rls_policy: - name: notifications_table_rls_policy - tenant_column: tenant - create_tenant_column_for_table: true - valid_tenant_value_constraint_name: "is_tenant_id_valid" - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_notification_exists" - pk_columns_name_to_type: - uuid: uuid - foreign_keys: - - constraint_name: "notifications_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_identi: " " \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-blank-fields.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-blank-fields.yaml deleted file mode 100644 index d4e4d8ecf..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-blank-fields.yaml +++ /dev/null @@ -1,14 +0,0 @@ -default_schema: public -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: - is_tenant_valid_constraint_name: " " \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-empty-list.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-empty-list.yaml deleted file mode 100644 index 3ec0b89f1..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-nested-node-empty-list.yaml +++ /dev/null @@ -1,15 +0,0 @@ -default_schema: public -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: [] \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-root-node-blank-fields.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-root-node-blank-fields.yaml deleted file mode 100644 index c3a01f2ce..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/invalid-root-node-blank-fields.yaml +++ /dev/null @@ -1,11 +0,0 @@ -default_schema: null -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "" # Field cannot be empty -set_current_tenant_id_function_name: " " # Field cannot be blank -equals_current_tenant_identifier_function_name: null # Field cannot be null -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -default_tenant_id_column: "tenant_id" -grantee: "" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/many-to-many-tables.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/many-to-many-tables.yaml deleted file mode 100644 index 30f904c6e..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/many-to-many-tables.yaml +++ /dev/null @@ -1,48 +0,0 @@ -default_schema: public -default_tenant_id_column: "tenant_id" -grantee: "application-user" -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - tenant_identifiers_blacklist: - - invalid_tenant - - "wrong tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: groups - rls_policy: - name: groups_table_rls_policy - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_group_exists" - pk_columns_name_to_type: - uuid: UUID - - name: users_groups - rls_policy: - name: groups_table_rls_policy - foreign_keys: - - constraint_name: "users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "groups_tenant_constraint" - table_name: "groups" - foreign_key_primary_key_columns_mappings: - group_id: uuid \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields-with-template-values.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields-with-template-values.yaml deleted file mode 100644 index f69d10f68..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields-with-template-values.yaml +++ /dev/null @@ -1,2 +0,0 @@ -default_schema: "{{db_schema}}" -grantee: "{{db_grantee}}" \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields.yaml deleted file mode 100644 index 0b056daa9..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/only-mandatory-fields.yaml +++ /dev/null @@ -1,2 +0,0 @@ -default_schema: non_public -grantee: "db-user" \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-custom-constraints.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-custom-constraints.yaml deleted file mode 100644 index 49b7132cd..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-custom-constraints.yaml +++ /dev/null @@ -1,66 +0,0 @@ -default_schema: non_public_schema -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -grantee: "postgresql-core-user" -sql_definitions_validation: - identifier_max_length: 255 - identifier_min_length: 8 -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-invalid-constraints.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-invalid-constraints.yaml deleted file mode 100644 index a570e0739..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-invalid-constraints.yaml +++ /dev/null @@ -1,65 +0,0 @@ -default_schema: non_public_schema -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -grantee: "postgresql-core-user" -sql_definitions_validation: - identifier_min_length: 0 -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id \ No newline at end of file diff --git a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-null-values.yaml b/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-null-values.yaml deleted file mode 100644 index 0f7ae84f2..000000000 --- a/configuration-parent/configuration-yaml-interpreter/src/test/resources/com/github/starnowski/posmulten/configuration/yaml/sql-definitions-validation-with-null-values.yaml +++ /dev/null @@ -1,67 +0,0 @@ -default_schema: non_public_schema -current_tenant_id_property_type: "VARCHAR(255)" -current_tenant_id_property: "pos.c.ten" -get_current_tenant_id_function_name: "get_ten_id" -set_current_tenant_id_function_name: "set_tenant" -equals_current_tenant_identifier_function_name: "equals_cur_tenant" -tenant_has_authorities_function_name: "_tenant_hast_auth" -force_row_level_security_for_table_owner: true -grantee: "postgresql-core-user" -sql_definitions_validation: - identifier_max_length: - identifier_min_length: - disabled: -set_current_tenant_identifier_as_default_value_for_tenant_column_in_all_tables: true -valid_tenant_value_constraint: - is_tenant_valid_function_name: is_t_valid - is_tenant_valid_constraint_name: "is_tenant_valid_constraint_SDFA" - tenant_identifiers_blacklist: - - invalid_tenant - - "Some strange tenant ID" -tables: - - name: users - rls_policy: - name: users_table_rls_policy - tenant_column: tenant_id - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_user_exists" - pk_columns_name_to_type: - id: bigint - - name: posts - rls_policy: - name: "posts_table_rls_policy" - tenant_column: tenant_id - skip_adding_of_tenant_column_default_value: false - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_post_exists" - pk_columns_name_to_type: - id: bigint - foreign_keys: - - constraint_name: "posts_users_tenant_constraint" - table_name: "users" - foreign_key_primary_key_columns_mappings: - user_id: id - - name: "comments" - rls_policy: - name: comments_table_rls_policy - tenant_column: tenant - skip_adding_of_tenant_column_default_value: true - primary_key_definition: - name_for_function_that_checks_if_record_exists_in_table: "is_comment_exists" - pk_columns_name_to_type: - id: int - user_id: bigint - foreign_keys: - - constraint_name: "comments_users_tenant_constraint" - table_name: users - foreign_key_primary_key_columns_mappings: - user_id: id - - constraint_name: "comments_posts_tenant_constraint" - table_name: posts - foreign_key_primary_key_columns_mappings: - post_id: id - - constraint_name: "comments_comment_parent_tenant_constraint" - table_name: comments - foreign_key_primary_key_columns_mappings: - parent_comment_id: id - parent_comment_user_id: user_id \ No newline at end of file diff --git a/configuration-parent/pom.xml b/configuration-parent/pom.xml index b8f99237b..ba30ad11c 100644 --- a/configuration-parent/pom.xml +++ b/configuration-parent/pom.xml @@ -10,11 +10,10 @@ 4.0.0 pom - configuration-yaml-interpreter - configuration-yaml-interpreter-functional-tests configuration-core configuration configuration-jar + configuration-yaml-interpreter-parent com.github.starnowski.posmulten.configuration configuration-parent diff --git a/openwebstart/README.md b/openwebstart/README.md index 18217ac53..dfe072457 100644 --- a/openwebstart/README.md +++ b/openwebstart/README.md @@ -2,7 +2,7 @@ This is simple GUI application implemented with Swing library. It generates DDL statements for creation, drop and checking RLS policy. -It uses yaml configuration based on schema for module [configuration-yaml-interpreter](../configuration-parent/configuration-yaml-interpreter) +It uses yaml configuration based on schema for module [configuration-yaml-interpreter](../configuration-parent/configuration-yaml-interpreter-parent/configuration-yaml-interpreter) After building the whole project, you should have an executable jar with dependencies.: