diff --git a/src/main/java/com/skyflow/VaultClient.java b/src/main/java/com/skyflow/VaultClient.java index a6a63f64..2f415f4f 100644 --- a/src/main/java/com/skyflow/VaultClient.java +++ b/src/main/java/com/skyflow/VaultClient.java @@ -97,7 +97,7 @@ protected RecordServiceInsertRecordBody getBulkInsertRequestBody(InsertRequest r insertRecordBody.setTokenization(request.getReturnTokens()); insertRecordBody.setHomogeneous(request.getHomogeneous()); insertRecordBody.setUpsert(request.getUpsert()); - insertRecordBody.setByot(request.getTokenStrict().getBYOT()); + insertRecordBody.setByot(request.getTokenMode().getBYOT()); List> values = request.getValues(); List> tokens = request.getTokens(); @@ -117,7 +117,7 @@ protected RecordServiceInsertRecordBody getBulkInsertRequestBody(InsertRequest r protected RecordServiceBatchOperationBody getBatchInsertRequestBody(InsertRequest request) { RecordServiceBatchOperationBody insertRequestBody = new RecordServiceBatchOperationBody(); insertRequestBody.setContinueOnError(true); - insertRequestBody.setByot(request.getTokenStrict().getBYOT()); + insertRequestBody.setByot(request.getTokenMode().getBYOT()); ArrayList> values = request.getValues(); ArrayList> tokens = request.getTokens(); @@ -142,7 +142,7 @@ protected RecordServiceBatchOperationBody getBatchInsertRequestBody(InsertReques protected RecordServiceUpdateRecordBody getUpdateRequestBody(UpdateRequest request) { RecordServiceUpdateRecordBody updateRequestBody = new RecordServiceUpdateRecordBody(); - updateRequestBody.byot(request.getTokenStrict().getBYOT()); + updateRequestBody.byot(request.getTokenMode().getBYOT()); updateRequestBody.setTokenization(request.getReturnTokens()); HashMap values = request.getData(); HashMap tokens = request.getTokens(); diff --git a/src/main/java/com/skyflow/enums/Byot.java b/src/main/java/com/skyflow/enums/TokenMode.java similarity index 88% rename from src/main/java/com/skyflow/enums/Byot.java rename to src/main/java/com/skyflow/enums/TokenMode.java index 9fe7d989..28564bb5 100644 --- a/src/main/java/com/skyflow/enums/Byot.java +++ b/src/main/java/com/skyflow/enums/TokenMode.java @@ -2,14 +2,14 @@ import com.skyflow.generated.rest.models.V1BYOT; -public enum Byot { +public enum TokenMode { DISABLE(V1BYOT.DISABLE), ENABLE(V1BYOT.ENABLE), ENABLE_STRICT(V1BYOT.ENABLE_STRICT); private final V1BYOT byot; - Byot(V1BYOT byot) { + TokenMode(V1BYOT byot) { this.byot = byot; } diff --git a/src/main/java/com/skyflow/errors/ErrorMessage.java b/src/main/java/com/skyflow/errors/ErrorMessage.java index ac5fd0cf..81516e94 100644 --- a/src/main/java/com/skyflow/errors/ErrorMessage.java +++ b/src/main/java/com/skyflow/errors/ErrorMessage.java @@ -65,10 +65,10 @@ public enum ErrorMessage { EmptyValueInTokens("%s0 Validation error. Invalid value in tokens. Specify a valid value."), EmptyUpsert("%s0 Validation error. 'upsert' key can't be empty. Specify an upsert column."), HomogenousNotSupportedWithUpsert("%s0 Validation error. 'homogenous' is not supported with 'upsert'. Specify either 'homogenous' or 'upsert'."), - TokensPassedForByotDisable("%s0 Validation error. 'tokenStrict' wasn't specified. Set 'tokenStrict' to 'ENABLE' to insert tokens."), - NoTokensWithByot("%s0 Validation error. Tokens weren't specified for records while 'tokenStrict' was %s1. Specify tokens."), + TokensPassedForTokenModeDisable("%s0 Validation error. 'tokenMode' wasn't specified. Set 'tokenMode' to 'ENABLE' to insert tokens."), + NoTokensWithTokenMode("%s0 Validation error. Tokens weren't specified for records while 'tokenMode' was %s1. Specify tokens."), MismatchOfFieldsAndTokens("%s0 Validation error. 'fields' and 'tokens' have different columns names. Verify that 'fields' and 'tokens' columns match."), - InsufficientTokensPassedForByotEnableStrict("%s0 Validation error. 'tokenStrict' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."), + InsufficientTokensPassedForTokenModeEnableStrict("%s0 Validation error. 'tokenMode' is set to 'ENABLE_STRICT', but some fields are missing tokens. Specify tokens for all fields."), BatchInsertPartialSuccess("%s0 Insert operation completed with partial success."), BatchInsertFailure("%s0 Insert operation failed."), diff --git a/src/main/java/com/skyflow/logs/ErrorLogs.java b/src/main/java/com/skyflow/logs/ErrorLogs.java index ad32b886..64e40c82 100644 --- a/src/main/java/com/skyflow/logs/ErrorLogs.java +++ b/src/main/java/com/skyflow/logs/ErrorLogs.java @@ -53,12 +53,12 @@ public enum ErrorLogs { EMPTY_OR_NULL_KEY_IN_VALUES("Invalid %s1 request. Key can not be null or empty in values"), EMPTY_UPSERT("Invalid %s1 request. Upsert can not be empty."), HOMOGENOUS_NOT_SUPPORTED_WITH_UPSERT("Invalid %s1 request. Homogenous is not supported when upsert is passed."), - TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenStrict is DISABLE."), - TOKENS_REQUIRED_WITH_BYOT("Invalid %s1 request. Tokens are required when tokenStrict is %s2."), + TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE("Invalid %s1 request. Tokens are not allowed when tokenMode is DISABLE."), + TOKENS_REQUIRED_WITH_TOKEN_MODE("Invalid %s1 request. Tokens are required when tokenMode is %s2."), EMPTY_TOKENS("Invalid %s1 request. Tokens can not be empty."), EMPTY_OR_NULL_VALUE_IN_TOKENS("Invalid %s1 request. Value can not be null or empty in tokens for key \"%s2\"."), EMPTY_OR_NULL_KEY_IN_TOKENS("Invalid %s1 request. Key can not be null or empty in tokens."), - INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT("Invalid %s1 request. For tokenStrict as ENABLE_STRICT, tokens should be passed for all fields."), + INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT("Invalid %s1 request. For tokenMode as ENABLE_STRICT, tokens should be passed for all fields."), MISMATCH_OF_FIELDS_AND_TOKENS("Invalid %s1 request. Keys for values and tokens are not matching."), INSERT_RECORDS_REJECTED("Insert request resulted in failure."), TOKENS_REQUIRED("Invalid %s1 request. Tokens are required."), diff --git a/src/main/java/com/skyflow/utils/validations/Validations.java b/src/main/java/com/skyflow/utils/validations/Validations.java index 77f6b823..e1e52581 100644 --- a/src/main/java/com/skyflow/utils/validations/Validations.java +++ b/src/main/java/com/skyflow/utils/validations/Validations.java @@ -3,9 +3,9 @@ import com.skyflow.config.ConnectionConfig; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.Byot; import com.skyflow.enums.InterfaceName; import com.skyflow.enums.RedactionType; +import com.skyflow.enums.TokenMode; import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; @@ -238,7 +238,7 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky ArrayList> tokens = insertRequest.getTokens(); String upsert = insertRequest.getUpsert(); Boolean homogeneous = insertRequest.getHomogeneous(); - Byot tokenStrict = insertRequest.getTokenStrict(); + TokenMode tokenMode = insertRequest.getTokenMode(); if (table == null) { LogUtil.printErrorLog(Utils.parameterizedString( @@ -296,46 +296,46 @@ public static void validateInsertRequest(InsertRequest insertRequest) throws Sky } } - switch (tokenStrict) { + switch (tokenMode) { case DISABLE: if (tokens != null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE.getLog(), InterfaceName.INSERT.getName() + ErrorLogs.TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE.getLog(), InterfaceName.INSERT.getName() )); - throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensPassedForByotDisable.getMessage()); + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.TokensPassedForTokenModeDisable.getMessage()); } break; case ENABLE: if (tokens == null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(), - InterfaceName.INSERT.getName(), Byot.ENABLE.toString() + ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(), + InterfaceName.INSERT.getName(), TokenMode.ENABLE.toString() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), - Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString()) + Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString()) ); } - validateTokensForInsertRequest(tokens, values, tokenStrict); + validateTokensForInsertRequest(tokens, values, tokenMode); break; case ENABLE_STRICT: if (tokens == null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(), - InterfaceName.INSERT.getName(), Byot.ENABLE_STRICT.toString() + ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(), + InterfaceName.INSERT.getName(), TokenMode.ENABLE_STRICT.toString() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), - Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString()) + Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString()) ); } else if (tokens.size() != values.size()) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(), + ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(), InterfaceName.INSERT.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), - ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage() + ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage() ); } - validateTokensForInsertRequest(tokens, values, tokenStrict); + validateTokensForInsertRequest(tokens, values, tokenMode); break; } } @@ -488,7 +488,7 @@ public static void validateUpdateRequest(UpdateRequest updateRequest) throws Sky String table = updateRequest.getTable(); HashMap data = updateRequest.getData(); HashMap tokens = updateRequest.getTokens(); - Byot tokenStrict = updateRequest.getTokenStrict(); + TokenMode tokenMode = updateRequest.getTokenMode(); if (table == null) { LogUtil.printErrorLog(Utils.parameterizedString( @@ -550,42 +550,42 @@ public static void validateUpdateRequest(UpdateRequest updateRequest) throws Sky } } - switch (tokenStrict) { + switch (tokenMode) { case DISABLE: if (tokens != null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.TOKENS_NOT_ALLOWED_WITH_BYOT_DISABLE.getLog(), InterfaceName.INSERT.getName() + ErrorLogs.TOKENS_NOT_ALLOWED_WITH_TOKEN_MODE_DISABLE.getLog(), InterfaceName.UPDATE.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), - ErrorMessage.TokensPassedForByotDisable.getMessage()); + ErrorMessage.TokensPassedForTokenModeDisable.getMessage()); } break; case ENABLE: if (tokens == null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(), - InterfaceName.INSERT.getName(), Byot.ENABLE.toString() + ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(), + InterfaceName.UPDATE.getName(), TokenMode.ENABLE.toString() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), Utils.parameterizedString( - ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString())); + ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString())); } validateTokensMapWithTokenStrict(tokens, data); break; case ENABLE_STRICT: if (tokens == null) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.TOKENS_REQUIRED_WITH_BYOT.getLog(), - InterfaceName.INSERT.getName(), Byot.ENABLE_STRICT.toString() + ErrorLogs.TOKENS_REQUIRED_WITH_TOKEN_MODE.getLog(), + InterfaceName.UPDATE.getName(), TokenMode.ENABLE_STRICT.toString() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), Utils.parameterizedString( - ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString())); + ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString())); } else if (tokens.size() != (data.size() - 1)) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(), - InterfaceName.INSERT.getName() + ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(), + InterfaceName.UPDATE.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), - ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage()); + ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage()); } validateTokensMapWithTokenStrict(tokens, data); break; @@ -692,7 +692,7 @@ private static boolean isInvalidURL(String configURL) { private static void validateTokensForInsertRequest( ArrayList> tokens, ArrayList> values, - Byot tokenStrict + TokenMode tokenStrict ) throws SkyflowException { if (tokens.isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( @@ -704,31 +704,37 @@ private static void validateTokensForInsertRequest( for (int index = 0; index < tokens.size(); index++) { HashMap tokensMap = tokens.get(index); HashMap valuesMap = values.get(index); - if (tokensMap.size() != valuesMap.size() && tokenStrict == Byot.ENABLE_STRICT) { + if (tokensMap.size() != valuesMap.size() && tokenStrict == TokenMode.ENABLE_STRICT) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT.getLog(), + ErrorLogs.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT.getLog(), InterfaceName.INSERT.getName() )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), - ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage() + ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage() ); } - validateTokensMapWithTokenStrict(tokensMap, valuesMap); + validateTokensMapWithTokenStrict(tokensMap, valuesMap, InterfaceName.INSERT.getName()); } } private static void validateTokensMapWithTokenStrict( HashMap tokensMap, HashMap valuesMap + ) throws SkyflowException { + validateTokensMapWithTokenStrict(tokensMap, valuesMap, InterfaceName.UPDATE.getName()); + } + + private static void validateTokensMapWithTokenStrict( + HashMap tokensMap, HashMap valuesMap, String interfaceName ) throws SkyflowException { for (String key : tokensMap.keySet()) { if (key == null || key.trim().isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.EMPTY_OR_NULL_KEY_IN_TOKENS.getLog(), InterfaceName.INSERT.getName() + ErrorLogs.EMPTY_OR_NULL_KEY_IN_TOKENS.getLog(), interfaceName )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyKeyInTokens.getMessage()); } else if (!valuesMap.containsKey(key)) { LogUtil.printErrorLog(Utils.parameterizedString( - ErrorLogs.MISMATCH_OF_FIELDS_AND_TOKENS.getLog(), InterfaceName.INSERT.getName() + ErrorLogs.MISMATCH_OF_FIELDS_AND_TOKENS.getLog(), interfaceName )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.MismatchOfFieldsAndTokens.getMessage()); } else { @@ -736,7 +742,7 @@ private static void validateTokensMapWithTokenStrict( if (value == null || value.toString().trim().isEmpty()) { LogUtil.printErrorLog(Utils.parameterizedString( ErrorLogs.EMPTY_OR_NULL_VALUE_IN_TOKENS.getLog(), - InterfaceName.INSERT.getName(), key + interfaceName, key )); throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyValueInTokens.getMessage()); } diff --git a/src/main/java/com/skyflow/vault/connection/InvokeConnectionRequest.java b/src/main/java/com/skyflow/vault/connection/InvokeConnectionRequest.java index c64bedf4..ea71cd0a 100644 --- a/src/main/java/com/skyflow/vault/connection/InvokeConnectionRequest.java +++ b/src/main/java/com/skyflow/vault/connection/InvokeConnectionRequest.java @@ -2,7 +2,6 @@ import com.skyflow.enums.RequestMethod; -import java.util.HashMap; import java.util.Map; public class InvokeConnectionRequest { @@ -17,8 +16,8 @@ public static InvokeConnectionRequestBuilder builder() { return new InvokeConnectionRequestBuilder(); } - public RequestMethod getMethodName() { - return builder.methodName; + public RequestMethod getMethod() { + return builder.method; } public Map getPathParams() { @@ -38,19 +37,19 @@ public Object getRequestBody() { } public static final class InvokeConnectionRequestBuilder { - private RequestMethod methodName; + private RequestMethod method; private Map pathParams; private Map queryParams; private Map requestHeaders; private Object requestBody; private InvokeConnectionRequestBuilder() { - this.methodName = RequestMethod.POST; + this.method = RequestMethod.POST; this.requestBody = new Object(); } - public InvokeConnectionRequestBuilder methodName(RequestMethod methodName) { - this.methodName = methodName == null ? RequestMethod.POST : methodName; + public InvokeConnectionRequestBuilder method(RequestMethod method) { + this.method = method == null ? RequestMethod.POST : method; return this; } diff --git a/src/main/java/com/skyflow/vault/controller/ConnectionController.java b/src/main/java/com/skyflow/vault/controller/ConnectionController.java index 890ef530..81e413ed 100644 --- a/src/main/java/com/skyflow/vault/controller/ConnectionController.java +++ b/src/main/java/com/skyflow/vault/controller/ConnectionController.java @@ -48,7 +48,7 @@ public InvokeConnectionResponse invoke(InvokeConnectionRequest invokeConnectionR headers.put("x-skyflow-authorization", token == null ? apiKey : token); } - RequestMethod requestMethod = invokeConnectionRequest.getMethodName(); + RequestMethod requestMethod = invokeConnectionRequest.getMethod(); JsonObject requestBody = null; Object requestBodyObject = invokeConnectionRequest.getRequestBody(); diff --git a/src/main/java/com/skyflow/vault/data/InsertRequest.java b/src/main/java/com/skyflow/vault/data/InsertRequest.java index b2a49f1b..55db92e4 100644 --- a/src/main/java/com/skyflow/vault/data/InsertRequest.java +++ b/src/main/java/com/skyflow/vault/data/InsertRequest.java @@ -1,6 +1,6 @@ package com.skyflow.vault.data; -import com.skyflow.enums.Byot; +import com.skyflow.enums.TokenMode; import java.util.ArrayList; import java.util.HashMap; @@ -40,16 +40,12 @@ public Boolean getHomogeneous() { return this.builder.homogeneous; } - public Boolean getTokenMode() { - return this.builder.tokenMode; - } - public Boolean getContinueOnError() { return this.builder.continueOnError; } - public Byot getTokenStrict() { - return this.builder.tokenStrict; + public TokenMode getTokenMode() { + return this.builder.tokenMode; } public static final class InsertRequestBuilder { @@ -59,15 +55,13 @@ public static final class InsertRequestBuilder { private Boolean returnTokens; private String upsert; private Boolean homogeneous; - private Boolean tokenMode; private Boolean continueOnError; - private Byot tokenStrict; + private TokenMode tokenMode; private InsertRequestBuilder() { this.returnTokens = true; - this.tokenMode = false; this.continueOnError = false; - this.tokenStrict = Byot.DISABLE; + this.tokenMode = TokenMode.DISABLE; } public InsertRequestBuilder table(String table) { @@ -100,18 +94,13 @@ public InsertRequestBuilder homogeneous(Boolean homogeneous) { return this; } - public InsertRequestBuilder tokenMode(Boolean tokenMode) { - this.tokenMode = tokenMode != null && tokenMode; - return this; - } - public InsertRequestBuilder continueOnError(Boolean continueOnError) { this.continueOnError = continueOnError != null && continueOnError; return this; } - public InsertRequestBuilder tokenStrict(Byot tokenStrict) { - this.tokenStrict = tokenStrict == null ? Byot.DISABLE : tokenStrict; + public InsertRequestBuilder tokenMode(TokenMode tokenMode) { + this.tokenMode = tokenMode == null ? TokenMode.DISABLE : tokenMode; return this; } diff --git a/src/main/java/com/skyflow/vault/data/UpdateRequest.java b/src/main/java/com/skyflow/vault/data/UpdateRequest.java index 58e075ac..03ca8f42 100644 --- a/src/main/java/com/skyflow/vault/data/UpdateRequest.java +++ b/src/main/java/com/skyflow/vault/data/UpdateRequest.java @@ -1,6 +1,6 @@ package com.skyflow.vault.data; -import com.skyflow.enums.Byot; +import com.skyflow.enums.TokenMode; import java.util.HashMap; @@ -31,8 +31,8 @@ public HashMap getTokens() { return this.builder.tokens; } - public Byot getTokenStrict() { - return this.builder.tokenStrict; + public TokenMode getTokenMode() { + return this.builder.tokenMode; } public static final class UpdateRequestBuilder { @@ -40,11 +40,11 @@ public static final class UpdateRequestBuilder { private Boolean returnTokens; private HashMap data; private HashMap tokens; - private Byot tokenStrict; + private TokenMode tokenMode; private UpdateRequestBuilder() { this.returnTokens = true; - this.tokenStrict = Byot.DISABLE; + this.tokenMode = TokenMode.DISABLE; } public UpdateRequestBuilder table(String table) { @@ -67,8 +67,8 @@ public UpdateRequestBuilder tokens(HashMap tokens) { return this; } - public UpdateRequestBuilder tokenStrict(Byot tokenStrict) { - this.tokenStrict = tokenStrict == null ? Byot.DISABLE : tokenStrict; + public UpdateRequestBuilder tokenMode(TokenMode tokenStrict) { + this.tokenMode = tokenStrict == null ? TokenMode.DISABLE : tokenStrict; return this; } diff --git a/src/test/java/com/skyflow/config/ConnectionConfigTests.java b/src/test/java/com/skyflow/config/ConnectionConfigTests.java index 5ff32ca5..21b17838 100644 --- a/src/test/java/com/skyflow/config/ConnectionConfigTests.java +++ b/src/test/java/com/skyflow/config/ConnectionConfigTests.java @@ -3,19 +3,11 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.generated.rest.ApiClient; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.validations.Validations; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class ConnectionConfigTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -25,12 +17,7 @@ public class ConnectionConfigTests { private static Credentials credentials = null; @BeforeClass - public static void setup() throws SkyflowException, NoSuchMethodException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); - PowerMockito.mock(ApiClient.class); - + public static void setup() { connectionID = "connection123"; connectionURL = "https://connection.url.com"; invalidConnectionURL = "invalid.connection.url.com"; diff --git a/src/test/java/com/skyflow/config/CredentialsTests.java b/src/test/java/com/skyflow/config/CredentialsTests.java index cfc61de6..8093b2c2 100644 --- a/src/test/java/com/skyflow/config/CredentialsTests.java +++ b/src/test/java/com/skyflow/config/CredentialsTests.java @@ -3,22 +3,14 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.generated.rest.ApiClient; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.validations.Validations; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.ArrayList; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class CredentialsTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -32,12 +24,7 @@ public class CredentialsTests { private static String context = null; @BeforeClass - public static void setup() throws SkyflowException, NoSuchMethodException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); - PowerMockito.mock(ApiClient.class); - + public static void setup() { path = "valid-path-to-credentials-file"; credentialsString = "valid-credentials-string"; token = "valid-token"; diff --git a/src/test/java/com/skyflow/config/VaultConfigTests.java b/src/test/java/com/skyflow/config/VaultConfigTests.java index 1a5ca703..6bffa6d6 100644 --- a/src/test/java/com/skyflow/config/VaultConfigTests.java +++ b/src/test/java/com/skyflow/config/VaultConfigTests.java @@ -4,19 +4,11 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.generated.rest.ApiClient; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.validations.Validations; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class VaultConfigTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -26,12 +18,7 @@ public class VaultConfigTests { @BeforeClass - public static void setup() throws SkyflowException, NoSuchMethodException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); - PowerMockito.mock(ApiClient.class); - + public static void setup() { vaultID = "vault123"; clusterID = "cluster123"; diff --git a/src/test/java/com/skyflow/utils/UtilsTests.java b/src/test/java/com/skyflow/utils/UtilsTests.java index 79817bc5..8116046e 100644 --- a/src/test/java/com/skyflow/utils/UtilsTests.java +++ b/src/test/java/com/skyflow/utils/UtilsTests.java @@ -160,7 +160,7 @@ public void testConstructConnectionURL() { connectionConfig.setConnectionUrl(connectionUrl); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST).pathParams(pathParams).queryParams(queryParams).build(); + .method(RequestMethod.POST).pathParams(pathParams).queryParams(queryParams).build(); String filledUrl = Utils.constructConnectionURL(connectionConfig, request); Assert.assertEquals(connectionUrl + "?" + "query_param=value", filledUrl); } catch (Exception e) { diff --git a/src/test/java/com/skyflow/vault/connection/InvokeConnectionTests.java b/src/test/java/com/skyflow/vault/connection/InvokeConnectionTests.java index 8d950279..7c6f6213 100644 --- a/src/test/java/com/skyflow/vault/connection/InvokeConnectionTests.java +++ b/src/test/java/com/skyflow/vault/connection/InvokeConnectionTests.java @@ -46,7 +46,7 @@ public void testValidInputInInvokeConnectionRequestValidations() { requestBody.put("key", "value"); try { InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -56,7 +56,7 @@ public void testValidInputInInvokeConnectionRequestValidations() { Assert.assertEquals(1, request.getQueryParams().size()); Assert.assertEquals(1, request.getPathParams().size()); Assert.assertEquals(1, request.getRequestHeaders().size()); - Assert.assertEquals(RequestMethod.POST, request.getMethodName()); + Assert.assertEquals(RequestMethod.POST, request.getMethod()); Assert.assertNotNull(request.getRequestBody()); } catch (SkyflowException e) { Assert.fail(INVALID_EXCEPTION_THROWN); @@ -67,7 +67,7 @@ public void testValidInputInInvokeConnectionRequestValidations() { public void testEmptyRequestHeadersInInvokeConnectionRequestValidations() { try { InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -87,7 +87,7 @@ public void testNullRequestHeaderKeyInInvokeConnectionRequestValidations() { requestHeaders.put("header1", "value1"); requestHeaders.put(null, "value2"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -107,7 +107,7 @@ public void testEmptyRequestHeaderKeyInInvokeConnectionRequestValidations() { requestHeaders.put("header1", "value"); requestHeaders.put("", "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -127,7 +127,7 @@ public void testNullRequestHeaderValueInInvokeConnectionRequestValidations() { requestHeaders.put("header1", "value"); requestHeaders.put("header2", null); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -147,7 +147,7 @@ public void testEmptyRequestHeaderValueInInvokeConnectionRequestValidations() { requestHeaders.put("header1", "value"); requestHeaders.put("header2", ""); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -166,7 +166,7 @@ public void testEmptyPathParamsInInvokeConnectionRequestValidations() { try { requestHeaders.put("header1", "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -187,7 +187,7 @@ public void testNullPathParamKeyInInvokeConnectionRequestValidations() { pathParams.put("path_param", "value"); pathParams.put(null, "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -208,7 +208,7 @@ public void testEmptyPathParamKeyInInvokeConnectionRequestValidations() { pathParams.put("path_param", "value"); pathParams.put("", "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -229,7 +229,7 @@ public void testNullPathParamValueInInvokeConnectionRequestValidations() { pathParams.put("path_param1", "value"); pathParams.put("path_param2", null); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -250,7 +250,7 @@ public void testEmptyPathParamValueInInvokeConnectionRequestValidations() { pathParams.put("path_param1", "value"); pathParams.put("path_param2", ""); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -270,7 +270,7 @@ public void testEmptyQueryParamsInInvokeConnectionRequestValidations() { requestHeaders.put("header1", "value"); pathParams.put("path_param", "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -292,7 +292,7 @@ public void testNullQueryParamKeyInInvokeConnectionRequestValidations() { queryParams.put("query_param", "value"); queryParams.put(null, "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -314,7 +314,7 @@ public void testEmptyQueryParamKeyInInvokeConnectionRequestValidations() { queryParams.put("query_param", "value"); queryParams.put("", "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -336,7 +336,7 @@ public void testNullQueryParamValueInInvokeConnectionRequestValidations() { queryParams.put("query_param1", "value"); queryParams.put("query_param2", null); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -358,7 +358,7 @@ public void testEmptyQueryParamValueInInvokeConnectionRequestValidations() { queryParams.put("query_param1", "value"); queryParams.put("query_param2", ""); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) @@ -379,7 +379,7 @@ public void testEmptyRequestBodyInInvokeConnectionRequestValidations() { pathParams.put("path_param", "value"); queryParams.put("query_param", "value"); InvokeConnectionRequest request = InvokeConnectionRequest.builder() - .methodName(RequestMethod.POST) + .method(RequestMethod.POST) .requestHeaders(requestHeaders) .pathParams(pathParams) .queryParams(queryParams) diff --git a/src/test/java/com/skyflow/vault/data/DeleteTests.java b/src/test/java/com/skyflow/vault/data/DeleteTests.java index 8cb43880..a0401842 100644 --- a/src/test/java/com/skyflow/vault/data/DeleteTests.java +++ b/src/test/java/com/skyflow/vault/data/DeleteTests.java @@ -7,7 +7,6 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.Constants; import com.skyflow.utils.Utils; import com.skyflow.utils.validations.Validations; @@ -15,15 +14,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.ArrayList; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class DeleteTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -35,11 +28,7 @@ public class DeleteTests { private static Skyflow skyflowClient = null; @BeforeClass - public static void setup() throws SkyflowException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); - + public static void setup() { vaultID = "vault123"; clusterID = "cluster123"; @@ -50,10 +39,6 @@ public static void setup() throws SkyflowException { vaultConfig.setVaultId(vaultID); vaultConfig.setClusterId(clusterID); vaultConfig.setEnv(Env.DEV); -// vaultConfig.setCredentials(credentials); - -// skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build(); - skyflowID = "test_delete_id_1"; ids = new ArrayList<>(); table = "test_table"; diff --git a/src/test/java/com/skyflow/vault/data/GetTests.java b/src/test/java/com/skyflow/vault/data/GetTests.java index f9fa98d9..769ff868 100644 --- a/src/test/java/com/skyflow/vault/data/GetTests.java +++ b/src/test/java/com/skyflow/vault/data/GetTests.java @@ -8,7 +8,6 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.Constants; import com.skyflow.utils.Utils; import com.skyflow.utils.validations.Validations; @@ -16,16 +15,10 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.ArrayList; import java.util.HashMap; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class GetTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -42,10 +35,7 @@ public class GetTests { private static Skyflow skyflowClient = null; @BeforeClass - public static void setup() throws SkyflowException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); + public static void setup() { vaultID = "vault123"; clusterID = "cluster123"; @@ -59,8 +49,6 @@ public static void setup() throws SkyflowException { vaultConfig.setEnv(Env.DEV); vaultConfig.setCredentials(credentials); -// skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build(); - skyflowID = "test_get_id_1"; ids = new ArrayList<>(); field = "test_get_field"; diff --git a/src/test/java/com/skyflow/vault/data/InsertTests.java b/src/test/java/com/skyflow/vault/data/InsertTests.java index 87057d7c..7b911bc1 100644 --- a/src/test/java/com/skyflow/vault/data/InsertTests.java +++ b/src/test/java/com/skyflow/vault/data/InsertTests.java @@ -3,12 +3,11 @@ import com.skyflow.Skyflow; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.Byot; +import com.skyflow.enums.TokenMode; import com.skyflow.enums.Env; import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.Constants; import com.skyflow.utils.Utils; import com.skyflow.utils.validations.Validations; @@ -16,16 +15,10 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.ArrayList; import java.util.HashMap; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class InsertTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -40,10 +33,7 @@ public class InsertTests { private static Skyflow skyflowClient = null; @BeforeClass - public static void setup() throws SkyflowException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); + public static void setup() { vaultID = "vault123"; clusterID = "cluster123"; @@ -91,8 +81,7 @@ public void testValidInputInInsertRequestValidations() { .upsert(upsert) .values(values) .tokens(tokens) - .tokenMode(true) - .tokenStrict(Byot.ENABLE) + .tokenMode(TokenMode.ENABLE) .build(); Validations.validateInsertRequest(request); @@ -100,10 +89,9 @@ public void testValidInputInInsertRequestValidations() { Assert.assertEquals(upsert, request.getUpsert()); Assert.assertEquals(1, request.getValues().size()); Assert.assertEquals(1, request.getTokens().size()); - Assert.assertEquals(Byot.ENABLE, request.getTokenStrict()); + Assert.assertEquals(TokenMode.ENABLE, request.getTokenMode()); Assert.assertTrue(request.getContinueOnError()); Assert.assertTrue(request.getReturnTokens()); - Assert.assertTrue(request.getTokenMode()); Assert.assertFalse(request.getHomogeneous()); } catch (SkyflowException e) { Assert.fail(INVALID_EXCEPTION_THROWN); @@ -248,7 +236,7 @@ public void testTokensWithTokenStrictDisableInInsertRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.TokensPassedForByotDisable.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.TokensPassedForTokenModeDisable.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); } @@ -258,7 +246,7 @@ public void testTokensWithTokenStrictDisableInInsertRequestValidations() { public void testNoTokensWithTokenStrictEnableInInsertRequestValidations() { values.add(valueMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokenStrict(Byot.ENABLE) + .table(table).values(values).tokenMode(TokenMode.ENABLE) .build(); try { Validations.validateInsertRequest(request); @@ -266,7 +254,7 @@ public void testNoTokensWithTokenStrictEnableInInsertRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString()), + Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString()), e.getMessage() ); } @@ -276,7 +264,7 @@ public void testNoTokensWithTokenStrictEnableInInsertRequestValidations() { public void testNoTokensWithTokenStrictEnableStrictInInsertRequestValidations() { values.add(valueMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokenStrict(Byot.ENABLE_STRICT) + .table(table).values(values).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateInsertRequest(request); @@ -284,7 +272,7 @@ public void testNoTokensWithTokenStrictEnableStrictInInsertRequestValidations() } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString()), + Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString()), e.getMessage() ); } @@ -294,7 +282,7 @@ public void testNoTokensWithTokenStrictEnableStrictInInsertRequestValidations() public void testEmptyTokensWithTokenStrictEnableInInsertRequestValidations() { values.add(valueMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokens(tokens).tokenStrict(Byot.ENABLE) + .table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE) .build(); try { Validations.validateInsertRequest(request); @@ -310,14 +298,14 @@ public void testInsufficientTokensWithTokenStrictEnableStrictInInsertRequestVali values.add(valueMap); tokens.add(tokenMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokens(tokens).tokenStrict(Byot.ENABLE_STRICT) + .table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateInsertRequest(request); Assert.fail(EXCEPTION_NOT_THROWN); } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); - Assert.assertEquals(ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage(), e.getMessage()); + Assert.assertEquals(ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage(), e.getMessage()); } } @@ -327,14 +315,14 @@ public void testInsufficientTokensWithTokenStrictEnableStrictInInsertRequestVali values.add(valueMap); tokens.add(tokenMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokens(tokens).tokenStrict(Byot.ENABLE_STRICT) + .table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateInsertRequest(request); Assert.fail(EXCEPTION_NOT_THROWN); } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); - Assert.assertEquals(ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage(), e.getMessage()); + Assert.assertEquals(ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage(), e.getMessage()); } } @@ -344,7 +332,7 @@ public void testTokenValueMismatchInInsertRequestValidations() { tokenMap.put("test_column_3", "test_token_3"); tokens.add(tokenMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokens(tokens).tokenStrict(Byot.ENABLE_STRICT) + .table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateInsertRequest(request); @@ -361,7 +349,7 @@ public void testEmptyKeyInTokensInInsertRequestValidations() { values.add(valueMap); tokens.add(tokenMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokens(tokens).tokenStrict(Byot.ENABLE_STRICT) + .table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateInsertRequest(request); @@ -378,7 +366,7 @@ public void testEmptyValueInTokensInInsertRequestValidations() { values.add(valueMap); tokens.add(tokenMap); InsertRequest request = InsertRequest.builder() - .table(table).values(values).tokens(tokens).tokenStrict(Byot.ENABLE_STRICT) + .table(table).values(values).tokens(tokens).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateInsertRequest(request); diff --git a/src/test/java/com/skyflow/vault/data/QueryTests.java b/src/test/java/com/skyflow/vault/data/QueryTests.java index 82b8499a..a18a45cf 100644 --- a/src/test/java/com/skyflow/vault/data/QueryTests.java +++ b/src/test/java/com/skyflow/vault/data/QueryTests.java @@ -7,23 +7,16 @@ import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.Constants; import com.skyflow.utils.Utils; import com.skyflow.utils.validations.Validations; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.ArrayList; import java.util.HashMap; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class QueryTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -34,11 +27,7 @@ public class QueryTests { private static HashMap queryRecord = null; @BeforeClass - public static void setup() throws SkyflowException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); - + public static void setup() { vaultID = "vault123"; clusterID = "cluster123"; @@ -55,8 +44,6 @@ public static void setup() throws SkyflowException { queryRecord = new HashMap<>(); queryRecord.put("name", "test_name"); queryRecord.put("card_number", "test_card_number"); - -// skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build(); } @Test diff --git a/src/test/java/com/skyflow/vault/data/UpdateTests.java b/src/test/java/com/skyflow/vault/data/UpdateTests.java index d323dcee..c23977c6 100644 --- a/src/test/java/com/skyflow/vault/data/UpdateTests.java +++ b/src/test/java/com/skyflow/vault/data/UpdateTests.java @@ -3,12 +3,11 @@ import com.skyflow.Skyflow; import com.skyflow.config.Credentials; import com.skyflow.config.VaultConfig; -import com.skyflow.enums.Byot; +import com.skyflow.enums.TokenMode; import com.skyflow.enums.Env; import com.skyflow.errors.ErrorCode; import com.skyflow.errors.ErrorMessage; import com.skyflow.errors.SkyflowException; -import com.skyflow.serviceaccount.util.Token; import com.skyflow.utils.Constants; import com.skyflow.utils.Utils; import com.skyflow.utils.validations.Validations; @@ -16,15 +15,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.util.HashMap; -@RunWith(PowerMockRunner.class) -@PrepareForTest(fullyQualifiedNames = "com.skyflow.serviceaccount.util.Token") public class UpdateTests { private static final String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception"; private static final String EXCEPTION_NOT_THROWN = "Should have thrown an exception"; @@ -37,11 +30,7 @@ public class UpdateTests { private static Skyflow skyflowClient = null; @BeforeClass - public static void setup() throws SkyflowException { - PowerMockito.mockStatic(Token.class); - PowerMockito.when(Token.isExpired("valid_token")).thenReturn(true); - PowerMockito.when(Token.isExpired("not_a_valid_token")).thenReturn(false); - + public static void setup() { vaultID = "vault123"; clusterID = "cluster123"; @@ -78,7 +67,7 @@ public void testValidInputInUpdateRequestValidations() { .data(dataMap) .tokens(tokenMap) .returnTokens(true) - .tokenStrict(Byot.ENABLE) + .tokenMode(TokenMode.ENABLE) .build(); Validations.validateUpdateRequest(request); Assert.assertEquals(table, request.getTable()); @@ -243,7 +232,7 @@ public void testTokensWithTokenStrictDisableInUpdateRequestValidations() { dataMap.put("test_column_2", "test_value_2"); tokenMap.put("test_column_1", "test_token_1"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokens(tokenMap).tokenStrict(Byot.DISABLE) + .table(table).data(dataMap).tokens(tokenMap).tokenMode(TokenMode.DISABLE) .build(); try { Validations.validateUpdateRequest(request); @@ -251,7 +240,7 @@ public void testTokensWithTokenStrictDisableInUpdateRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.TokensPassedForByotDisable.getMessage(), Constants.SDK_PREFIX), + Utils.parameterizedString(ErrorMessage.TokensPassedForTokenModeDisable.getMessage(), Constants.SDK_PREFIX), e.getMessage() ); } @@ -263,7 +252,7 @@ public void testNoTokensWithTokenStrictEnableInUpdateRequestValidations() { dataMap.put("test_column_1", "test_value_1"); dataMap.put("test_column_2", "test_value_2"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokenStrict(Byot.ENABLE) + .table(table).data(dataMap).tokenMode(TokenMode.ENABLE) .build(); try { Validations.validateUpdateRequest(request); @@ -271,7 +260,7 @@ public void testNoTokensWithTokenStrictEnableInUpdateRequestValidations() { } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE.toString()), + Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE.toString()), e.getMessage() ); } @@ -283,7 +272,7 @@ public void testNoTokensWithTokenStrictEnableStrictInUpdateRequestValidations() dataMap.put("test_column_1", "test_value_1"); dataMap.put("test_column_2", "test_value_2"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokenStrict(Byot.ENABLE_STRICT) + .table(table).data(dataMap).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateUpdateRequest(request); @@ -291,7 +280,7 @@ public void testNoTokensWithTokenStrictEnableStrictInUpdateRequestValidations() } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); Assert.assertEquals( - Utils.parameterizedString(ErrorMessage.NoTokensWithByot.getMessage(), Byot.ENABLE_STRICT.toString()), + Utils.parameterizedString(ErrorMessage.NoTokensWithTokenMode.getMessage(), TokenMode.ENABLE_STRICT.toString()), e.getMessage() ); } @@ -303,7 +292,7 @@ public void testEmptyTokensWithTokenStrictEnableInUpdateRequestValidations() { dataMap.put("test_column_1", "test_value_1"); dataMap.put("test_column_2", "test_value_2"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokens(tokenMap).tokenStrict(Byot.ENABLE) + .table(table).data(dataMap).tokens(tokenMap).tokenMode(TokenMode.ENABLE) .build(); try { Validations.validateUpdateRequest(request); @@ -321,14 +310,14 @@ public void testInsufficientTokensWithTokenStrictEnableStrictInUpdateRequestVali dataMap.put("test_column_2", "test_value_2"); tokenMap.put("test_column_1", "test_token_1"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokens(tokenMap).tokenStrict(Byot.ENABLE_STRICT) + .table(table).data(dataMap).tokens(tokenMap).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateUpdateRequest(request); Assert.fail(EXCEPTION_NOT_THROWN); } catch (SkyflowException e) { Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode()); - Assert.assertEquals(ErrorMessage.InsufficientTokensPassedForByotEnableStrict.getMessage(), e.getMessage()); + Assert.assertEquals(ErrorMessage.InsufficientTokensPassedForTokenModeEnableStrict.getMessage(), e.getMessage()); } } @@ -340,7 +329,7 @@ public void testTokenValueMismatchInUpdateRequestValidations() { tokenMap.put("test_column_1", "test_token_1"); tokenMap.put("test_column_3", "test_token_3"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokens(tokenMap).tokenStrict(Byot.ENABLE_STRICT) + .table(table).data(dataMap).tokens(tokenMap).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateUpdateRequest(request); @@ -359,7 +348,7 @@ public void testEmptyKeyInTokensInUpdateRequestValidations() { tokenMap.put("test_column_1", "test_token_1"); tokenMap.put("", "test_token_2"); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokens(tokenMap).tokenStrict(Byot.ENABLE_STRICT) + .table(table).data(dataMap).tokens(tokenMap).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateUpdateRequest(request); @@ -378,7 +367,7 @@ public void testEmptyValueInTokensInUpdateRequestValidations() { tokenMap.put("test_column_1", "test_token_1"); tokenMap.put("test_column_2", ""); UpdateRequest request = UpdateRequest.builder() - .table(table).data(dataMap).tokens(tokenMap).tokenStrict(Byot.ENABLE_STRICT) + .table(table).data(dataMap).tokens(tokenMap).tokenMode(TokenMode.ENABLE_STRICT) .build(); try { Validations.validateUpdateRequest(request);