@Test void testFindResources() { String query = "text"; Package package0 = mock(Package.class); when(package0.getId()).thenReturn("p0"); when(package0.getLabel()).thenReturn("package0"); Stream<Package> packages = Stream.of(package0); @SuppressWarnings("unchecked") Query<Package> packageQuery = mock(Query.class); doReturn(packageQuery).when(packageQuery).search(PackageMetadata.LABEL, query); doReturn(packageQuery).when(packageQuery).or(); doReturn(packageQuery).when(packageQuery).search(PackageMetadata.DESCRIPTION, query); when(packageQuery.findAll()).thenReturn(packages); doReturn(packageQuery).when(dataService).query(PACKAGE, Package.class); EntityType entityType0 = mock(EntityType.class); when(entityType0.getId()).thenReturn("e0"); when(entityType0.getLabel()).thenReturn("entityType0"); Stream<EntityType> entityTypes = Stream.of(entityType0); @SuppressWarnings("unchecked") Query<EntityType> entityTypeQuery = mock(Query.class); doReturn(entityTypeQuery).when(entityTypeQuery).search(EntityTypeMetadata.LABEL, query); doReturn(entityTypeQuery).when(entityTypeQuery).or(); doReturn(entityTypeQuery).when(entityTypeQuery).search(EntityTypeMetadata.DESCRIPTION, query); when(entityTypeQuery.findAll()).thenReturn(entityTypes); doReturn(entityTypeQuery).when(dataService).query(ENTITY_TYPE_META_DATA, EntityType.class); List<Resource> expectedResources = asList( Resource.builder() .setType(ResourceType.PACKAGE) .setId("p0") .setLabel("package0") .build(), Resource.builder() .setType(ResourceType.ENTITY_TYPE) .setId("e0") .setLabel("entityType0") .build()); assertEquals(expectedResources, navigatorServiceImpl.findResources(query)); }
@Transactional(readOnly = true) @Override public List<Resource> findResources(String query) { Stream<Resource> packageResources = dataService .query(PackageMetadata.PACKAGE, Package.class) .search(PackageMetadata.LABEL, query) .or() .search(PackageMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); Stream<Resource> entityTypeResources = dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .search(EntityTypeMetadata.LABEL, query) .or() .search(EntityTypeMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); return Streams.concat(packageResources, entityTypeResources).collect(toList()); }
NavigatorServiceImpl implements NavigatorService { @Transactional(readOnly = true) @Override public List<Resource> findResources(String query) { Stream<Resource> packageResources = dataService .query(PackageMetadata.PACKAGE, Package.class) .search(PackageMetadata.LABEL, query) .or() .search(PackageMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); Stream<Resource> entityTypeResources = dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .search(EntityTypeMetadata.LABEL, query) .or() .search(EntityTypeMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); return Streams.concat(packageResources, entityTypeResources).collect(toList()); } }
NavigatorServiceImpl implements NavigatorService { @Transactional(readOnly = true) @Override public List<Resource> findResources(String query) { Stream<Resource> packageResources = dataService .query(PackageMetadata.PACKAGE, Package.class) .search(PackageMetadata.LABEL, query) .or() .search(PackageMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); Stream<Resource> entityTypeResources = dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .search(EntityTypeMetadata.LABEL, query) .or() .search(EntityTypeMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); return Streams.concat(packageResources, entityTypeResources).collect(toList()); } NavigatorServiceImpl(
      DataService dataService,
      JobExecutor jobExecutor,
      ResourceDownloadJobExecutionFactory downloadJobExecutionFactory,
      ResourceCopyJobExecutionFactory copyJobExecutionFactory,
      ResourceDeleteJobExecutionFactory resourceDeleteJobExecutionFactory); }
NavigatorServiceImpl implements NavigatorService { @Transactional(readOnly = true) @Override public List<Resource> findResources(String query) { Stream<Resource> packageResources = dataService .query(PackageMetadata.PACKAGE, Package.class) .search(PackageMetadata.LABEL, query) .or() .search(PackageMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); Stream<Resource> entityTypeResources = dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .search(EntityTypeMetadata.LABEL, query) .or() .search(EntityTypeMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); return Streams.concat(packageResources, entityTypeResources).collect(toList()); } NavigatorServiceImpl(
      DataService dataService,
      JobExecutor jobExecutor,
      ResourceDownloadJobExecutionFactory downloadJobExecutionFactory,
      ResourceCopyJobExecutionFactory copyJobExecutionFactory,
      ResourceDeleteJobExecutionFactory resourceDeleteJobExecutionFactory); @Transactional(readOnly = true) @Override @Nullable @CheckForNull Folder getFolder(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> getResources(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> findResources(String query); @Transactional @Override void moveResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution copyResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution downloadResources(List<ResourceIdentifier> resources); @Transactional @Override JobExecution deleteResources(List<ResourceIdentifier> resources); @Transactional @Override void updateResource(Resource resource); }
NavigatorServiceImpl implements NavigatorService { @Transactional(readOnly = true) @Override public List<Resource> findResources(String query) { Stream<Resource> packageResources = dataService .query(PackageMetadata.PACKAGE, Package.class) .search(PackageMetadata.LABEL, query) .or() .search(PackageMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); Stream<Resource> entityTypeResources = dataService .query(ENTITY_TYPE_META_DATA, EntityType.class) .search(EntityTypeMetadata.LABEL, query) .or() .search(EntityTypeMetadata.DESCRIPTION, query) .findAll() .map(this::toResource); return Streams.concat(packageResources, entityTypeResources).collect(toList()); } NavigatorServiceImpl(
      DataService dataService,
      JobExecutor jobExecutor,
      ResourceDownloadJobExecutionFactory downloadJobExecutionFactory,
      ResourceCopyJobExecutionFactory copyJobExecutionFactory,
      ResourceDeleteJobExecutionFactory resourceDeleteJobExecutionFactory); @Transactional(readOnly = true) @Override @Nullable @CheckForNull Folder getFolder(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> getResources(@Nullable @CheckForNull String folderId); @Transactional(readOnly = true) @Override List<Resource> findResources(String query); @Transactional @Override void moveResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution copyResources(
      List<ResourceIdentifier> resources, @Nullable @CheckForNull String targetFolderId); @Override JobExecution downloadResources(List<ResourceIdentifier> resources); @Transactional @Override JobExecution deleteResources(List<ResourceIdentifier> resources); @Transactional @Override void updateResource(Resource resource);  }