Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#101
Browse files Browse the repository at this point in the history
# Conflicts:
#	vertx-pojo-mapper-common-test/src/main/java/de/braintags/vertx/jomnigate/testdatastore/AllTestsCommon.java
#	vertx-pojo-mapper-common/src/main/java/de/braintags/vertx/jomnigate/dataaccess/write/impl/AbstractWrite.java
#	vertx-pojo-mapper-common/src/main/java/de/braintags/vertx/jomnigate/dataaccess/write/impl/AfterInsertHandler.java
#	vertx-pojo-mapper-common/src/main/java/de/braintags/vertx/jomnigate/dataaccess/write/impl/AfterSaveHandler.java
#	vertx-pojo-mapper-common/src/main/java/de/braintags/vertx/jomnigate/dataaccess/write/impl/BeforeInsertHandler.java
#	vertx-pojo-mapper-common/src/main/java/de/braintags/vertx/jomnigate/dataaccess/write/impl/BeforeSaveHandler.java
#	vertx-pojo-mapper-mysql/src/main/java/de/braintags/vertx/jomnigate/mysql/dataaccess/SqlWrite.java
#	vertx-pojongo/src/main/java/de/braintags/vertx/jomnigate/mongo/dataaccess/MongoWrite.java
  • Loading branch information
Michael Remme committed Jul 26, 2017
2 parents de4c3c0 + 7a936ba commit 46f5dda
Show file tree
Hide file tree
Showing 44 changed files with 1,213 additions and 276 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ artifactid=vertx-pojo-mapper
projectDescription=vertx-pojo-mapper is a framework for nonblocking pojo mapping for different datasources

# dependencies
vertxVersion = 3.4.0-SNAPSHOT
vertxVersion = 3.4.2
btVertxVersion = 1.4.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ protected boolean isDuplicateKeyException(Throwable e) {
return e instanceof DuplicateKeyException;
}

