org.springframework.data.repository.core.support.DefaultRepositoryMetadata Java Examples

The following examples show how to use org.springframework.data.repository.core.support.DefaultRepositoryMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartTreeDatastoreQueryTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
private void queryWithMockResult(String queryName, List results, Method m, boolean mockOptionalNullable,
		ProjectionInformation projectionInformation) {
	when(this.queryMethod.getName()).thenReturn(queryName);
	doReturn(new DefaultParameters(m))
			.when(this.queryMethod).getParameters();
	if (mockOptionalNullable) {
		DefaultRepositoryMetadata mockMetadata = mock(DefaultRepositoryMetadata.class);
		doReturn(m.getReturnType()).when(mockMetadata).getReturnedDomainClass(m);
		DatastoreQueryMethod datastoreQueryMethod =
				new DatastoreQueryMethod(m,
						mockMetadata,
						mock(SpelAwareProxyProjectionFactory.class));
		doReturn(datastoreQueryMethod.isOptionalReturnType())
				.when(this.queryMethod).isOptionalReturnType();
		doReturn(datastoreQueryMethod.isNullable())
				.when(this.queryMethod).isNullable();
	}

	this.partTreeDatastoreQuery = createQuery(false, false, projectionInformation);
	when(this.datastoreTemplate.queryKeysOrEntities(any(), Mockito.<Class<Trade>>any()))
			.thenReturn(new DatastoreResultsIterable<>(
					results != null ? results.iterator() : Collections.emptyIterator(), null));
}
 
Example #2
Source File: AggregateQueryProvider2Test.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class})
public void testCreateAggregateQuery(String methodName) throws Exception {
  AggregateQuerySupportingRepositoryFactory factory = new AggregateQuerySupportingRepositoryFactory(mongoOperations,
                                                                                                    queryExecutor);
  QueryLookupStrategy lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider);

  Method method = TestAggregateRepository22.class.getMethod(methodName);
  RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(TestAggregateRepository22.class);
  ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
  RepositoryQuery query = lookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory, null);
  assertNotNull(query);
  Object object = query.execute(new Object[0]);
  assertNull(object);
}
 
Example #3
Source File: ReactiveAggregateQueryProviderTest.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class})
public void testCreateAggregateQuery(String methodName) throws Exception {
  ReactiveAggregateQuerySupportingRepositoryFactory factory = new ReactiveAggregateQuerySupportingRepositoryFactory(mongoOperations,
                                                                                                                    queryExecutor);
  Optional<QueryLookupStrategy> lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider);

  Assert.isTrue(lookupStrategy.isPresent(), "Lookup strategy must not be null");
  Method method = ReactiveTestAggregateRepository22.class.getMethod(methodName);
  RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(ReactiveTestAggregateRepository22.class);
  ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
  RepositoryQuery query = lookupStrategy.get().resolveQuery(method, repositoryMetadata, projectionFactory, null);
  assertNotNull(query);
  Object object = query.execute(new Object[0]);
  assertNull(object);
}
 
Example #4
Source File: AggregateQueryProvider2Test.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class})
public void testCreateAggregateQuery(String methodName) throws Exception {
  NonReactiveAggregateQuerySupportingRepositoryFactory factory =
      new NonReactiveAggregateQuerySupportingRepositoryFactory(mongoOperations, queryExecutor);
  Optional<QueryLookupStrategy> lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider);
  assertTrue(lookupStrategy.isPresent(), "Expecting non null lookupStrategy");
  Method method = TestAggregateRepository22.class.getMethod(methodName);
  RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(TestAggregateRepository22.class);
  ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
  RepositoryQuery query = lookupStrategy.get().resolveQuery(method, repositoryMetadata, projectionFactory, null);
  assertNotNull(query);
  Object object = query.execute(new Object[0]);
  assertNull(object);
}
 
Example #5
Source File: AbstractSpringAuditableRepositoryAspect.java    From javers with Apache License 2.0 5 votes vote down vote up
protected void onDelete(JoinPoint pjp) {
    getRepositoryInterface(pjp).ifPresent( i -> {
        RepositoryMetadata metadata = DefaultRepositoryMetadata.getMetadata(i);
        for (Object deletedObject : AspectUtil.collectArguments(pjp)) {
            handleDelete(metadata, deletedObject);
        }
    });
}