From d6d87f55afc9bb887b032c09d99494b2a9bae922 Mon Sep 17 00:00:00 2001 From: Alex Iudice Date: Fri, 6 Jan 2023 12:32:46 -0500 Subject: [PATCH] Adds check and message to SdkTestBase for required maven test properties. --- .../java/com/graphgrid/sdk/SdkTestBase.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/graphgrid-sdk-java-tests/src/test/java/com/graphgrid/sdk/SdkTestBase.java b/graphgrid-sdk-java-tests/src/test/java/com/graphgrid/sdk/SdkTestBase.java index f02ab98..70b4f6a 100644 --- a/graphgrid-sdk-java-tests/src/test/java/com/graphgrid/sdk/SdkTestBase.java +++ b/graphgrid-sdk-java-tests/src/test/java/com/graphgrid/sdk/SdkTestBase.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.Properties; +import com.graphgrid.sdk.core.exception.GraphGridSdkInvalidArgumentException; import com.graphgrid.sdk.core.security.SecurityConfig; /** @@ -32,6 +33,8 @@ public abstract class SdkTestBase protected String username; protected String password; + private Properties p = new Properties(); + @Before public void setUp() { @@ -42,7 +45,6 @@ public void setUp() private void loadSecurityCredentialsFromPom() { java.io.InputStream is = this.getClass().getClassLoader().getResourceAsStream( "test.properties" ); - java.util.Properties p = new Properties(); try { p.load( is ); @@ -57,11 +59,28 @@ private void loadSecurityCredentialsFromPom() return; } - securityConfig.setClientId( p.getProperty( "client.id" ) ); - securityConfig.setClientSecret( p.getProperty( "client.secret" ) ); - securityConfig.setBaseSecurityUrl( p.getProperty( "baseSecurityUrl" ) ); + final String clientId = getPropertyValueAndThrowErrorIfMissing( "client.id" ); + final String clientSecret = getPropertyValueAndThrowErrorIfMissing( "client.secret" ); + final String baseSecurityUrl = getPropertyValueAndThrowErrorIfMissing( "baseSecurityUrl" ); + final String oauthUsername = getPropertyValueAndThrowErrorIfMissing( "oauth.username" ); + final String oauthPassword = getPropertyValueAndThrowErrorIfMissing( "oauth.password" ); + + securityConfig.setClientId( clientId ); + securityConfig.setClientSecret( clientSecret ); + securityConfig.setBaseSecurityUrl( baseSecurityUrl ); + + username = oauthUsername; + password = oauthPassword; + } - username = p.getProperty( "oauth.username" ); - password = p.getProperty( "oauth.password" ); + private String getPropertyValueAndThrowErrorIfMissing( String propName ) throws GraphGridSdkInvalidArgumentException + { + String propValue = p.getProperty( propName ); + if ( propValue == null || propValue.isEmpty() ) + { + throw new GraphGridSdkInvalidArgumentException( "Property '" + propName + "' is missing or empty. " + + "Graphgrid-java-sdk tests require this property to be non-empty (set directly in the test pom or through the properties in your maven settings.xml)" ); + } + return propValue; } }