Skip to content

Commit

Permalink
creates test to document collection manager async
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Oct 1, 2019
1 parent 6333d7f commit 550df23
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2019 Otávio Santana and others
* 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.artemis.configuration.document;

import jakarta.nosql.document.DocumentCollectionManagerAsync;
import org.eclipse.jnosql.artemis.configuration.CDIExtension;
import org.eclipse.jnosql.artemis.configuration.ConfigurationException;
import org.eclipse.jnosql.artemis.configuration.document.DocumentConfigurationMock.DocumentCollectionManagerMock;
import org.eclipse.microprofile.config.Config;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import javax.inject.Inject;
import java.util.NoSuchElementException;
import java.util.UUID;

@ExtendWith(CDIExtension.class)
class DocumentCollectionManagerAsyncConverterTest {

@Inject
private Config config;

@Test
public void shouldReturnErrorWhenThereIsNoProvider() {
final String prefix = UUID.randomUUID().toString();
System.setProperty(prefix, prefix);
System.setProperty(prefix + ".settings.key", "value");
System.setProperty(prefix + ".settings.key2", "value2");
Assertions.assertThrows(NoSuchElementException.class, () -> config.getValue(prefix, DocumentCollectionManagerAsync.class) );

System.clearProperty(prefix);
System.clearProperty(prefix + ".settings.key");
System.clearProperty(prefix + ".settings.key2");
}

@Test
public void shouldReturnErrorWhenThereIsInvalidProvider() {
final String prefix = UUID.randomUUID().toString();
System.setProperty(prefix, prefix);
System.setProperty(prefix + ".settings.key", "value");
System.setProperty(prefix + ".settings.key2", "value2");
System.setProperty(prefix + ".provider", "java.lang.String");
Assertions.assertThrows(ConfigurationException.class, () -> config.getValue(prefix, DocumentCollectionManagerAsync.class) );

System.clearProperty(prefix);
System.clearProperty(prefix + ".settings.key");
System.clearProperty(prefix + ".settings.key2");
System.clearProperty(prefix + ".provider");
}

@Test
public void shouldReturnErrorWhenTableIsMissing() {
final String prefix = UUID.randomUUID().toString();
System.setProperty(prefix, prefix);
System.setProperty(prefix + ".settings.key", "value");
System.setProperty(prefix + ".settings.key2", "value2");
System.setProperty(prefix + ".provider", DocumentConfigurationAsyncMock.class.getName());
Assertions.assertThrows(NoSuchElementException.class, () -> config.getValue(prefix, DocumentCollectionManagerAsync.class) );

System.clearProperty(prefix);
System.clearProperty(prefix + ".settings.key");
System.clearProperty(prefix + ".settings.key2");
System.clearProperty(prefix + ".provider");
}

@Test
public void shouldReturnManager() {
final String prefix = UUID.randomUUID().toString();
System.setProperty(prefix, prefix);
System.setProperty(prefix + ".settings.key", "value");
System.setProperty(prefix + ".settings.key2", "value2");
System.setProperty(prefix + ".provider", DocumentConfigurationAsyncMock.class.getName());
System.setProperty(prefix + ".database", "database");
final DocumentCollectionManagerAsync manager = config.getValue(prefix, DocumentCollectionManagerAsync.class);
final DocumentCollectionManagerMock managerMock = DocumentCollectionManagerMock.class.cast(manager);
Assertions.assertEquals("database", managerMock.getDatabase());
System.clearProperty(prefix);
System.clearProperty(prefix + ".settings.key");
System.clearProperty(prefix + ".settings.key2");
System.clearProperty(prefix + ".provider");
System.clearProperty(prefix + ".database");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.nosql.document.DocumentQuery;

import java.time.Duration;
import java.util.function.Consumer;
import java.util.stream.Stream;

class DocumentConfigurationAsyncMock implements DocumentConfigurationAsync {
Expand Down Expand Up @@ -40,8 +41,8 @@ public Settings getSettings() {


@Override
public <T extends DocumentCollectionManagerAsync> T getAsync(String database) {
return null;
public DocumentCollectionManagerMock getAsync(String database) {
return new DocumentCollectionManagerMock(database);
}

@Override
Expand All @@ -50,36 +51,61 @@ public void close() {
}
}

public static class DocumentCollectionManagerMock implements DocumentCollectionManager {
public static class DocumentCollectionManagerMock implements DocumentCollectionManagerAsync {

private final String database;

public DocumentCollectionManagerMock(String database) {
this.database = database;
}

public String getDatabase() {
return database;
}

@Override
public DocumentEntity insert(DocumentEntity entity) {
return null;
public void insert(DocumentEntity entity) {

}

@Override
public DocumentEntity insert(DocumentEntity entity, Duration ttl) {
return null;
public void insert(DocumentEntity entity, Duration ttl) {

}

@Override
public Iterable<DocumentEntity> insert(Iterable<DocumentEntity> entities) {
return null;
public void insert(Iterable<DocumentEntity> entities) {

}

@Override
public Iterable<DocumentEntity> insert(Iterable<DocumentEntity> entities, Duration ttl) {
return null;
public void insert(Iterable<DocumentEntity> entities, Duration ttl) {

}

@Override
public DocumentEntity update(DocumentEntity entity) {
return null;
public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) {

}

@Override
public Iterable<DocumentEntity> update(Iterable<DocumentEntity> entities) {
return null;
public void insert(DocumentEntity entity, Duration ttl, Consumer<DocumentEntity> callBack) {

}

@Override
public void update(DocumentEntity entity) {

}

@Override
public void update(Iterable<DocumentEntity> entities) {

}

@Override
public void update(DocumentEntity entity, Consumer<DocumentEntity> callBack) {

}

@Override
Expand All @@ -88,13 +114,18 @@ public void delete(DocumentDeleteQuery query) {
}

@Override
public Stream<DocumentEntity> select(DocumentQuery query) {
return null;
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) {

}

@Override
public long count(String documentCollection) {
return 0;
public void select(DocumentQuery query, Consumer<Stream<DocumentEntity>> callBack) {

}

@Override
public void count(String documentCollection, Consumer<Long> callback) {

}

@Override
Expand Down

0 comments on commit 550df23

Please sign in to comment.