-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Otavio Santana <[email protected]>
- Loading branch information
1 parent
430e6a5
commit 86729b5
Showing
4 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...core/src/test/java/org/eclipse/jnosql/mapping/core/query/AbstractRepositoryProxyTest.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,104 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.mapping.core.query; | ||
|
||
import jakarta.nosql.MappingException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.reflect.Method; | ||
import jakarta.enterprise.inject.spi.CDI; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class AbstractRepositoryProxyTest { | ||
|
||
private final TestRepositoryProxy proxy = new TestRepositoryProxy(); | ||
|
||
@Test | ||
void shouldInvokeExecuteFindByQuery() throws Throwable { | ||
Method method = TestRepository.class.getMethod("findEntityById", UUID.class); | ||
Object result = proxy.invoke(proxy, method, new Object[]{UUID.randomUUID()}); | ||
|
||
assertEquals("executeFindByQuery", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteDeleteById() throws Throwable { | ||
Method method = TestRepository.class.getMethod("deleteById"); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
|
||
assertEquals("executeDeleteByAll", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteCountById() throws Throwable { | ||
Method method = TestRepository.class.getMethod("countBy"); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
assertEquals("executeCountByQuery", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteExistById() throws Throwable { | ||
Method method = TestRepository.class.getMethod("existsBy"); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
assertEquals("executeExistByQuery", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteFindAll() throws Throwable { | ||
Method method = TestRepository.class.getMethod("findAll"); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
assertEquals("executeFindAll", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteQuery() throws Throwable { | ||
Method method = TestRepository.class.getMethod("query", int.class); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
assertEquals("executeQuery", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteCursor() throws Throwable { | ||
Method method = TestRepository.class.getMethod("cursor"); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
assertEquals("executeCursorPagination", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeExecuteFind() throws Throwable { | ||
Method method = TestRepository.class.getMethod("find"); | ||
Object result = proxy.invoke(proxy, method, new Object[]{}); | ||
assertEquals("executeParameterBased", result); | ||
} | ||
|
||
@Test | ||
void shouldInvokeThrowsMappingException() throws Throwable { | ||
Method method = TestRepository.class.getMethod("customMethod"); | ||
|
||
assertThrows(UnsupportedOperationException.class, () -> { | ||
proxy.invoke(proxy, method, new Object[]{}); | ||
}); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...g/jnosql-mapping-core/src/test/java/org/eclipse/jnosql/mapping/core/query/TestEntity.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,44 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.mapping.core.query; | ||
|
||
import java.util.UUID; | ||
|
||
public class TestEntity { | ||
|
||
private UUID id; | ||
private String name; | ||
|
||
public TestEntity(UUID id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public UUID getId() { | ||
return id; | ||
} | ||
|
||
public void setId(UUID id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...osql-mapping-core/src/test/java/org/eclipse/jnosql/mapping/core/query/TestRepository.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,40 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.mapping.core.query; | ||
|
||
import jakarta.data.page.CursoredPage; | ||
import jakarta.data.repository.Find; | ||
import jakarta.data.repository.Query; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public interface TestRepository { | ||
|
||
void customMethod(); | ||
TestEntity findEntityById(UUID id); | ||
void deleteById(); | ||
long countBy(); | ||
boolean existsBy(); | ||
List<TestEntity> findAll(); | ||
|
||
@Query("") | ||
List<TestEntity> query(int age); | ||
|
||
CursoredPage<TestEntity> cursor(); | ||
|
||
@Find | ||
List<TestEntity> find(); | ||
} |
79 changes: 79 additions & 0 deletions
79
...mapping-core/src/test/java/org/eclipse/jnosql/mapping/core/query/TestRepositoryProxy.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,79 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
* | ||
* Contributors: | ||
* | ||
* Otavio Santana | ||
*/ | ||
package org.eclipse.jnosql.mapping.core.query; | ||
|
||
import org.eclipse.jnosql.mapping.metadata.EntityMetadata; | ||
import org.mockito.Mockito; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.UUID; | ||
|
||
public class TestRepositoryProxy extends AbstractRepositoryProxy<TestEntity, UUID> { | ||
|
||
@Override | ||
protected AbstractRepository<TestEntity, UUID> repository() { | ||
return Mockito.mock(AbstractRepository.class); | ||
} | ||
|
||
@Override | ||
protected Class<?> repositoryType() { | ||
return TestRepository.class; | ||
} | ||
|
||
@Override | ||
protected EntityMetadata entityMetadata() { | ||
return Mockito.mock(EntityMetadata.class); | ||
} | ||
|
||
@Override | ||
protected Object executeQuery(Object instance, Method method, Object[] params) { | ||
return "executeQuery"; | ||
} | ||
|
||
@Override | ||
protected Object executeDeleteByAll(Object instance, Method method, Object[] params) { | ||
return "executeDeleteByAll"; | ||
} | ||
|
||
@Override | ||
protected Object executeFindAll(Object instance, Method method, Object[] params) { | ||
return "executeFindAll"; | ||
} | ||
|
||
@Override | ||
protected Object executeExistByQuery(Object instance, Method method, Object[] params) { | ||
return "executeExistByQuery"; | ||
} | ||
|
||
@Override | ||
protected Object executeCountByQuery(Object instance, Method method, Object[] params) { | ||
return "executeCountByQuery"; | ||
} | ||
|
||
@Override | ||
protected Object executeFindByQuery(Object instance, Method method, Object[] params) { | ||
return "executeFindByQuery"; | ||
} | ||
|
||
@Override | ||
protected Object executeCursorPagination(Object instance, Method method, Object[] params) { | ||
return "executeCursorPagination"; | ||
} | ||
|
||
@Override | ||
protected Object executeParameterBased(Object instance, Method method, Object[] params) { | ||
return "executeParameterBased"; | ||
} | ||
} |