@Test public void testFindByDomain() throws TechnicalException { Application application = new Application(); application.setName("testApp"); application.setDomain("testDomain"); applicationRepository.create(application).blockingGet(); TestObserver<Page<Application>> testObserver = applicationRepository.findByDomain("testDomain", 0, Integer.MAX_VALUE).test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete(); testObserver.assertNoErrors(); testObserver.assertValue(applicationPage -> applicationPage.getData().size() == 1); }
@Override public Single<Page<Application>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(applicationsCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Application>> applicationsOperation = Observable.fromPublisher(applicationsCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, applicationsOperation, (count, applications) -> new Page<>(applications, page, count)); }
MongoApplicationRepository extends AbstractManagementMongoRepository implements ApplicationRepository { @Override public Single<Page<Application>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(applicationsCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Application>> applicationsOperation = Observable.fromPublisher(applicationsCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, applicationsOperation, (count, applications) -> new Page<>(applications, page, count)); } }
MongoApplicationRepository extends AbstractManagementMongoRepository implements ApplicationRepository { @Override public Single<Page<Application>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(applicationsCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Application>> applicationsOperation = Observable.fromPublisher(applicationsCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, applicationsOperation, (count, applications) -> new Page<>(applications, page, count)); }  }
MongoApplicationRepository extends AbstractManagementMongoRepository implements ApplicationRepository { @Override public Single<Page<Application>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(applicationsCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Application>> applicationsOperation = Observable.fromPublisher(applicationsCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, applicationsOperation, (count, applications) -> new Page<>(applications, page, count)); }  @PostConstruct void init(); @Override Single<List<Application>> findAll(); @Override Single<Page<Application>> findAll(int page, int size); @Override Single<Page<Application>> findByDomain(String domain, int page, int size); @Override Single<Page<Application>> search(String domain, String query, int page, int size); @Override Single<Set<Application>> findByCertificate(String certificate); @Override Single<Set<Application>> findByIdentityProvider(String identityProvider); @Override Single<Set<Application>> findByFactor(String factor); @Override Maybe<Application> findById(String id); @Override Maybe<Application> findByDomainAndClientId(String domain, String clientId); @Override Single<Set<Application>> findByDomainAndExtensionGrant(String domain, String extensionGrant); @Override Single<Set<Application>> findByIdIn(List<String> ids); @Override Single<Application> create(Application item); @Override Single<Application> update(Application item); @Override Completable delete(String id); @Override Single<Long> count(); @Override Single<Long> countByDomain(String domain); }
MongoApplicationRepository extends AbstractManagementMongoRepository implements ApplicationRepository { @Override public Single<Page<Application>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(applicationsCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Application>> applicationsOperation = Observable.fromPublisher(applicationsCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, applicationsOperation, (count, applications) -> new Page<>(applications, page, count)); }  @PostConstruct void init(); @Override Single<List<Application>> findAll(); @Override Single<Page<Application>> findAll(int page, int size); @Override Single<Page<Application>> findByDomain(String domain, int page, int size); @Override Single<Page<Application>> search(String domain, String query, int page, int size); @Override Single<Set<Application>> findByCertificate(String certificate); @Override Single<Set<Application>> findByIdentityProvider(String identityProvider); @Override Single<Set<Application>> findByFactor(String factor); @Override Maybe<Application> findById(String id); @Override Maybe<Application> findByDomainAndClientId(String domain, String clientId); @Override Single<Set<Application>> findByDomainAndExtensionGrant(String domain, String extensionGrant); @Override Single<Set<Application>> findByIdIn(List<String> ids); @Override Single<Application> create(Application item); @Override Single<Application> update(Application item); @Override Completable delete(String id); @Override Single<Long> count(); @Override Single<Long> countByDomain(String domain);  }