@Override
protected void doQueryUpdate(T entity, JsonStoreObject<T> storeObject, Handler<AsyncResult<Object>> resultHandler) {
resultHandler.handle(Future.failedFuture(new UnsupportedOperationException()));
}

}
2 changes: 1 addition & 1 deletion vertx-pojo-mapper-common-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dependencies {
compile project(':vertx-pojo-mapper-common')
compile group: 'junit', name: 'junit', version:'4.11'
compile group: 'io.vertx', name:'vertx-unit', version:vertxVersion

compile group:'org.hamcrest', name:'hamcrest-library', version:'1.3'
if (isIncludedBuild) {
compile group: 'de.braintags', name:'vertx-util', version:btVertxVersion, configuration:'commonTests'
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TestOnlyIdMapper.class, TestTrigger.class, TestMassInsert.class, TestKeyGenerator.class, TestGeoSearch.class,
TestEncoder.class, TestListExtrems.class, TestReferenced.class, TestFieldConditionCache.class,
TestQueryInterator.class, DataTypesTestSuite.class, ObserverVersioningSuite.class, TestClearDatastore.class,
TestIndexedFields.class })
TestIndexedFields.class, TestUpdate.class })
public class AllTestsCommon {

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.braintags.vertx.jomnigate.dataaccess.write.IWrite;
import de.braintags.vertx.jomnigate.dataaccess.write.IWriteEntry;
import de.braintags.vertx.jomnigate.dataaccess.write.IWriteResult;
import de.braintags.vertx.jomnigate.mapping.IIndexDefinition;
import de.braintags.vertx.jomnigate.mapping.IMapper;
import de.braintags.vertx.jomnigate.util.QueryHelper;
import de.braintags.vertx.util.ErrorObject;
Expand All @@ -52,6 +53,7 @@

@RunWith(VertxUnitRunner.class)
public abstract class DatastoreBaseTest {

private static final Logger LOGGER = LoggerFactory.getLogger(DatastoreBaseTest.class);

@SuppressWarnings("unused")
Expand Down Expand Up @@ -191,7 +193,8 @@ public static ResultContainer find(final TestContext context, final IQuery<?> qu
* the limit the query should be executed with
* @return ResultContainer with certain informations
*/
public static ResultContainer find(final TestContext context, final IQuery<?> query, final int expectedResult, final int limit) {
public static ResultContainer find(final TestContext context, final IQuery<?> query, final int expectedResult,
final int limit) {
return find(context, query, expectedResult, limit, 0);
}

Expand All @@ -211,7 +214,8 @@ public static ResultContainer find(final TestContext context, final IQuery<?> qu
* @return ResultContainer with certain informations
*/
@SuppressWarnings("rawtypes")
public static ResultContainer find(final TestContext context, final IQuery<?> query, final int expectedResult, final int limit, final int offset) {
public static ResultContainer find(final TestContext context, final IQuery<?> query, final int expectedResult,
final int limit, final int offset) {
Async async = context.async();
ResultContainer resultContainer = new ResultContainer();
ErrorObject err = new ErrorObject<>(null);
Expand Down Expand Up @@ -402,6 +406,42 @@ public static ResultContainer delete(final TestContext context, final IDelete<?>
return null;
}

public static ResultContainer write(final TestContext context, final IWrite<?> write, final IQuery<?> checkQuery,
final int expectedResult) {
Async async = context.async();
ResultContainer resultContainer = new ResultContainer();
ErrorObject err = new ErrorObject<>(null);
write.save(result -> {
try {
resultContainer.writeResult = result.result();
checkWriteResult(context, result);
} catch (Throwable e) {
err.setThrowable(e);
} finally {
async.complete();
}
});

async.await();
if (err.isError()) {
throw new AssertionError(err.getThrowable());
}

// Now perform the query check
if (checkQuery != null) {
ResultContainer queryResult = find(context, checkQuery, expectedResult);
resultContainer.queryResult = queryResult.queryResult;
return resultContainer;
}
return null;
}

public static void checkWriteResult(final TestContext context, final AsyncResult<? extends IWriteResult> dResult) {
resultFine(dResult);
IWriteResult dr = dResult.result();
context.assertNotNull(dr);
}

public static void checkDeleteResult(final TestContext context, final AsyncResult<? extends IDeleteResult> dResult) {
resultFine(dResult);
IDeleteResult dr = dResult.result();
Expand All @@ -410,7 +450,8 @@ public static void checkDeleteResult(final TestContext context, final AsyncResul
LOGGER.info(dr.getOriginalCommand());
}

public static void checkQueryResultCount(final TestContext context, final AsyncResult<? extends IQueryCountResult> qResult,
public static void checkQueryResultCount(final TestContext context,
final AsyncResult<? extends IQueryCountResult> qResult,
final int expectedResult) {
resultFine(qResult);
IQueryCountResult qr = qResult.result();
Expand Down Expand Up @@ -532,16 +573,18 @@ public static void dropTable(final TestContext context, final String tableName)
* @param context
* @param q
*/
protected void checkIndex(final TestContext context, final IMapper<?> mapper, final String indexName) {
protected void checkIndex(final TestContext context, final IMapper<?> mapper,
final IIndexDefinition indexDefinition) {
Async async = context.async();
getDataStore(context).getMetaData().getIndexInfo(indexName, mapper, result -> {
getDataStore(context).getMetaData().getIndexInfo(indexDefinition.getName(), mapper, result -> {
if (result.failed()) {
context.fail(result.cause());
async.complete();
} else {
Object indexInfo = result.result();
LOGGER.info("indexInfo: " + indexInfo);
context.assertNotNull(indexInfo, "Index wasn't created");
TestHelper.getDatastoreContainer(context).checkIndex(indexInfo, indexDefinition, context);
async.complete();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

import de.braintags.vertx.jomnigate.IDataStore;
import de.braintags.vertx.jomnigate.init.DataStoreSettings;
import de.braintags.vertx.jomnigate.mapping.IIndexDefinition;
import de.braintags.vertx.jomnigate.testdatastore.typehandler.json.AbstractTypeHandlerTest;
import de.braintags.vertx.jomnigate.typehandler.ITypeHandler;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.ext.unit.TestContext;

/**
*
Expand Down Expand Up @@ -65,4 +67,16 @@ public interface IDatastoreContainer {
*/
public String getExpectedTypehandlerName(Class<? extends AbstractTypeHandlerTest> testClass, String defaultName);

/**
* Check that the result of an index info request matches the index definition that created it
*
* @param indexInfo
* the info from the index info operation from the datastore
* @param sourceIndex
* the source index definition that created the resulting index
* @param context
* the test context
*/
public void checkIndex(Object indexInfo, IIndexDefinition sourceIndex, TestContext context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package de.braintags.vertx.jomnigate.testdatastore;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -43,6 +44,7 @@ public class TestClearDatastore {
* @param context
*/
@Test
@Ignore("can only test with real database, not locally started test database that loses its data on every init")
public void testDatastore_noClearOnInit(final TestContext context) {
testDatastore(false, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public void testGeoSearch(TestContext context) {
found = findAll(context, query);
context.assertEquals(found.size(), 3, "wrong number of records");

query = getDataStore(context).createQuery(GeoMapper.class);
query.setSearchCondition(ISearchCondition.near(GeoMapper.POSITION, sLong, sLat));
found = findAll(context, query);
context.assertEquals(found.size(), 3, "wrong number of records");

}

public static void createDemoRecords(TestContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@
*/
package de.braintags.vertx.jomnigate.testdatastore;

import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;

import java.util.Arrays;

import org.junit.BeforeClass;
import org.junit.Test;

import com.google.common.collect.ImmutableSet;

import de.braintags.vertx.jomnigate.dataaccess.query.IQuery;
import de.braintags.vertx.jomnigate.dataaccess.write.IWrite;
import de.braintags.vertx.jomnigate.exception.DuplicateKeyException;
import de.braintags.vertx.jomnigate.mapping.IIndexDefinition;
import de.braintags.vertx.jomnigate.testdatastore.mapper.GeoMapper2;
import de.braintags.vertx.jomnigate.testdatastore.mapper.MiniMapperIndex;
import de.braintags.vertx.jomnigate.testdatastore.mapper.MiniMapperIndexPartialFilter;
import de.braintags.vertx.jomnigate.testdatastore.mapper.MiniMapperIndexUnique;
import de.braintags.vertx.jomnigate.testdatastore.mapper.MiniMapperIndexUniqueFilter;
import io.vertx.ext.unit.TestContext;

/**
Expand All @@ -36,19 +49,67 @@ public void testGeoIndex(final TestContext context) {
clearTable(context, GeoMapper2.class.getSimpleName());
IQuery<GeoMapper2> q = getDataStore(context).createQuery(GeoMapper2.class);
findAll(context, q);
checkIndex(context, q.getMapper(), "testindex");
checkIndex(context, q.getMapper(), getIndexDefinition(GeoMapper2.class, context));
}

@Test
public void testIndexMiniMapper(final TestContext context) {
clearTable(context, MiniMapperIndex.class.getSimpleName());
IQuery<MiniMapperIndex> q = getDataStore(context).createQuery(MiniMapperIndex.class);
findAll(context, q);
checkIndex(context, q.getMapper(), "testindexMiniMapper");
checkIndex(context, q.getMapper(), getIndexDefinition(MiniMapperIndex.class, context));
}

@Test
public void testIndexMiniMapper_partialFilter(final TestContext context) {
clearTable(context, MiniMapperIndexPartialFilter.class.getSimpleName());
IQuery<MiniMapperIndexPartialFilter> q = getDataStore(context).createQuery(MiniMapperIndexPartialFilter.class);
findAll(context, q);
checkIndex(context, q.getMapper(), getIndexDefinition(MiniMapperIndexPartialFilter.class, context));
}

@Test
public void testIndexMiniMapper_unique(final TestContext context) {
clearTable(context, MiniMapperIndexUnique.class.getSimpleName());
IQuery<MiniMapperIndexUnique> q = getDataStore(context).createQuery(MiniMapperIndexUnique.class);
findAll(context, q);
checkIndex(context, q.getMapper(), getIndexDefinition(MiniMapperIndexUnique.class, context));
}

@Test
public void testIndexMiniMapper_unique_filter(final TestContext context) {
clearTable(context, MiniMapperIndexUniqueFilter.class.getSimpleName());
IQuery<MiniMapperIndexUniqueFilter> q = getDataStore(context).createQuery(MiniMapperIndexUniqueFilter.class);
findAll(context, q);
checkIndex(context, q.getMapper(), getIndexDefinition(MiniMapperIndexUniqueFilter.class, context));
MiniMapperIndexUniqueFilter unfiltered1 = new MiniMapperIndexUniqueFilter(false);
unfiltered1.name = "not-unique";
MiniMapperIndexUniqueFilter unfiltered2 = new MiniMapperIndexUniqueFilter(false);
unfiltered2.name = "not-unique";
// should not throw exception, as they don't match the filter query
saveRecords(context, Arrays.asList(unfiltered1, unfiltered2));

MiniMapperIndexUniqueFilter filtered1 = new MiniMapperIndexUniqueFilter(true);
filtered1.name = "unique";
saveRecord(context, filtered1);

MiniMapperIndexUniqueFilter filtered2 = new MiniMapperIndexUniqueFilter(true);
filtered2.name = "unique";
IWrite<MiniMapperIndexUniqueFilter> write = getDataStore(context).createWrite(MiniMapperIndexUniqueFilter.class);
write.add(filtered2);
write.save(context.asyncAssertFailure(e -> context.assertTrue(e instanceof DuplicateKeyException)));
}

@BeforeClass
public static void beforeClass(final TestContext context) {
dropTable(context, GeoMapper2.class.getSimpleName());
}

private IIndexDefinition getIndexDefinition(Class<?> mapperClass, final TestContext context) {
ImmutableSet<IIndexDefinition> indexDefinitions = getDataStore(context).getMapperFactory().getMapper(mapperClass)
.getIndexDefinitions();
assertThat(indexDefinitions, hasSize(1));
IIndexDefinition indexDefinition = indexDefinitions.iterator().next();
return indexDefinition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ public void testDeepQuery(TestContext context) {

}

/**
* Search:
*/
@Test
public void testNot(TestContext context) {
createDemoRecords(context);
IQuery<SimpleMapper> query = getDataStore(context).createQuery(SimpleMapper.class);
List<String> it = Arrays.asList("erste", "zweite");
query.setSearchCondition(ISearchCondition.not(ISearchCondition.in(SimpleMapper.SECOND_PROPERTY, it)));
find(context, query, 6);
}

@Test
public void testSimpleOr(TestContext context) {
createDemoRecords(context);
Expand Down
Loading

0 comments on commit 46f5dda

Please sign in to comment.