forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a fix to pick the annotated container name for annotated queri…
…es (Azure#15924) * Adding a fix to pick the annotated container name for the user types while running annotated queries. Renaming RoleRepository to ReactiveRoleRepository appropriately Adding a new RoleRepository for test Adding tests to test the fix for both reactive and synchronous repositories. * Reafactoring RoleRepository to BookRepository to avoid flaky IT.
- Loading branch information
Showing
9 changed files
with
255 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/domain/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.data.cosmos.domain; | ||
|
||
import com.azure.spring.data.cosmos.common.TestConstants; | ||
import com.azure.spring.data.cosmos.core.mapping.Container; | ||
import com.azure.spring.data.cosmos.core.mapping.PartitionKey; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@Container(containerName = TestConstants.BOOK_COLLECTION_NAME, | ||
autoCreateContainer = false) | ||
public class Book { | ||
@Id | ||
String id; | ||
|
||
@PartitionKey | ||
String authorId; | ||
|
||
String title; | ||
|
||
public Book() { | ||
|
||
} | ||
|
||
public Book(String id, String authorId, String title) { | ||
this.id = id; | ||
this.authorId = authorId; | ||
this.title = title; | ||
} | ||
|
||
/** | ||
* Getter for property 'id'. | ||
* | ||
* @return Value for property 'id'. | ||
*/ | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Setter for property 'id'. | ||
* | ||
* @param id Value to set for property 'id'. | ||
*/ | ||
public void setId(final String id) { | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Getter for property 'authorId'. | ||
* | ||
* @return Value for property 'authorId'. | ||
*/ | ||
public String getAuthorId() { | ||
return authorId; | ||
} | ||
|
||
/** | ||
* Setter for property 'authorId'. | ||
* | ||
* @param authorId Value to set for property 'authorId'. | ||
*/ | ||
public void setAuthorId(final String authorId) { | ||
this.authorId = authorId; | ||
} | ||
|
||
/** | ||
* Getter for property 'title'. | ||
* | ||
* @return Value for property 'title'. | ||
*/ | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
/** | ||
* Setter for property 'title'. | ||
* | ||
* @param title Value to set for property 'title'. | ||
*/ | ||
public void setTitle(final String title) { | ||
this.title = title; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...t/src/test/java/com/azure/spring/data/cosmos/repository/integration/BookRepositoryIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.data.cosmos.repository.integration; | ||
|
||
import com.azure.spring.data.cosmos.common.TestConstants; | ||
import com.azure.spring.data.cosmos.core.CosmosTemplate; | ||
import com.azure.spring.data.cosmos.domain.Book; | ||
import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; | ||
import com.azure.spring.data.cosmos.repository.repository.BookRepository; | ||
import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = TestRepositoryConfig.class) | ||
public class BookRepositoryIT { | ||
|
||
private static final Book TEST_BOOK_1 = new Book(TestConstants.ID_1, UUID.randomUUID().toString(), | ||
"title1"); | ||
private static final Book TEST_BOOK_2 = new Book(TestConstants.ID_2, UUID.randomUUID().toString(), | ||
"title2"); | ||
|
||
private static final CosmosEntityInformation<Book, String> entityInformation = | ||
new CosmosEntityInformation<>(Book.class); | ||
|
||
private static CosmosTemplate staticTemplate; | ||
private static boolean isSetupDone; | ||
|
||
@Autowired | ||
private CosmosTemplate template; | ||
|
||
@Autowired | ||
private BookRepository repository; | ||
|
||
@AfterClass | ||
public static void afterClassCleanup() { | ||
staticTemplate.deleteContainer(entityInformation.getContainerName()); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
if (!isSetupDone) { | ||
staticTemplate = template; | ||
template.createContainerIfNotExists(entityInformation); | ||
} | ||
repository.saveAll(Arrays.asList(TEST_BOOK_1, TEST_BOOK_2)); | ||
isSetupDone = true; | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
repository.deleteAll(); | ||
} | ||
|
||
@Test | ||
public void testAnnotatedQuery() { | ||
final List<Book> result = repository.annotatedFindBookById(TEST_BOOK_1.getId()); | ||
assertThat(result).isNotNull(); | ||
assertThat(result.size()).isEqualTo(1); | ||
assertThat(result.get(0).getId()).isEqualTo(TEST_BOOK_1.getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...st/java/com/azure/spring/data/cosmos/repository/integration/ReactiveRoleRepositoryIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.data.cosmos.repository.integration; | ||
|
||
import com.azure.spring.data.cosmos.common.TestConstants; | ||
import com.azure.spring.data.cosmos.core.CosmosTemplate; | ||
import com.azure.spring.data.cosmos.domain.Role; | ||
import com.azure.spring.data.cosmos.repository.TestRepositoryConfig; | ||
import com.azure.spring.data.cosmos.repository.repository.ReactiveRoleRepository; | ||
import com.azure.spring.data.cosmos.repository.support.CosmosEntityInformation; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
import java.util.Arrays; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = TestRepositoryConfig.class) | ||
public class ReactiveRoleRepositoryIT { | ||
|
||
private static final Role TEST_ROLE_1 = new Role(TestConstants.ID_1, true, TestConstants.LEVEL, | ||
TestConstants.ROLE_NAME); | ||
private static final Role TEST_ROLE_2 = new Role(TestConstants.ID_2, false, TestConstants.LEVEL, | ||
TestConstants.ROLE_NAME); | ||
|
||
private static final CosmosEntityInformation<Role, String> entityInformation = | ||
new CosmosEntityInformation<>(Role.class); | ||
private static CosmosTemplate staticTemplate; | ||
private static boolean isSetupDone; | ||
@Autowired | ||
private CosmosTemplate template; | ||
@Autowired | ||
private ReactiveRoleRepository repository; | ||
|
||
@AfterClass | ||
public static void afterClassCleanup() { | ||
staticTemplate.deleteContainer(entityInformation.getContainerName()); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
if (!isSetupDone) { | ||
staticTemplate = template; | ||
template.createContainerIfNotExists(entityInformation); | ||
} | ||
final Flux<Role> savedFlux = repository.saveAll(Arrays.asList(TEST_ROLE_1, TEST_ROLE_2)); | ||
StepVerifier.create(savedFlux).thenConsumeWhile(role -> true).expectComplete().verify(); | ||
isSetupDone = true; | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
final Mono<Void> deletedMono = repository.deleteAll(); | ||
StepVerifier.create(deletedMono).thenAwait().verifyComplete(); | ||
} | ||
|
||
@Test | ||
public void testAnnotatedQuery() { | ||
Flux<Role> roleFlux = repository.annotatedFindRoleById(TestConstants.ID_1); | ||
StepVerifier.create(roleFlux).expectNext(TEST_ROLE_1).verifyComplete(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...test/src/test/java/com/azure/spring/data/cosmos/repository/repository/BookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.spring.data.cosmos.repository.repository; | ||
|
||
import com.azure.spring.data.cosmos.domain.Book; | ||
import com.azure.spring.data.cosmos.repository.CosmosRepository; | ||
import com.azure.spring.data.cosmos.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface BookRepository extends CosmosRepository<Book, String> { | ||
|
||
@Query(value = "select * from c where c.id = @id") | ||
List<Book> annotatedFindBookById(@Param("id") String id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters