METAMODEL-1151: Added test to ensure loading of factory classes

Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/57a614de
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/57a614de
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/57a614de

Branch: refs/heads/master
Commit: 57a614dee43f72051c50d9b8af5b31b99cfddb78
Parents: 7b91f36
Author: Kasper Sørensen <i.am.kasper.soren...@gmail.com>
Authored: Tue Aug 8 20:55:43 2017 -0700
Committer: Kasper Sørensen <i.am.kasper.soren...@gmail.com>
Committed: Tue Aug 8 21:05:57 2017 -0700

----------------------------------------------------------------------
 .../factory/AbstractDataContextFactory.java     | 10 +--
 .../factory/DataContextFactoryRegistryTest.java | 66 ++++++++++++++++++++
 2 files changed, 71 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel/blob/57a614de/core/src/main/java/org/apache/metamodel/factory/AbstractDataContextFactory.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/metamodel/factory/AbstractDataContextFactory.java
 
b/core/src/main/java/org/apache/metamodel/factory/AbstractDataContextFactory.java
index f338d3e..045eb63 100644
--- 
a/core/src/main/java/org/apache/metamodel/factory/AbstractDataContextFactory.java
+++ 
b/core/src/main/java/org/apache/metamodel/factory/AbstractDataContextFactory.java
@@ -76,18 +76,18 @@ public abstract class AbstractDataContextFactory implements 
DataContextFactory {
 
     private static boolean isNullOrEmpty(Object value) {
         if (value == null) {
-            return false;
+            return true;
         }
         if (value instanceof String && ((String) value).isEmpty()) {
-            return false;
+            return true;
         }
         if (value instanceof Collection && ((Collection<?>) value).isEmpty()) {
-            return false;
+            return true;
         }
         if (value instanceof Map && ((Map<?, ?>) value).isEmpty()) {
-            return false;
+            return true;
         }
-        return true;
+        return false;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/metamodel/blob/57a614de/full/src/test/java/org/apache/metamodel/factory/DataContextFactoryRegistryTest.java
----------------------------------------------------------------------
diff --git 
a/full/src/test/java/org/apache/metamodel/factory/DataContextFactoryRegistryTest.java
 
b/full/src/test/java/org/apache/metamodel/factory/DataContextFactoryRegistryTest.java
new file mode 100644
index 0000000..03fd40f
--- /dev/null
+++ 
b/full/src/test/java/org/apache/metamodel/factory/DataContextFactoryRegistryTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.metamodel.factory;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.metamodel.cassandra.CassandraDataContextFactory;
+import org.apache.metamodel.couchdb.CouchDbDataContextFactory;
+import org.apache.metamodel.csv.CsvDataContextFactory;
+import 
org.apache.metamodel.elasticsearch.nativeclient.ElasticSearchDataContextFactory;
+import 
org.apache.metamodel.elasticsearch.rest.ElasticSearchRestDataContextFactory;
+import org.apache.metamodel.excel.ExcelDataContextFactory;
+import org.apache.metamodel.fixedwidth.FixedWidthDataContextFactory;
+import org.apache.metamodel.hbase.HbaseDataContextFactory;
+import org.apache.metamodel.jdbc.JdbcDataContextFactory;
+import org.apache.metamodel.json.JsonDataContextFactory;
+import org.apache.metamodel.pojo.PojoDataContextFactory;
+import org.apache.metamodel.salesforce.SalesforceDataContextFactory;
+import org.apache.metamodel.xml.XmlDomDataContextFactory;
+import org.apache.metamodel.xml.XmlSaxDataContextFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DataContextFactoryRegistryTest {
+
+    @Test
+    public void testLoadAllFactories() {
+        final DataContextFactoryRegistry registry = 
DataContextFactoryRegistryImpl.getDefaultInstance();
+        final Collection<DataContextFactory> factories = 
registry.getFactories();
+
+        final List<Class<?>> factoryClasses = factories.stream().map(f -> 
f.getClass()).collect(Collectors.toList());
+
+        
Assert.assertTrue(factoryClasses.contains(CassandraDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(CsvDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(CouchDbDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(ElasticSearchDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(ElasticSearchRestDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(ExcelDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(FixedWidthDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(HbaseDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(JdbcDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(JsonDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(PojoDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(SalesforceDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(XmlDomDataContextFactory.class));
+        
Assert.assertTrue(factoryClasses.contains(XmlSaxDataContextFactory.class));
+    }
+}

Reply via email to