This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid identifier of SQL parameters, fix #221.
* For nested query with DocumentQuery, replace user.name to user_name. Signed-off-by: Pan Li <[email protected]>
- Loading branch information
1 parent
e684b63
commit eb8dfdc
Showing
4 changed files
with
146 additions
and
6 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
31 changes: 31 additions & 0 deletions
31
src/test/java/com/microsoft/azure/spring/data/cosmosdb/domain/Customer.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,31 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
package com.microsoft.azure.spring.data.cosmosdb.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class Customer { | ||
|
||
@Id | ||
private String id; | ||
|
||
private Long level; | ||
|
||
private User user; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public static class User { | ||
|
||
private String name; | ||
|
||
private Long age; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...com/microsoft/azure/spring/data/cosmosdb/repository/integration/CustomerRepositoryIT.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,85 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
package com.microsoft.azure.spring.data.cosmosdb.repository.integration; | ||
|
||
import com.microsoft.azure.spring.data.cosmosdb.domain.Customer; | ||
import com.microsoft.azure.spring.data.cosmosdb.repository.TestRepositoryConfig; | ||
import com.microsoft.azure.spring.data.cosmosdb.repository.repository.CustomerRepository; | ||
import lombok.NonNull; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
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.Comparator; | ||
import java.util.List; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = TestRepositoryConfig.class) | ||
public class CustomerRepositoryIT { | ||
|
||
private static final String USER_NAME_0 = "username-0"; | ||
private static final String USER_NAME_1 = "username-1"; | ||
private static final String FAKE_USER_NAME = "username-fake"; | ||
|
||
private static final Long USER_AGE_0 = 34L; | ||
private static final Long USER_AGE_1 = 45L; | ||
|
||
private static final String CUSTOMER_ID_0 = "id-0"; | ||
private static final String CUSTOMER_ID_1 = "id-1"; | ||
private static final String CUSTOMER_ID_2 = "id-2"; | ||
|
||
private static final Long CUSTOMER_LEVEL_0 = 1L; | ||
private static final Long CUSTOMER_LEVEL_1 = 2L; | ||
|
||
private static final Customer.User USER_0 = new Customer.User(USER_NAME_0, USER_AGE_0); | ||
private static final Customer.User USER_1 = new Customer.User(USER_NAME_1, USER_AGE_1); | ||
private static final Customer.User USER_2 = new Customer.User(USER_NAME_0, USER_AGE_1); | ||
|
||
private static final Customer CUSTOMER_0 = new Customer(CUSTOMER_ID_0, CUSTOMER_LEVEL_0, USER_0); | ||
private static final Customer CUSTOMER_1 = new Customer(CUSTOMER_ID_1, CUSTOMER_LEVEL_1, USER_1); | ||
private static final Customer CUSTOMER_2 = new Customer(CUSTOMER_ID_2, CUSTOMER_LEVEL_1, USER_2); | ||
|
||
@Autowired | ||
private CustomerRepository repository; | ||
|
||
@Before | ||
public void setup() { | ||
this.repository.saveAll(Arrays.asList(CUSTOMER_0, CUSTOMER_1, CUSTOMER_2)); | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
this.repository.deleteAll(); | ||
} | ||
|
||
private void assertCustomerListEquals(@NonNull List<Customer> customers, @NonNull List<Customer> reference) { | ||
Assert.assertEquals(customers.size(), reference.size()); | ||
|
||
customers.sort(Comparator.comparing(Customer::getId)); | ||
reference.sort(Comparator.comparing(Customer::getId)); | ||
|
||
Assert.assertEquals(customers, reference); | ||
} | ||
|
||
@Test | ||
public void testFindByUserAndLevel() { | ||
final List<Customer> references = Arrays.asList(CUSTOMER_0, CUSTOMER_2); | ||
List<Customer> customers = this.repository.findByUser_Name(USER_NAME_0); | ||
|
||
assertCustomerListEquals(references, customers); | ||
|
||
customers = this.repository.findByUser_Name(FAKE_USER_NAME); | ||
|
||
Assert.assertTrue(customers.isEmpty()); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...va/com/microsoft/azure/spring/data/cosmosdb/repository/repository/CustomerRepository.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,15 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for | ||
* license information. | ||
*/ | ||
package com.microsoft.azure.spring.data.cosmosdb.repository.repository; | ||
|
||
import com.microsoft.azure.spring.data.cosmosdb.domain.Customer; | ||
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface CustomerRepository extends DocumentDbRepository<Customer, String> { | ||
List<Customer> findByUser_Name(String name); | ||
} |