Skip to content

Commit 0b65661

Browse files
committed
test: create scenarios to deployment parse
Signed-off-by: Otavio Santana <[email protected]>
1 parent 218fc8b commit 0b65661

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

jnosql-oracle/src/main/java/org/eclipse/jnosql/databases/oracle/communication/DeploymentType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public Optional<AuthorizationProvider> apply(Settings settings) {
9191
*/
9292
public static DeploymentType parse(String value) {
9393
try {
94+
if(value == null) {
95+
return DeploymentType.ON_PREMISES;
96+
}
9497
return DeploymentType.valueOf(value.toUpperCase());
9598
} catch (IllegalArgumentException | NullPointerException e) {
9699
return DeploymentType.ON_PREMISES;

jnosql-oracle/src/main/java/org/eclipse/jnosql/databases/oracle/communication/NoSQLHandleConfigConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public NoSQLHandleConfiguration apply(Settings settings) {
3939

4040

4141
DeploymentType deploymentType = settings.get(OracleNoSQLConfigurations.DEPLOYMENT.get())
42-
.map(Object::toString).map(DeploymentType::valueOf).orElse(DeploymentType.ON_PREMISES);
42+
.map(Object::toString).map(DeploymentType::parse).orElse(DeploymentType.ON_PREMISES);
4343
NoSQLHandleConfig config = new NoSQLHandleConfig(host);
4444

4545
deploymentType.apply(settings).ifPresent(config::setAuthorizationProvider);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
package org.eclipse.jnosql.databases.oracle.communication;
16+
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.params.ParameterizedTest;
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
import java.util.Locale;
22+
23+
import static org.junit.jupiter.api.Assertions.*;
24+
25+
class DeploymentTypeTest {
26+
27+
28+
@Test
29+
void shouldReturnOnPremiseWhenIsNull() {
30+
assertEquals(DeploymentType.ON_PREMISES, DeploymentType.parse(null));
31+
}
32+
33+
@Test
34+
void shouldReturnOnPremiseWhenTextIsInvalid() {
35+
assertEquals(DeploymentType.ON_PREMISES, DeploymentType.parse("invalid"));
36+
}
37+
38+
@ParameterizedTest
39+
@EnumSource(DeploymentType.class)
40+
void shouldParseEnum(DeploymentType type){
41+
assertEquals(type, DeploymentType.parse(type.name()));
42+
}
43+
44+
@ParameterizedTest
45+
@EnumSource(DeploymentType.class)
46+
void shouldParseEnumIgnoreCase(DeploymentType type){
47+
assertEquals(type, DeploymentType.parse(type.name().toLowerCase(Locale.ROOT)));
48+
}
49+
}

0 commit comments

Comments
 (0)