Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kelly Domico
OS Core Lib Azure
Commits
28f9dfd7
Commit
28f9dfd7
authored
Sep 01, 2020
by
Aman Verma
Committed by
Hema Vishnu Pola [Microsoft]
Sep 01, 2020
Browse files
BugFix: moving client creation logic out of constructor
parent
0bafa9e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
28f9dfd7
...
...
@@ -21,7 +21,7 @@
<groupId>
org.opengroup.osdu
</groupId>
<artifactId>
core-lib-azure
</artifactId>
<packaging>
jar
</packaging>
<version>
0.0.2
2
</version>
<version>
0.0.2
3
</version>
<name>
core-lib-azure
</name>
<properties>
...
...
src/main/java/org/opengroup/osdu/azure/blobstorage/BlobServiceClientFactoryImpl.java
View file @
28f9dfd7
...
...
@@ -20,28 +20,26 @@ import com.azure.storage.blob.BlobServiceClientBuilder;
import
org.opengroup.osdu.azure.di.BlobStoreConfiguration
;
import
org.opengroup.osdu.common.Validators
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
context.annotation.Lazy
;
import
org.springframework.
stereotype.Component
;
/**
* Implementation for IBlobServiceClientFactory.
*/
@Component
public
class
BlobServiceClientFactoryImpl
implements
IBlobServiceClientFactory
{
@Autowired
private
DefaultAzureCredential
defaultAzureCredential
;
@Autowired
@Lazy
private
BlobStoreConfiguration
blobStoreConfiguration
;
private
BlobServiceClient
blobServiceClient
;
/**
* Parameter-less constructor.
* This initializes the blobServiceClient.
* Constructor to initialize blobServiceClient.
* @param defaultAzureCredential Default azure credentials.
* @param blobStoreConfiguration Configuration details for blob storage.
*/
public
BlobServiceClientFactoryImpl
()
{
Validators
.
checkNotNull
(
defaultAzureCredential
,
"Credential cannot be null"
);
@Autowired
public
BlobServiceClientFactoryImpl
(
final
DefaultAzureCredential
defaultAzureCredential
,
final
BlobStoreConfiguration
blobStoreConfiguration
)
{
Validators
.
checkNotNull
(
defaultAzureCredential
,
"Default credentials"
);
Validators
.
checkNotNullAndNotEmpty
(
blobStoreConfiguration
.
getStorageAccountName
(),
"Storage account name cannot be null"
);
String
endpoint
=
String
.
format
(
"https://%s.blob.core.windows.net"
,
blobStoreConfiguration
.
getStorageAccountName
());
...
...
src/test/java/org/opengroup/osdu/azure/blobstorage/BlobServiceClientFactoryImplTest.java
0 → 100644
View file @
28f9dfd7
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.azure.blobstorage
;
import
com.azure.identity.DefaultAzureCredential
;
import
com.azure.storage.blob.BlobServiceClient
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.opengroup.osdu.azure.di.BlobStoreConfiguration
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
fail
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
lenient
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
@ExtendWith
(
MockitoExtension
.
class
)
public
class
BlobServiceClientFactoryImplTest
{
@Mock
DefaultAzureCredential
credential
;
@Mock
BlobStoreConfiguration
configuration
;
BlobServiceClientFactoryImpl
clientFactory
;
private
static
final
String
ACCOUNT_NAME
=
"testAccount"
;
private
static
final
String
PARTITION_ID
=
"dataPartitionId"
;
@BeforeEach
void
init
()
{
initMocks
(
this
);
lenient
().
doReturn
(
ACCOUNT_NAME
).
when
(
configuration
).
getStorageAccountName
();
}
@Test
public
void
ConstructorThrowsException_IfDefaultAzureCredentialIsNull
()
{
try
{
clientFactory
=
new
BlobServiceClientFactoryImpl
(
null
,
configuration
);
}
catch
(
NullPointerException
ex
)
{
assertEquals
(
"Default credentials cannot be null!"
,
ex
.
getMessage
());
}
catch
(
Exception
ex
)
{
fail
(
"Should not get any other exception. Received "
+
ex
.
getClass
());
}
}
@Test
public
void
ConstructorThrowsException_IfBlobStoreConfigurationIsNull
()
{
doReturn
(
""
).
when
(
configuration
).
getStorageAccountName
();
try
{
clientFactory
=
new
BlobServiceClientFactoryImpl
(
credential
,
configuration
);
}
catch
(
IllegalArgumentException
ex
)
{
assertEquals
(
"Storage account name cannot be null cannot be empty!"
,
ex
.
getMessage
());
}
catch
(
Exception
ex
)
{
fail
(
"Should not get any other exception. Received "
+
ex
.
getClass
());
}
}
@Test
public
void
testGetBlobServiceClient_Success
()
{
try
{
clientFactory
=
new
BlobServiceClientFactoryImpl
(
credential
,
configuration
);
BlobServiceClient
client
=
clientFactory
.
getBlobServiceClient
(
PARTITION_ID
);
assertEquals
(
ACCOUNT_NAME
,
client
.
getAccountName
());
}
catch
(
Exception
ex
)
{
fail
(
"Should not fail."
);
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment