Skip to content

Commit 18a60d9

Browse files
Fixed project.version conflict in spring data cosmos (Azure#27311)
* Fixed project.version conflict in spring data cosmos * Added integration tests * Updated project properties file name
1 parent 3c7b514 commit 18a60d9

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/CosmosTemplateIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import com.azure.cosmos.models.PartitionKey;
1212
import com.azure.cosmos.models.SqlQuerySpec;
1313
import com.azure.cosmos.models.ThroughputResponse;
14+
import com.azure.spring.data.cosmos.Constants;
1415
import com.azure.spring.data.cosmos.CosmosFactory;
1516
import com.azure.spring.data.cosmos.IntegrationTestCollectionManager;
1617
import com.azure.spring.data.cosmos.common.PageTestUtils;
18+
import com.azure.spring.data.cosmos.common.PropertyLoader;
1719
import com.azure.spring.data.cosmos.common.ResponseDiagnosticsTestUtils;
1820
import com.azure.spring.data.cosmos.common.TestConstants;
1921
import com.azure.spring.data.cosmos.common.TestUtils;
@@ -50,6 +52,8 @@
5052
import org.springframework.test.context.ContextConfiguration;
5153
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
5254

55+
import java.lang.reflect.InvocationTargetException;
56+
import java.lang.reflect.Method;
5357
import java.util.Arrays;
5458
import java.util.Collections;
5559
import java.util.List;
@@ -704,6 +708,16 @@ public void createDatabaseWithThroughput() throws ClassNotFoundException {
704708
assertEquals(expectedRequestUnits, response.getProperties().getManualThroughput());
705709
}
706710

711+
@Test
712+
public void userAgentSpringDataCosmosSuffix() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
713+
// getUserAgentSuffix method from CosmosClientBuilder
714+
Method getUserAgentSuffix = CosmosClientBuilder.class.getDeclaredMethod("getUserAgentSuffix");
715+
getUserAgentSuffix.setAccessible(true);
716+
String userAgentSuffix = (String) getUserAgentSuffix.invoke(cosmosClientBuilder);
717+
assertThat(userAgentSuffix).contains(Constants.USER_AGENT_SUFFIX);
718+
assertThat(userAgentSuffix).contains(PropertyLoader.getProjectVersion());
719+
}
720+
707721
private void deleteDatabaseIfExists(String dbName) {
708722
CosmosAsyncDatabase database = client.getDatabase(dbName);
709723
try {

sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/core/ReactiveCosmosTemplateIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import com.azure.cosmos.models.PartitionKey;
1313
import com.azure.cosmos.models.SqlQuerySpec;
1414
import com.azure.cosmos.models.ThroughputResponse;
15+
import com.azure.spring.data.cosmos.Constants;
1516
import com.azure.spring.data.cosmos.CosmosFactory;
1617
import com.azure.spring.data.cosmos.ReactiveIntegrationTestCollectionManager;
18+
import com.azure.spring.data.cosmos.common.PropertyLoader;
1719
import com.azure.spring.data.cosmos.common.ResponseDiagnosticsTestUtils;
1820
import com.azure.spring.data.cosmos.common.TestConstants;
1921
import com.azure.spring.data.cosmos.config.CosmosConfig;
@@ -50,6 +52,8 @@
5052
import reactor.core.publisher.Mono;
5153
import reactor.test.StepVerifier;
5254

55+
import java.lang.reflect.InvocationTargetException;
56+
import java.lang.reflect.Method;
5357
import java.util.ArrayList;
5458
import java.util.Arrays;
5559
import java.util.Collections;
@@ -570,6 +574,16 @@ public void createDatabaseWithThroughput() throws ClassNotFoundException {
570574
assertEquals(expectedRequestUnits, response.getProperties().getManualThroughput());
571575
}
572576

577+
@Test
578+
public void userAgentSpringDataCosmosSuffix() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
579+
// getUserAgentSuffix method from CosmosClientBuilder
580+
Method getUserAgentSuffix = CosmosClientBuilder.class.getDeclaredMethod("getUserAgentSuffix");
581+
getUserAgentSuffix.setAccessible(true);
582+
String userAgentSuffix = (String) getUserAgentSuffix.invoke(cosmosClientBuilder);
583+
assertThat(userAgentSuffix).contains(Constants.USER_AGENT_SUFFIX);
584+
assertThat(userAgentSuffix).contains(PropertyLoader.getProjectVersion());
585+
}
586+
573587
private void deleteDatabaseIfExists(String dbName) {
574588
CosmosAsyncDatabase database = client.getDatabase(dbName);
575589
try {

sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/common/PropertyLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public final class PropertyLoader {
1515

16-
private static final String PROJECT_PROPERTY_FILE = "/META-INF/project.properties";
16+
private static final String PROJECT_PROPERTY_FILE = "/META-INF/azure-spring-data-cosmos.properties";
1717

1818
private static final String APPLICATION_PROPERTY_FILE = "/application.properties";
1919

@@ -23,7 +23,7 @@ private PropertyLoader() {
2323
}
2424

2525
/**
26-
* Get project version from /META-INF/project.properties
26+
* Get project version from /META-INF/azure-spring-data-cosmos.properties
2727
*
2828
* @return String project version
2929
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.spring.data.cosmos.core;
5+
6+
import com.azure.cosmos.CosmosClientBuilder;
7+
import com.azure.spring.data.cosmos.Constants;
8+
import com.azure.spring.data.cosmos.CosmosFactory;
9+
import com.azure.spring.data.cosmos.common.PropertyLoader;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
import org.mockito.junit.MockitoJUnitRunner;
13+
14+
import java.lang.reflect.InvocationTargetException;
15+
import java.lang.reflect.Method;
16+
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
19+
@RunWith(MockitoJUnitRunner.class)
20+
public class CosmosFactoryUnitTest {
21+
22+
@Test
23+
public void userAgentSpringDataCosmosSuffix() {
24+
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder();
25+
try {
26+
Method updateCosmosClientBuilderWithUASuffix = CosmosFactory.class.getDeclaredMethod(
27+
"updateCosmosClientBuilderWithUASuffix", CosmosClientBuilder.class);
28+
29+
// static method invoke call
30+
updateCosmosClientBuilderWithUASuffix.setAccessible(true);
31+
updateCosmosClientBuilderWithUASuffix.invoke(null, cosmosClientBuilder);
32+
33+
// getUserAgentSuffix method from CosmosClientBuilder
34+
Method getUserAgentSuffix = CosmosClientBuilder.class.getDeclaredMethod("getUserAgentSuffix");
35+
getUserAgentSuffix.setAccessible(true);
36+
String userAgentSuffix = (String) getUserAgentSuffix.invoke(cosmosClientBuilder);
37+
assertThat(userAgentSuffix).contains(Constants.USER_AGENT_SUFFIX);
38+
assertThat(userAgentSuffix).contains(PropertyLoader.getProjectVersion());
39+
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
40+
e.printStackTrace();
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)