You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2013/07/19 11:33:02 UTC
[19/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java b/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java
deleted file mode 100644
index 8eca7b2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/MutableSchemaTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.eobjects.metamodel.schema;
-
-import junit.framework.TestCase;
-
-public class MutableSchemaTest extends TestCase {
-
- /**
- * Tests that the following (general) rules apply to the object:
- *
- * <li>the hashcode is the same when run twice on an unaltered object</li>
- * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
- * 02.hashCode()
- */
- public void testEqualsAndHashCode() throws Exception {
- MutableSchema schema1 = new MutableSchema("foo");
- MutableSchema schema2 = new MutableSchema("foo");
-
- assertTrue(schema1.equals(schema2));
- assertTrue(schema1.hashCode() == schema2.hashCode());
-
- schema2.addTable(new MutableTable("foo"));
- assertFalse(schema1.equals(schema2));
- assertTrue(schema1.hashCode() == schema2.hashCode());
-
- schema2 = new MutableSchema("foo");
- assertTrue(schema1.equals(schema2));
- assertTrue(schema1.hashCode() == schema2.hashCode());
- }
-
- public void testGetTableByName() throws Exception {
- MutableSchema s = new MutableSchema("foobar");
- s.addTable(new MutableTable("Foo"));
- s.addTable(new MutableTable("FOO"));
- s.addTable(new MutableTable("bar"));
-
- assertEquals("Foo", s.getTableByName("Foo").getName());
- assertEquals("FOO", s.getTableByName("FOO").getName());
- assertEquals("bar", s.getTableByName("bar").getName());
-
- // picking the first alternative that matches case insensitively
- assertEquals("Foo", s.getTableByName("fOO").getName());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java b/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java
deleted file mode 100644
index 4efb0d6..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/MutableTableTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.eobjects.metamodel.schema;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class MutableTableTest extends TestCase {
-
- /**
- * Tests that the following (general) rules apply to the object:
- *
- * <li>the hashcode is the same when run twice on an unaltered object</li>
- * <li>if o1.equals(o2) then this condition must be true: o1.hashCode() ==
- * 02.hashCode()
- */
- public void testEqualsAndHashCode() throws Exception {
- MutableTable table1 = new MutableTable("Foo").addColumn(new MutableColumn("col1"));
- MutableTable table2 = new MutableTable("Foo").addColumn(new MutableColumn("col1"));
-
- assertFalse(table2.equals(null));
- assertEquals(table1.hashCode(), table2.hashCode());
- assertEquals(table1, table2);
-
- table2.addColumn(new MutableColumn("bar"));
- assertFalse(table1.equals(table2));
-
- int table1hash = table1.hashCode();
- int table2hash = table2.hashCode();
- assertTrue(table1hash + "==" + table2hash, table1hash == table2hash);
- }
-
- public void testGetColumnsOfType() throws Exception {
- MutableTable t = new MutableTable("foo");
- t.addColumn(new MutableColumn("b").setType(ColumnType.VARCHAR));
- t.addColumn(new MutableColumn("a").setType(ColumnType.VARCHAR));
- t.addColumn(new MutableColumn("r").setType(ColumnType.INTEGER));
-
- Column[] cols = t.getColumnsOfType(ColumnType.VARCHAR);
- assertEquals(2, cols.length);
- assertEquals("b", cols[0].getName());
- assertEquals("a", cols[1].getName());
-
- cols = t.getColumnsOfType(ColumnType.INTEGER);
- assertEquals(1, cols.length);
- assertEquals("r", cols[0].getName());
-
- cols = t.getColumnsOfType(ColumnType.FLOAT);
- assertEquals(0, cols.length);
- }
-
- public void testGetIndexedColumns() throws Exception {
- MutableTable t = new MutableTable("foo");
- t.addColumn(new MutableColumn("b").setIndexed(true));
- t.addColumn(new MutableColumn("a").setIndexed(false));
- t.addColumn(new MutableColumn("r").setIndexed(true));
- Column[] indexedColumns = t.getIndexedColumns();
- assertEquals(
- "[Column[name=b,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null], Column[name=r,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null]]",
- Arrays.toString(indexedColumns));
- for (Column column : indexedColumns) {
- assertTrue(column.isIndexed());
- }
- }
-
- public void testGetColumnByName() throws Exception {
- MutableTable t = new MutableTable("foobar");
- t.addColumn(new MutableColumn("Foo"));
- t.addColumn(new MutableColumn("FOO"));
- t.addColumn(new MutableColumn("bar"));
-
- assertEquals("Foo", t.getColumnByName("Foo").getName());
- assertEquals("FOO", t.getColumnByName("FOO").getName());
- assertEquals("bar", t.getColumnByName("bar").getName());
-
- // picking the first alternative that matches case insensitively
- assertEquals("Foo", t.getColumnByName("fOO").getName());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java b/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java
deleted file mode 100644
index 380d9d1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/SchemaModelTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * 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.eobjects.metamodel.schema;
-
-import java.util.Arrays;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-
-public class SchemaModelTest extends MetaModelTestCase {
-
- public void testGetExampleSchema() throws Exception {
- Schema schema = getExampleSchema();
- assertEquals("MetaModelSchema", schema.getName());
- assertEquals("Schema[name=MetaModelSchema]", schema.toString());
- assertEquals(5, schema.getRelationships().length);
-
- assertEquals(4, schema.getTableCount());
- assertEquals(3, schema.getTableCount(TableType.TABLE));
- assertEquals(1, schema.getTableCount(TableType.VIEW));
-
- assertNull(schema.getTableByName("foobar"));
- assertNull(schema.getTableByName(null));
-
- Table contributorTable = schema.getTableByName(TABLE_CONTRIBUTOR);
- assertEquals(3, contributorTable.getColumnCount());
- assertEquals(2, contributorTable.getRelationshipCount());
-
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- assertEquals(4, projectTable.getColumnCount());
- assertEquals(2, projectTable.getRelationshipCount());
- assertNotNull(projectTable.getColumnByName("project_id"));
-
- assertEquals("[project_id, name, lines_of_code, parent_project_id]",
- Arrays.toString(projectTable.getColumnNames()));
-
- assertEquals(
- "[Column[name=project_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null], "
- + "Column[name=lines_of_code,columnNumber=2,type=BIGINT,nullable=true,nativeType=null,columnSize=null], "
- + "Column[name=parent_project_id,columnNumber=3,type=INTEGER,nullable=true,nativeType=null,columnSize=null]]",
- Arrays.toString(projectTable.getNumberColumns()));
-
- assertEquals("[Column[name=name,columnNumber=1,type=VARCHAR,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(projectTable.getLiteralColumns()));
-
- assertEquals("[]", Arrays.toString(projectTable.getTimeBasedColumns()));
-
- assertNull(projectTable.getColumnByName("foobar"));
- assertNull(projectTable.getColumnByName(null));
-
- Table roleTable = schema.getTableByName(TABLE_ROLE);
- assertEquals(3, roleTable.getColumnCount());
- assertEquals(3, roleTable.getRelationshipCount());
-
- Table projectContributorView = schema.getTableByName(TABLE_PROJECT_CONTRIBUTOR);
- assertEquals(3, projectContributorView.getColumnCount());
- assertEquals(3, projectContributorView.getRelationshipCount());
-
- Relationship[] projectContributorToContributorRelations = projectContributorView
- .getRelationships(contributorTable);
- assertEquals(1, projectContributorToContributorRelations.length);
- Relationship[] contributorToProjectContributorRelations = contributorTable
- .getRelationships(projectContributorView);
- assertEquals(1, contributorToProjectContributorRelations.length);
- assertTrue(Arrays.equals(projectContributorToContributorRelations, contributorToProjectContributorRelations));
-
- assertEquals(
- "Relationship[primaryTable=contributor,primaryColumns=[name],foreignTable=project_contributor,foreignColumns=[contributor]]",
- projectContributorToContributorRelations[0].toString());
-
- ((MutableRelationship) projectContributorToContributorRelations[0]).remove();
- projectContributorToContributorRelations = projectContributorView.getRelationships(contributorTable);
- assertEquals(0, projectContributorToContributorRelations.length);
- contributorToProjectContributorRelations = contributorTable.getRelationships(projectContributorView);
- assertEquals(0, contributorToProjectContributorRelations.length);
-
- // Get primary keys / Get foreign keys test
- assertEquals(
- "[Column[name=contributor_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(contributorTable.getPrimaryKeys()));
- assertEquals("[]", Arrays.toString(contributorTable.getForeignKeys()));
-
- assertEquals(
- "[Column[name=contributor_id,columnNumber=0,type=INTEGER,nullable=false,nativeType=null,columnSize=null], Column[name=project_id,columnNumber=1,type=INTEGER,nullable=false,nativeType=null,columnSize=null]]",
- Arrays.toString(roleTable.getPrimaryKeys()));
- Column[] foreignKeys = roleTable.getForeignKeys();
- assertEquals(2, foreignKeys.length);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java b/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java
deleted file mode 100644
index 127c54b..0000000
--- a/core/src/test/java/org/eobjects/metamodel/schema/TableTypeTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.eobjects.metamodel.schema;
-
-import junit.framework.TestCase;
-
-public class TableTypeTest extends TestCase {
-
- public void testGetTableType() throws Exception {
- assertSame(TableType.TABLE, TableType.getTableType("table"));
- assertSame(TableType.VIEW, TableType.getTableType("view"));
- assertSame(TableType.GLOBAL_TEMPORARY, TableType
- .getTableType("GLOBAL_TEMPORARY"));
- assertSame(TableType.SYSTEM_TABLE, TableType
- .getTableType("system_table"));
- assertSame(TableType.LOCAL_TEMPORARY, TableType
- .getTableType("LOCAL_TEMPORARY"));
- assertSame(TableType.ALIAS, TableType.getTableType("alIAs"));
- assertSame(TableType.SYNONYM, TableType.getTableType("synonym"));
- assertSame(TableType.OTHER, TableType.getTableType("foobar"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java b/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java
deleted file mode 100644
index 36039c4..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/AlphabeticSequenceTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class AlphabeticSequenceTest extends TestCase {
-
- public void testNoArgsConstructor() throws Exception {
- AlphabeticSequence seq = new AlphabeticSequence();
- assertEquals("A", seq.next());
- }
-
- public void testNext() throws Exception {
- AlphabeticSequence seq = new AlphabeticSequence("A");
- assertEquals("A", seq.current());
- assertEquals("B", seq.next());
- assertEquals("C", seq.next());
- assertEquals("D", seq.next());
- assertEquals("E", seq.next());
- assertEquals("F", seq.next());
- assertEquals("G", seq.next());
- assertEquals("H", seq.next());
- assertEquals("I", seq.next());
- assertEquals("J", seq.next());
- assertEquals("K", seq.next());
- assertEquals("L", seq.next());
- assertEquals("M", seq.next());
- assertEquals("N", seq.next());
- assertEquals("O", seq.next());
- assertEquals("P", seq.next());
- assertEquals("Q", seq.next());
- assertEquals("R", seq.next());
- assertEquals("S", seq.next());
- assertEquals("T", seq.next());
- assertEquals("U", seq.next());
- assertEquals("V", seq.next());
- assertEquals("W", seq.next());
- assertEquals("X", seq.next());
- assertEquals("Y", seq.next());
- assertEquals("Z", seq.next());
- assertEquals("AA", seq.next());
-
- seq = new AlphabeticSequence("AZ");
- assertEquals("BA", seq.next());
-
- seq = new AlphabeticSequence("ZZ");
- assertEquals("AAA", seq.next());
-
- seq = new AlphabeticSequence("ABZ");
- assertEquals("ACA", seq.next());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java b/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java
deleted file mode 100644
index e147bc1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/BaseObjectTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class BaseObjectTest extends TestCase {
-
- class MyClass extends BaseObject {
- private int[] ints;
-
- @Override
- protected void decorateIdentity(List<Object> identifiers) {
- identifiers.add(ints);
- }
- }
-
- public void testHashCodeForPrimitiveArray() throws Exception {
- MyClass o1 = new MyClass();
- o1.ints = new int[] { 1, 2, 3 };
- MyClass o2 = new MyClass();
- o2.ints = new int[] { 4, 5, 6 };
- MyClass o3 = new MyClass();
- o3.ints = new int[] { 1, 2, 3 };
-
- assertTrue(o1.hashCode() == o1.hashCode());
- assertTrue(o1.hashCode() == o3.hashCode());
- assertFalse(o1.hashCode() == o2.hashCode());
- assertFalse(o3.hashCode() == o2.hashCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java
deleted file mode 100644
index 1c099fd..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/BooleanComparatorTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-
-public class BooleanComparatorTest extends TestCase {
-
- public void testCompare() throws Exception {
- Comparator<Object> c = BooleanComparator.getComparator();
- assertEquals(1, c.compare(true, false));
- assertEquals(-1, c.compare(false, true));
- assertEquals(0, c.compare(true, true));
- assertEquals(0, c.compare(false, false));
-
- assertEquals(1, c.compare("true", "false"));
- assertEquals(1, c.compare("1", "false"));
- assertEquals(1, c.compare("true", "0"));
- assertEquals(1, c.compare("true", "false"));
-
- assertEquals(1, c.compare(1, 0));
-
- assertEquals(1, c.compare(1, "false"));
- assertEquals(1, c.compare("yes", false));
- assertEquals(1, c.compare("y", false));
- assertEquals(1, c.compare("TRUE", false));
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = BooleanComparator.getComparable(true);
- assertEquals(1, comparable.compareTo(false));
- assertEquals(1, comparable.compareTo(0));
- assertEquals(1, comparable.compareTo("false"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java b/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java
deleted file mode 100644
index 0b94d5d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ClasspathResourceTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.io.InputStream;
-
-import junit.framework.TestCase;
-
-public class ClasspathResourceTest extends TestCase {
-
- public void testGetName() throws Exception {
- ClasspathResource resource = new ClasspathResource("folder/foo");
- assertEquals("foo", resource.getName());
- assertTrue(resource.isExists());
- assertTrue(resource.isReadOnly());
-
- resource = new ClasspathResource("/folder/foo");
- assertEquals("foo", resource.getName());
- assertTrue(resource.isExists());
- assertTrue(resource.isReadOnly());
-
- String result = resource.read(new Func<InputStream, String>() {
- @Override
- public String eval(InputStream inputStream) {
- return FileHelper.readInputStreamAsString(inputStream, "UTF8");
- }
- });
- assertEquals("bar-baz", result);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java b/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java
deleted file mode 100644
index d3c5ebf..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/CollectionUtilsTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class CollectionUtilsTest extends TestCase {
-
- public void testArray1() throws Exception {
- String[] result = CollectionUtils.array(new String[] { "foo", "bar" },
- "hello", "world");
- assertEquals("[foo, bar, hello, world]", Arrays.toString(result));
- }
-
- public void testArray2() throws Exception {
- Object[] existingArray = new Object[] { 'c' };
- Object[] result = CollectionUtils.array(existingArray, "foo", 1, "bar");
-
- assertEquals("[c, foo, 1, bar]", Arrays.toString(result));
- }
-
- public void testConcat() throws Exception {
- List<String> list1 = new ArrayList<String>();
- list1.add("hello");
- list1.add("hello");
- list1.add("world");
- List<String> list2 = new ArrayList<String>();
- list2.add("howdy");
- list2.add("world");
- List<String> list3 = new ArrayList<String>();
- list3.add("hi");
- list3.add("world");
-
- List<String> result = CollectionUtils.concat(true, list1, list2, list3);
- assertEquals("[hello, world, howdy, hi]", result.toString());
- assertEquals(4, result.size());
-
- result = CollectionUtils.concat(false, list1, list2, list3);
- assertEquals("[hello, hello, world, howdy, world, hi, world]",
- result.toString());
- assertEquals(7, result.size());
- }
-
- public void testMap() throws Exception {
- List<String> strings = new ArrayList<String>();
- strings.add("hi");
- strings.add("world");
-
- List<Integer> ints = CollectionUtils.map(strings,
- new Func<String, Integer>() {
- @Override
- public Integer eval(String arg) {
- return arg.length();
- }
- });
- assertEquals("[2, 5]", ints.toString());
- }
-
- public void testFilter() throws Exception {
- List<String> list = new ArrayList<String>();
- list.add("foo");
- list.add("bar");
- list.add("3");
- list.add("2");
-
- list = CollectionUtils.filter(list, new Predicate<String>() {
- @Override
- public Boolean eval(String arg) {
- return arg.length() > 1;
- }
- });
-
- assertEquals(2, list.size());
- assertEquals("[foo, bar]", list.toString());
- }
-
- public void testArrayRemove() throws Exception {
- String[] arr = new String[] { "a", "b", "c", "d", "e" };
- arr = CollectionUtils.arrayRemove(arr, "c");
- assertEquals("[a, b, d, e]", Arrays.toString(arr));
-
- arr = CollectionUtils.arrayRemove(arr, "e");
- assertEquals("[a, b, d]", Arrays.toString(arr));
-
- arr = CollectionUtils.arrayRemove(arr, "e");
- assertEquals("[a, b, d]", Arrays.toString(arr));
-
- arr = CollectionUtils.arrayRemove(arr, "a");
- assertEquals("[b, d]", Arrays.toString(arr));
- }
-
- public void testToList() throws Exception {
- assertTrue(CollectionUtils.toList(null).isEmpty());
- assertEquals("[foo]", CollectionUtils.toList("foo").toString());
- assertEquals("[foo, bar]",
- CollectionUtils.toList(new String[] { "foo", "bar" })
- .toString());
-
- List<Integer> ints = Arrays.asList(1, 2, 3);
- assertSame(ints, CollectionUtils.toList(ints));
-
- assertEquals("[1, 2, 3]", CollectionUtils.toList(ints.iterator())
- .toString());
- assertEquals("[1, 2, 3]",
- CollectionUtils.toList(new HashSet<Integer>(ints)).toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java b/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java
deleted file mode 100644
index b1bd885..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/DateUtilsTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-public class DateUtilsTest extends TestCase {
-
- public void testGet() throws Exception {
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
- Date christmasDay = DateUtils.get(2010, Month.DECEMBER, 24);
- assertEquals("2010-12-24 00:00:00", f.format(christmasDay));
- assertEquals(Weekday.FRIDAY, DateUtils.getWeekday(christmasDay));
-
- Date date2 = DateUtils.get(christmasDay, 1);
- assertEquals("2010-12-25 00:00:00", f.format(date2));
-
- Date date3 = DateUtils.get(christmasDay, 10);
- assertEquals("2011-01-03 00:00:00", f.format(date3));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java
deleted file mode 100644
index 78649a8..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/EqualsBuilderTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class EqualsBuilderTest extends TestCase {
-
- public void testEquals() throws Exception {
- assertTrue(EqualsBuilder.equals(null, null));
- assertTrue(EqualsBuilder.equals("hello", "hello"));
- assertFalse(EqualsBuilder.equals("hello", null));
- assertFalse(EqualsBuilder.equals(null, "hello"));
- assertFalse(EqualsBuilder.equals("world", "hello"));
-
- MyCloneable o1 = new MyCloneable();
- assertTrue(EqualsBuilder.equals(o1, o1));
- MyCloneable o2 = o1.clone();
- assertFalse(EqualsBuilder.equals(o1, o2));
- }
-
- static final class MyCloneable implements Cloneable {
- @Override
- public boolean equals(Object obj) {
- return false;
- }
-
- @Override
- public MyCloneable clone() {
- try {
- return (MyCloneable) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new UnsupportedOperationException();
- }
- }
- };
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java b/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java
deleted file mode 100644
index f2d9237..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ExclusionPredicateTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class ExclusionPredicateTest extends TestCase {
-
- public void testEval() throws Exception {
- ExclusionPredicate<String> predicate = new ExclusionPredicate<String>(Arrays.asList("foo","bar","baz"));
-
- assertFalse(predicate.eval("foo"));
- assertFalse(predicate.eval("bar"));
- assertFalse(predicate.eval("baz"));
-
- assertTrue(predicate.eval("hello world"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java b/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java
deleted file mode 100644
index f51553f..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/FileHelperTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.io.File;
-
-import junit.framework.TestCase;
-
-public class FileHelperTest extends TestCase {
-
- public void testGetTempDir() throws Exception {
- File tempDir = FileHelper.getTempDir();
- String property = System.getProperty("java.io.tmpdir");
- assertEquals(normalize(property), normalize(tempDir.getPath()));
- }
-
- private String normalize(String path) {
- if (path == null) {
- return null;
- }
- if (path.endsWith(File.separator)) {
- path = path.substring(0, path.length() - 1);
- }
- return path;
- }
-
- public void testWriteAndRead() throws Exception {
- File file = new File("target/tmp/FileHelperTest.testWriteAndRead.txt");
- if (file.exists()) {
- file.delete();
- }
- file.getParentFile().mkdirs();
- assertTrue(file.createNewFile());
- FileHelper.writeStringAsFile(file, "foo\nbar");
- String content = FileHelper.readFileAsString(file);
- assertEquals("foo\nbar", content);
- assertTrue(file.delete());
- }
-
- public void testByteOrderMarksInputStream() throws Exception {
- String str1 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16.txt"));
- assertEquals("hello", str1);
-
- String str2 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf8.txt"));
- assertEquals(str1, str2);
-
- String str3 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16le.txt"));
- assertEquals(str2, str3);
-
- String str4 = FileHelper.readFileAsString(new File("src/test/resources/unicode-text-utf16be.txt"));
- assertEquals(str3, str4);
- }
-
- public void testCannotAppendAndInsertBom() throws Exception {
- try {
- FileHelper.getWriter(new File("foo"), "foo", true, true);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Can not insert BOM into appending writer", e.getMessage());
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java b/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java
deleted file mode 100644
index eebe345..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/FormatHelperTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.text.NumberFormat;
-import java.util.Arrays;
-
-import org.eobjects.metamodel.schema.ColumnType;
-
-import junit.framework.TestCase;
-
-public class FormatHelperTest extends TestCase {
-
- public void testNumberFormat() throws Exception {
- NumberFormat format = FormatHelper.getUiNumberFormat();
- assertEquals("987643.21", format.format(987643.213456343));
- assertEquals("0.22", format.format(0.218456343));
- assertEquals("20.1", format.format(20.1));
- }
-
- @SuppressWarnings("unchecked")
- public void testFormatSqlValue() throws Exception {
- assertEquals("'foo'", FormatHelper.formatSqlValue(null, "foo"));
- assertEquals("1", FormatHelper.formatSqlValue(null, 1));
- assertEquals("NULL", FormatHelper.formatSqlValue(null, null));
- assertEquals(
- "TIMESTAMP '2011-07-24 00:00:00'",
- FormatHelper.formatSqlValue(ColumnType.TIMESTAMP,
- DateUtils.get(2011, Month.JULY, 24)));
- assertEquals(
- "DATE '2011-07-24'",
- FormatHelper.formatSqlValue(ColumnType.DATE,
- DateUtils.get(2011, Month.JULY, 24)));
- assertEquals(
- "TIME '00:00:00'",
- FormatHelper.formatSqlValue(ColumnType.TIME,
- DateUtils.get(2011, Month.JULY, 24)));
- assertEquals(
- "('foo' , 1 , 'bar' , 0.1234)",
- FormatHelper.formatSqlValue(null,
- Arrays.asList("foo", 1, "bar", 0.1234)));
- assertEquals(
- "('foo' , 1 , 'bar' , 0.1234)",
- FormatHelper.formatSqlValue(null, new Object[] { "foo", 1,
- "bar", 0.1234 }));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java b/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java
deleted file mode 100644
index ee2995d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/InMemoryResourceTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import junit.framework.TestCase;
-
-public class InMemoryResourceTest extends TestCase {
-
- public void testScenario() throws Exception {
- InMemoryResource r = new InMemoryResource("foo/bar");
- assertEquals("bar", r.getName());
- assertEquals(-1, r.getLastModified());
- assertEquals(0, r.getSize());
- assertFalse(r.isReadOnly());
- assertTrue(r.isExists());
-
- r.write(new Action<OutputStream>() {
- @Override
- public void run(OutputStream out) throws Exception {
- out.write(1);
- out.write(2);
- out.write(3);
- }
- });
-
- assertEquals(3, r.getSize());
-
- r.read(new Action<InputStream>() {
- @Override
- public void run(InputStream in) throws Exception {
- assertEquals(1, in.read());
- assertEquals(2, in.read());
- assertEquals(3, in.read());
- assertEquals(-1, in.read());
- }
- });
-
- r.append(new Action<OutputStream>() {
- @Override
- public void run(OutputStream out) throws Exception {
- out.write(4);
- out.write(5);
- out.write(6);
- }
- });
-
- r.read(new Action<InputStream>() {
- @Override
- public void run(InputStream in) throws Exception {
- assertEquals(1, in.read());
- assertEquals(2, in.read());
- assertEquals(3, in.read());
- assertEquals(4, in.read());
- assertEquals(5, in.read());
- assertEquals(6, in.read());
- assertEquals(-1, in.read());
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java b/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java
deleted file mode 100644
index 0225aff..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/InclusionPredicateTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class InclusionPredicateTest extends TestCase {
-
- public void testEval() throws Exception {
- InclusionPredicate<String> predicate = new InclusionPredicate<String>(Arrays.asList("foo","bar","baz"));
-
- assertTrue(predicate.eval("foo"));
- assertTrue(predicate.eval("bar"));
- assertTrue(predicate.eval("baz"));
-
- assertFalse(predicate.eval("hello world"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java b/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java
deleted file mode 100644
index f68fb96..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/LazyRefTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-import junit.framework.TestCase;
-
-public class LazyRefTest extends TestCase {
-
- public void testRequestLoad() throws Exception {
- LazyRef<Integer> lazyRef = new LazyRef<Integer>() {
- private final AtomicInteger counter = new AtomicInteger();
-
- @Override
- protected Integer fetch() {
- return counter.incrementAndGet();
- }
- };
-
- lazyRef.requestLoad();
- Thread.sleep(20);
- Integer integer = lazyRef.get();
- assertEquals(1, integer.intValue());
- }
-
- public void testErrorHandling() throws Exception {
- LazyRef<Object> ref = new LazyRef<Object>() {
- @Override
- protected Object fetch() throws Throwable {
- throw new Exception("foo");
- }
- };
-
- assertNull(ref.get());
- assertEquals("foo", ref.getError().getMessage());
-
- // now with a runtime exception (retain previous behaviour in this
- // regard)
- ref = new LazyRef<Object>() {
- @Override
- protected Object fetch() throws Throwable {
- throw new IllegalStateException("bar");
- }
- };
-
- try {
- ref.get();
- fail("Exception expected");
- } catch (IllegalStateException e) {
- assertEquals("bar", e.getMessage());
- }
- }
-
- public void testGet() throws Exception {
- final AtomicInteger counter = new AtomicInteger();
- LazyRef<String> lazyRef = new LazyRef<String>() {
- @Override
- protected String fetch() {
- counter.incrementAndGet();
- return "foo";
- }
- };
-
- assertFalse(lazyRef.isFetched());
- assertEquals(0, counter.get());
-
- assertEquals("foo", lazyRef.get());
- assertEquals("foo", lazyRef.get());
- assertEquals("foo", lazyRef.get());
-
- assertTrue(lazyRef.isFetched());
- assertEquals(1, counter.get());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java b/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java
deleted file mode 100644
index 528caed..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/MonthTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class MonthTest extends TestCase {
-
- public void testGetName() throws Exception {
- assertEquals("December", Month.DECEMBER.getName());
- }
-
- public void testNext() throws Exception {
- assertEquals(Month.APRIL, Month.MARCH.next());
- assertEquals(Month.JANUARY, Month.DECEMBER.next());
- }
-
- public void testPrevious() throws Exception {
- assertEquals(Month.FEBRUARY, Month.MARCH.previous());
- assertEquals(Month.DECEMBER, Month.JANUARY.previous());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java
deleted file mode 100644
index 211c967..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/NumberComparatorTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-
-public class NumberComparatorTest extends TestCase {
-
- public void testDoubleAndIntegerComparison() throws Exception {
- Comparator<Object> comparator = NumberComparator.getComparator();
- assertEquals(0, comparator.compare(1, 1.0));
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = NumberComparator.getComparable("125");
- assertEquals(0, comparable.compareTo(125));
- assertEquals(-1, comparable.compareTo(126));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java
deleted file mode 100644
index 925318c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ObjectComparatorTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.TreeSet;
-
-import junit.framework.TestCase;
-
-public class ObjectComparatorTest extends TestCase {
-
- public void testString() throws Exception {
- Comparator<Object> c = ObjectComparator.getComparator();
- assertTrue(c.compare("aaaa", "bbbb") < 0);
-
- assertTrue(c.compare("w", "y") < 0);
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = ObjectComparator.getComparable("aaaa");
- assertEquals(-1, comparable.compareTo("bbbb"));
- }
-
- public void testNull() throws Exception {
- Comparator<Object> comparator = ObjectComparator.getComparator();
- assertEquals(0, comparator.compare(null, null));
- assertEquals(1, comparator.compare("h", null));
- assertEquals(-1, comparator.compare(null, "h"));
-
- TreeSet<Object> set = new TreeSet<Object>(comparator);
- set.add("Hello");
- set.add(null);
- set.add(null);
- set.add(DateUtils.get(2010, Month.SEPTEMBER, 27));
- set.add(DateUtils.get(2010, Month.SEPTEMBER, 28));
- set.add(DateUtils.get(2010, Month.SEPTEMBER, 26));
-
- assertEquals(5, set.size());
- Iterator<Object> it = set.iterator();
- assertEquals(null, it.next());
- assertEquals("Hello", it.next());
- assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 26), it.next());
- assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 27), it.next());
- assertEquals(DateUtils.get(2010, Month.SEPTEMBER, 28), it.next());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java b/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java
deleted file mode 100644
index 6e1c05e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/SerializableRefTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.StringTokenizer;
-
-import junit.framework.TestCase;
-
-public class SerializableRefTest extends TestCase {
-
- public void testSerialize() throws Exception {
- SerializableRef<String> ref = new SerializableRef<String>("Foobar");
- assertNotNull(ref.get());
-
- SerializableRef<String> copy = copy(ref);
- assertEquals("Foobar", copy.get());
- }
-
- public void testDontSerialize() throws Exception {
- SerializableRef<StringTokenizer> ref = new SerializableRef<StringTokenizer>(new StringTokenizer("foobar"));
- assertNotNull(ref.get());
-
- SerializableRef<StringTokenizer> copy = copy(ref);
- assertNull(copy.get());
- }
-
- @SuppressWarnings("unchecked")
- private <E> SerializableRef<E> copy(SerializableRef<E> ref) throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream os = new ObjectOutputStream(baos);
- os.writeObject(ref);
- os.flush();
- os.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream is = new ObjectInputStream(bais);
- Object obj = is.readObject();
- is.close();
- return (SerializableRef<E>) obj;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java b/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java
deleted file mode 100644
index fcc89c3..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/SimpleRefTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class SimpleRefTest extends TestCase {
-
- public void testGet() throws Exception {
- Ref<String> lazyRef = new ImmutableRef<String>("foo");
-
- assertEquals("foo", lazyRef.get());
-
- lazyRef = ImmutableRef.of("foo");
-
- assertEquals("foo", lazyRef.get());
- assertEquals("foo", lazyRef.get());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java
deleted file mode 100644
index 4b43dcb..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/TimeComparatorTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.text.DateFormat;
-import java.util.Comparator;
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-public class TimeComparatorTest extends TestCase {
-
- public void testCompare() throws Exception {
- Comparator<Object> c = TimeComparator.getComparator();
- Date d1 = new Date();
- Thread.sleep(100);
- Date d2 = new Date();
- assertEquals(0, c.compare(d1, d1));
- assertEquals(-1, c.compare(d1, d2));
- assertEquals(1, c.compare(d2, d1));
-
- assertEquals(1, c.compare(d2, "2005-10-08"));
- assertEquals(1, c.compare("2006-11-09", "2005-10-08"));
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = TimeComparator
- .getComparable(new Date());
- Thread.sleep(100);
- assertEquals(-1, comparable.compareTo(new Date()));
- }
-
- public void testToDate() throws Exception {
- DateFormat dateFormat = DateUtils
- .createDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-
- assertEquals("2008-11-04 00:00:00.000",
- dateFormat.format(TimeComparator.toDate("08-11-04")));
-
- assertEquals("2010-09-21 14:06:00.000",
- dateFormat.format(TimeComparator.toDate("2010-09-21 14:06")));
-
- assertEquals("2010-09-21 14:06:13.000",
- dateFormat.format(TimeComparator.toDate("2010-09-21 14:06:13")));
-
- assertEquals("2010-09-21 14:06:13.009",
- dateFormat.format(TimeComparator
- .toDate("2010-09-21 14:06:13.009")));
-
- assertEquals("2000-12-31 02:30:05.100",
- dateFormat.format(TimeComparator
- .toDate("2000-12-31 02:30:05.100")));
- }
-
- public void testToDateOfDateToString() throws Exception {
- Date date = new Date();
- String dateString = date.toString();
- Date convertedDate = TimeComparator.toDate(dateString);
-
- String convertedToString = convertedDate.toString();
- assertEquals(dateString, convertedToString);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java b/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java
deleted file mode 100644
index 684c714..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/ToStringComparatorTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import java.util.Comparator;
-
-import junit.framework.TestCase;
-import org.eobjects.metamodel.util.ToStringComparator;
-
-public class ToStringComparatorTest extends TestCase {
-
- private Comparator<Object> comparator = ToStringComparator.getComparator();
-
- public void testNotNull() throws Exception {
- assertEquals(4, comparator.compare("foo", "bar"));
- assertEquals(-4, comparator.compare("bar", "foo"));
- }
-
- public void testNull() throws Exception {
- int result = comparator.compare(null, null);
- assertEquals(-1, result);
-
- result = comparator.compare(1, null);
- assertEquals(1, result);
-
- result = comparator.compare(null, 1);
- assertEquals(-1, result);
- }
-
- public void testComparable() throws Exception {
- Comparable<Object> comparable = ToStringComparator
- .getComparable("aaaa");
- assertEquals(-1, comparable.compareTo("bbbb"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java b/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java
deleted file mode 100644
index a94eee2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/UrlResourceTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class UrlResourceTest extends TestCase {
-
- public void testGetName() throws Exception {
- UrlResource resource = new UrlResource("http://eobjects.org/foo.txt");
- assertEquals("foo.txt", resource.getName());
-
- resource = new UrlResource("http://eobjects.org/");
- assertEquals("http://eobjects.org/", resource.getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java b/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java
deleted file mode 100644
index f5f7bb6..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/WeekdayTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class WeekdayTest extends TestCase {
-
- public void testGetName() throws Exception {
- assertEquals("Monday", Weekday.MONDAY.getName());
- }
-
- public void testNext() throws Exception {
- assertEquals(Weekday.TUESDAY, Weekday.MONDAY.next());
- assertEquals(Weekday.MONDAY, Weekday.SUNDAY.next());
- }
-
- public void testPrevious() throws Exception {
- assertEquals(Weekday.SUNDAY, Weekday.MONDAY.previous());
- assertEquals(Weekday.SATURDAY, Weekday.SUNDAY.previous());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java b/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java
deleted file mode 100644
index 13da97b..0000000
--- a/core/src/test/java/org/eobjects/metamodel/util/WildcardPatternTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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.eobjects.metamodel.util;
-
-import junit.framework.TestCase;
-
-public class WildcardPatternTest extends TestCase {
-
- public void testMatches() throws Exception {
- WildcardPattern pattern = new WildcardPattern("foo%bar", '%');
- assertTrue(pattern.matches("foobar"));
- assertTrue(pattern.matches("foofoobar"));
- assertFalse(pattern.matches("foobarbar"));
- assertFalse(pattern.matches("w00p"));
-
- pattern = new WildcardPattern("*foo*bar", '*');
- assertTrue(pattern.matches("foobar"));
- assertTrue(pattern.matches("foofoobar"));
- assertFalse(pattern.matches("foobarbar"));
- assertFalse(pattern.matches("w00p"));
-
- pattern = new WildcardPattern("foo%bar%", '%');
- assertTrue(pattern.matches("foobar"));
- assertTrue(pattern.matches("foofoobar"));
- assertTrue(pattern.matches("foobarbar"));
- assertFalse(pattern.matches("w00p"));
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
----------------------------------------------------------------------
diff --git a/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
new file mode 100644
index 0000000..ac626e6
--- /dev/null
+++ b/couchdb/src/main/java/org/apache/metamodel/couchdb/CouchDbDataContext.java
@@ -0,0 +1,254 @@
+/**
+ * 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.eobjects.metamodel.couchdb;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.codehaus.jackson.JsonNode;
+import org.ektorp.CouchDbConnector;
+import org.ektorp.CouchDbInstance;
+import org.ektorp.StreamingViewResult;
+import org.ektorp.ViewQuery;
+import org.ektorp.ViewResult.Row;
+import org.ektorp.http.HttpClient;
+import org.ektorp.http.StdHttpClient;
+import org.ektorp.impl.StdCouchDbInstance;
+import org.eobjects.metamodel.MetaModelException;
+import org.eobjects.metamodel.MetaModelHelper;
+import org.eobjects.metamodel.QueryPostprocessDataContext;
+import org.eobjects.metamodel.UpdateScript;
+import org.eobjects.metamodel.UpdateableDataContext;
+import org.eobjects.metamodel.data.DataSet;
+import org.eobjects.metamodel.query.FilterItem;
+import org.eobjects.metamodel.query.SelectItem;
+import org.eobjects.metamodel.schema.Column;
+import org.eobjects.metamodel.schema.ColumnType;
+import org.eobjects.metamodel.schema.MutableSchema;
+import org.eobjects.metamodel.schema.MutableTable;
+import org.eobjects.metamodel.schema.Schema;
+import org.eobjects.metamodel.schema.Table;
+import org.eobjects.metamodel.util.SimpleTableDef;
+
+/**
+ * DataContext implementation for CouchDB
+ */
+public class CouchDbDataContext extends QueryPostprocessDataContext implements UpdateableDataContext {
+
+ public static final int DEFAULT_PORT = 5984;
+
+ public static final String FIELD_ID = "_id";
+ public static final String FIELD_REV = "_rev";
+
+ private static final String SCHEMA_NAME = "CouchDB";
+
+ private final CouchDbInstance _couchDbInstance;
+ private final SimpleTableDef[] _tableDefs;
+
+ public CouchDbDataContext(StdHttpClient.Builder httpClientBuilder, SimpleTableDef... tableDefs) {
+ this(httpClientBuilder.build(), tableDefs);
+ }
+
+ public CouchDbDataContext(StdHttpClient.Builder httpClientBuilder) {
+ this(httpClientBuilder.build());
+ }
+
+ public CouchDbDataContext(HttpClient httpClient, SimpleTableDef... tableDefs) {
+ this(new StdCouchDbInstance(httpClient), tableDefs);
+ }
+
+ public CouchDbDataContext(HttpClient httpClient) {
+ this(new StdCouchDbInstance(httpClient));
+ }
+
+ public CouchDbDataContext(CouchDbInstance couchDbInstance) {
+ this(couchDbInstance, detectSchema(couchDbInstance));
+ }
+
+ public CouchDbDataContext(CouchDbInstance couchDbInstance, SimpleTableDef... tableDefs) {
+ // the instance represents a handle to the whole couchdb cluster
+ _couchDbInstance = couchDbInstance;
+ _tableDefs = tableDefs;
+ }
+
+ public static SimpleTableDef[] detectSchema(CouchDbInstance couchDbInstance) {
+ final List<SimpleTableDef> tableDefs = new ArrayList<SimpleTableDef>();
+ final List<String> databaseNames = couchDbInstance.getAllDatabases();
+ for (final String databaseName : databaseNames) {
+
+ if (databaseName.startsWith("_")) {
+ // don't add system tables
+ continue;
+ }
+
+ CouchDbConnector connector = couchDbInstance.createConnector(databaseName, false);
+
+ SimpleTableDef tableDef = detectTable(connector);
+ tableDefs.add(tableDef);
+ }
+ return tableDefs.toArray(new SimpleTableDef[tableDefs.size()]);
+ }
+
+ public static SimpleTableDef detectTable(CouchDbConnector connector) {
+ final SortedMap<String, Set<ColumnType>> columnsAndTypes = new TreeMap<String, Set<ColumnType>>();
+
+ final StreamingViewResult streamingView = connector.queryForStreamingView(new ViewQuery().allDocs().includeDocs(true)
+ .limit(1000));
+ try {
+ final Iterator<Row> rowIterator = streamingView.iterator();
+ while (rowIterator.hasNext()) {
+ Row row = rowIterator.next();
+ JsonNode doc = row.getDocAsNode();
+
+ final Iterator<Entry<String, JsonNode>> fieldIterator = doc.getFields();
+ while (fieldIterator.hasNext()) {
+ Entry<String, JsonNode> entry = fieldIterator.next();
+ String key = entry.getKey();
+
+ Set<ColumnType> types = columnsAndTypes.get(key);
+
+ if (types == null) {
+ types = EnumSet.noneOf(ColumnType.class);
+ columnsAndTypes.put(key, types);
+ }
+
+ JsonNode value = entry.getValue();
+ if (value == null || value.isNull()) {
+ // do nothing
+ } else if (value.isTextual()) {
+ types.add(ColumnType.VARCHAR);
+ } else if (value.isArray()) {
+ types.add(ColumnType.LIST);
+ } else if (value.isObject()) {
+ types.add(ColumnType.MAP);
+ } else if (value.isBoolean()) {
+ types.add(ColumnType.BOOLEAN);
+ } else if (value.isInt()) {
+ types.add(ColumnType.INTEGER);
+ } else if (value.isLong()) {
+ types.add(ColumnType.BIGINT);
+ } else if (value.isDouble()) {
+ types.add(ColumnType.DOUBLE);
+ }
+ }
+
+ }
+ } finally {
+ streamingView.close();
+ }
+
+ final String[] columnNames = new String[columnsAndTypes.size()];
+ final ColumnType[] columnTypes = new ColumnType[columnsAndTypes.size()];
+
+ int i = 0;
+ for (Entry<String, Set<ColumnType>> columnAndTypes : columnsAndTypes.entrySet()) {
+ final String columnName = columnAndTypes.getKey();
+ final Set<ColumnType> columnTypeSet = columnAndTypes.getValue();
+ final ColumnType columnType;
+ if (columnTypeSet.isEmpty()) {
+ columnType = ColumnType.OTHER;
+ } else if (columnTypeSet.size() == 1) {
+ columnType = columnTypeSet.iterator().next();
+ } else {
+ // TODO: Select best type?
+ columnType = ColumnType.OTHER;
+ }
+ columnNames[i] = columnName;
+ columnTypes[i] = columnType;
+ i++;
+ }
+
+ final SimpleTableDef tableDef = new SimpleTableDef(connector.getDatabaseName(), columnNames, columnTypes);
+ return tableDef;
+ }
+
+ public CouchDbInstance getCouchDbInstance() {
+ return _couchDbInstance;
+ }
+
+ @Override
+ protected Schema getMainSchema() throws MetaModelException {
+ final MutableSchema schema = new MutableSchema(SCHEMA_NAME);
+ for (final SimpleTableDef tableDef : _tableDefs) {
+ final MutableTable table = tableDef.toTable().setSchema(schema);
+ CouchDbTableCreationBuilder.addMandatoryColumns(table);
+ schema.addTable(table);
+ }
+ return schema;
+ }
+
+ @Override
+ protected String getMainSchemaName() throws MetaModelException {
+ return SCHEMA_NAME;
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int firstRow, int maxRows) {
+ // the connector represents a handle to the the couchdb "database".
+ final String databaseName = table.getName();
+ final CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
+
+ ViewQuery query = new ViewQuery().allDocs().includeDocs(true);
+
+ if (maxRows > 0) {
+ query = query.limit(maxRows);
+ }
+ if (firstRow > 1) {
+ final int skip = firstRow - 1;
+ query = query.skip(skip);
+ }
+
+ final StreamingViewResult streamingView = connector.queryForStreamingView(query);
+
+ final SelectItem[] selectItems = MetaModelHelper.createSelectItems(columns);
+ return new CouchDbDataSet(selectItems, streamingView);
+ }
+
+ @Override
+ protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
+ return materializeMainSchemaTable(table, columns, 1, maxRows);
+ }
+
+ @Override
+ protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) {
+ if (whereItems.isEmpty()) {
+ String databaseName = table.getName();
+ CouchDbConnector connector = _couchDbInstance.createConnector(databaseName, false);
+ long docCount = connector.getDbInfo().getDocCount();
+ return docCount;
+ }
+ return null;
+ }
+
+ @Override
+ public void executeUpdate(UpdateScript script) {
+ CouchDbUpdateCallback callback = new CouchDbUpdateCallback(this);
+ try {
+ script.run(callback);
+ } finally {
+ callback.close();
+ }
+ }
+}