Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where any value of enable_types_contributor is treated as false #735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ public void contribute(TypeContributions typeContributions, ServiceRegistry serv
if(value instanceof Boolean) {
return value;
}
if(value instanceof String) {
return Boolean.getBoolean((String) value);
if (value instanceof String) {
if ("true".equalsIgnoreCase((String) value)) {
return Boolean.TRUE;
} else if ("false".equalsIgnoreCase((String) value)) {
return Boolean.FALSE;
}
}
throw new HibernateException(
String.format("The value [%s] of the [%s] setting is not supported!", value, ENABLE_TYPES_CONTRIBUTOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public void contribute(TypeContributions typeContributions, ServiceRegistry serv
if(value instanceof Boolean) {
return value;
}
if(value instanceof String) {
return Boolean.getBoolean((String) value);
if (value instanceof String) {
if ("true".equalsIgnoreCase((String) value)) {
return Boolean.TRUE;
} else if ("false".equalsIgnoreCase((String) value)) {
return Boolean.FALSE;
}
}
throw new HibernateException(
String.format("The value [%s] of the [%s] setting is not supported!", value, ENABLE_TYPES_CONTRIBUTOR)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.hypersistence.utils.hibernate.util;

import io.hypersistence.utils.hibernate.util.AbstractTest;
import io.hypersistence.utils.test.providers.DataSourceProvider;
import io.hypersistence.utils.hibernate.util.providers.PostgreSQLDataSourceProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.hypersistence.utils.hibernate.util.contributor;

import io.hypersistence.utils.hibernate.type.HibernateTypesContributor;
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest;
import org.hibernate.HibernateException;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

@RunWith(Enclosed.class)
public class TypeContributorToggleTest {
public static class TypeContributorEnabledSettingValueTrueTest extends TypeContributorEnableTest {
@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(
HibernateTypesContributor.ENABLE_TYPES_CONTRIBUTOR,
Boolean.TRUE.toString()
);
}
}

public static class TypeContributorDisabledSettingValueArbitraryStringTest extends AbstractPostgreSQLIntegrationTest {
@Override
public void init() {
}

@Override
public void destroy() {
}

@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(
HibernateTypesContributor.ENABLE_TYPES_CONTRIBUTOR,
"arbitrary"
);
}

@Test
public void test() {
assertEquals("The value [arbitrary] of the [hypersistence.utils.enable_types_contributor] setting is not supported!",
assertThrows(HibernateException.class, this::newEntityManagerFactory).getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.hypersistence.utils.hibernate.type.array.*;
import io.hypersistence.utils.hibernate.type.basic.Iso8601MonthType;
import io.hypersistence.utils.hibernate.type.basic.NullableCharacterType;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLHStoreType;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLInetType;
import io.hypersistence.utils.hibernate.type.interval.OracleIntervalDayToSecondType;
Expand Down Expand Up @@ -45,8 +44,12 @@ public void contribute(TypeContributions typeContributions, ServiceRegistry serv
if(value instanceof Boolean) {
return value;
}
if(value instanceof String) {
return Boolean.getBoolean((String) value);
if (value instanceof String) {
if ("true".equalsIgnoreCase((String) value)) {
return Boolean.TRUE;
} else if ("false".equalsIgnoreCase((String) value)) {
return Boolean.FALSE;
}
}
throw new HibernateException(
String.format("The value [%s] of the [%s] setting is not supported!", value, ENABLE_TYPES_CONTRIBUTOR)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.hypersistence.utils.hibernate.util;

import io.hypersistence.utils.hibernate.util.AbstractTest;
import io.hypersistence.utils.test.providers.DataSourceProvider;
import io.hypersistence.utils.hibernate.util.providers.PostgreSQLDataSourceProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.hypersistence.utils.hibernate.util.contributor;

import io.hypersistence.utils.hibernate.type.HibernateTypesContributor;
import io.hypersistence.utils.hibernate.type.basic.Inet;
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest;
import jakarta.persistence.Column;
Expand All @@ -9,8 +8,6 @@
import jakarta.persistence.Table;
import org.junit.Test;

import java.util.Properties;

import static org.junit.Assert.assertEquals;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.hypersistence.utils.hibernate.util.contributor;

import io.hypersistence.utils.hibernate.type.HibernateTypesContributor;
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest;
import org.hibernate.HibernateException;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

@RunWith(Enclosed.class)
public class TypeContributorToggleTest {
public static class TypeContributorEnabledSettingValueTrueTest extends TypeContributorEnableTest {
@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(
HibernateTypesContributor.ENABLE_TYPES_CONTRIBUTOR,
Boolean.TRUE.toString()
);
}
}

public static class TypeContributorDisabledSettingValueArbitraryStringTest extends AbstractPostgreSQLIntegrationTest {
@Override
public void init() {
}

@Override
public void destroy() {
}

@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(
HibernateTypesContributor.ENABLE_TYPES_CONTRIBUTOR,
"arbitrary"
);
}

@Test
public void test() {
assertEquals("The value [arbitrary] of the [hypersistence.utils.enable_types_contributor] setting is not supported!",
assertThrows(HibernateException.class, this::newEntityManagerFactory).getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.hypersistence.utils.common.ReflectionUtils;
import io.hypersistence.utils.hibernate.type.basic.Iso8601MonthType;
import io.hypersistence.utils.hibernate.type.basic.NullableCharacterType;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLHStoreType;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLInetType;
import io.hypersistence.utils.hibernate.type.interval.OracleIntervalDayToSecondType;
Expand Down Expand Up @@ -44,8 +43,12 @@ public void contribute(TypeContributions typeContributions, ServiceRegistry serv
if(value instanceof Boolean) {
return value;
}
if(value instanceof String) {
return Boolean.getBoolean((String) value);
if (value instanceof String) {
if ("true".equalsIgnoreCase((String) value)) {
return Boolean.TRUE;
} else if ("false".equalsIgnoreCase((String) value)) {
return Boolean.FALSE;
}
}
throw new HibernateException(
String.format("The value [%s] of the [%s] setting is not supported!", value, ENABLE_TYPES_CONTRIBUTOR)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.hypersistence.utils.hibernate.util;

import io.hypersistence.utils.hibernate.util.AbstractTest;
import io.hypersistence.utils.test.providers.DataSourceProvider;
import io.hypersistence.utils.hibernate.util.providers.PostgreSQLDataSourceProvider;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.hypersistence.utils.hibernate.util.contributor;

import io.hypersistence.utils.hibernate.type.HibernateTypesContributor;
import io.hypersistence.utils.hibernate.type.basic.Inet;
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest;
import jakarta.persistence.Column;
Expand All @@ -9,8 +8,6 @@
import jakarta.persistence.Table;
import org.junit.Test;

import java.util.Properties;

import static org.junit.Assert.assertEquals;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.hypersistence.utils.hibernate.util.contributor;

import io.hypersistence.utils.hibernate.type.HibernateTypesContributor;
import io.hypersistence.utils.hibernate.util.AbstractPostgreSQLIntegrationTest;
import org.hibernate.HibernateException;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

@RunWith(Enclosed.class)
public class TypeContributorToggleTest {
public static class TypeContributorEnabledSettingValueTrueTest extends TypeContributorEnableTest {
@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(
HibernateTypesContributor.ENABLE_TYPES_CONTRIBUTOR,
Boolean.TRUE.toString()
);
}
}

public static class TypeContributorDisabledSettingValueArbitraryStringTest extends AbstractPostgreSQLIntegrationTest {
@Override
public void init() {
}

@Override
public void destroy() {
}

@Override
protected void additionalProperties(Properties properties) {
properties.setProperty(
HibernateTypesContributor.ENABLE_TYPES_CONTRIBUTOR,
"arbitrary"
);
}

@Test
public void test() {
assertEquals("The value [arbitrary] of the [hypersistence.utils.enable_types_contributor] setting is not supported!",
assertThrows(HibernateException.class, this::newEntityManagerFactory).getMessage());
}
}
}