polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [7/8] zest-java git commit: mongo-entitystore: test using embedded mongodb process
Date Sat, 03 Dec 2016 11:06:03 GMT
mongo-entitystore: test using embedded mongodb process


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/d3ae3cdc
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/d3ae3cdc
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/d3ae3cdc

Branch: refs/heads/develop
Commit: d3ae3cdce0a49b5a25b1758ae7e8682e51680969
Parents: de4731b
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sat Dec 3 11:30:54 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sat Dec 3 11:30:54 2016 +0100

----------------------------------------------------------------------
 dependencies.gradle                             |  2 +
 extensions/entitystore-mongodb/build.gradle     |  1 +
 .../mongodb/EmbedMongoMapEntityStoreTest.java   | 92 ++++++++++++++++++++
 3 files changed, 95 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/d3ae3cdc/dependencies.gradle
----------------------------------------------------------------------
diff --git a/dependencies.gradle b/dependencies.gradle
index b3c0aa3..b14783e 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -171,6 +171,7 @@ def antVersion = '1.9.7'
 def awaitilityVersion = '2.0.0'
 def dnsJavaVersion = '2.1.7'
 def easyMockVersion = '3.4'
+def embedMongoVersion = '1.50.5'
 def h2Version = '1.4.193'
 def hamcrestVersion = '1.3'
 def junitVersion = '4.12'
@@ -186,6 +187,7 @@ dependencies.libraries << [
   derby             : "org.apache.derby:derby:$derbyVersion",
   dnsjava           : "dnsjava:dnsjava:$dnsJavaVersion",
   easymock          : "org.easymock:easymock:$easyMockVersion",
+  embed_mongo       : "de.flapdoodle.embed:de.flapdoodle.embed.mongo:$embedMongoVersion",
   h2                : "com.h2database:h2:$h2Version",
   hamcrest          : [ "org.hamcrest:hamcrest-core:$hamcrestVersion",
                         "org.hamcrest:hamcrest-library:$hamcrestVersion" ],

http://git-wip-us.apache.org/repos/asf/zest-java/blob/d3ae3cdc/extensions/entitystore-mongodb/build.gradle
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/build.gradle b/extensions/entitystore-mongodb/build.gradle
index d7ae1ec..55f77f6 100644
--- a/extensions/entitystore-mongodb/build.gradle
+++ b/extensions/entitystore-mongodb/build.gradle
@@ -31,6 +31,7 @@ dependencies {
 
   testCompile zest.core.testsupport
   testCompile zest.extension( 'valueserialization-orgjson' )
+  testCompile libraries.embed_mongo
 
   testRuntime libraries.logback
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/d3ae3cdc/extensions/entitystore-mongodb/src/test/java/org/apache/zest/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/zest/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
b/extensions/entitystore-mongodb/src/test/java/org/apache/zest/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
new file mode 100644
index 0000000..b528b54
--- /dev/null
+++ b/extensions/entitystore-mongodb/src/test/java/org/apache/zest/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.zest.entitystore.mongodb;
+
+import de.flapdoodle.embed.mongo.MongodExecutable;
+import de.flapdoodle.embed.mongo.MongodStarter;
+import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
+import de.flapdoodle.embed.mongo.config.Net;
+import de.flapdoodle.embed.mongo.distribution.Version;
+import de.flapdoodle.embed.process.runtime.Network;
+import java.io.IOException;
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.bootstrap.AssemblyException;
+import org.apache.zest.bootstrap.ModuleAssembly;
+import org.apache.zest.entitystore.mongodb.assembly.MongoDBEntityStoreAssembler;
+import org.apache.zest.test.EntityTestAssembler;
+import org.apache.zest.test.entity.AbstractEntityStoreTest;
+import org.apache.zest.test.util.FreePortFinder;
+import org.apache.zest.valueserialization.orgjson.OrgJsonValueSerializationAssembler;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+public class EmbedMongoMapEntityStoreTest extends AbstractEntityStoreTest
+{
+    private static final MongodStarter MONGO_STARTER = MongodStarter.getDefaultInstance();
+
+    @Rule
+    public TestName testName = new TestName();
+    private static int port;
+    private static MongodExecutable mongod;
+
+
+    @BeforeClass
+    public static void startEmbedMongo() throws IOException
+    {
+        port = FreePortFinder.findFreePortOnLoopback();
+        mongod = MONGO_STARTER.prepare( new MongodConfigBuilder()
+                                            .version( Version.Main.PRODUCTION )
+                                            .net( new Net( port, Network.localhostIsIPv6()
) )
+                                            .build() );
+        mongod.start();
+    }
+
+    @AfterClass
+    public static void stopEmbedMongo()
+    {
+        if( mongod != null )
+        {
+            mongod.stop();
+        }
+    }
+
+    @Override
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        super.assemble( module );
+
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().assemble( config );
+
+        new OrgJsonValueSerializationAssembler().assemble( module );
+
+        new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble(
module );
+
+
+        MongoEntityStoreConfiguration mongoConfig = config.forMixin( MongoEntityStoreConfiguration.class
)
+                                                          .declareDefaults();
+        mongoConfig.writeConcern().set( MongoEntityStoreConfiguration.WriteConcern.FSYNC_SAFE
);
+        mongoConfig.database().set( "zest:test" );
+        mongoConfig.collection().set( testName.getMethodName() );
+        mongoConfig.hostname().set( "localhost" );
+        mongoConfig.port().set( port );
+    }
+}


Mime
View raw message