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

The following examples show how to use org.springframework.data.repository.core.support.DefaultRepositoryMetadata. These examples are extracted from open source projects. 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
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
@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
@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
@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
protected void onDelete(JoinPoint pjp) {
    getRepositoryInterface(pjp).ifPresent( i -> {
        RepositoryMetadata metadata = DefaultRepositoryMetadata.getMetadata(i);
        for (Object deletedObject : AspectUtil.collectArguments(pjp)) {
            handleDelete(metadata, deletedObject);
        }
    });
}