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:04 UTC
[21/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/convert/StringToDoubleConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java b/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java
deleted file mode 100644
index a44fa1d..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/StringToDoubleConverterTest.java
+++ /dev/null
@@ -1,39 +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.convert;
-
-import junit.framework.TestCase;
-
-public class StringToDoubleConverterTest extends TestCase {
-
- private StringToDoubleConverter conv = new StringToDoubleConverter();
-
- public void testToVirtual() throws Exception {
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
- assertEquals(123d, conv.toVirtualValue("123").doubleValue());
- assertEquals(123.0d, conv.toVirtualValue("123.0").doubleValue());
- }
-
- public void testToPhysical() throws Exception {
- assertNull(conv.toPhysicalValue(null));
- assertEquals("123.0", conv.toPhysicalValue(123d));
- assertEquals("123.0", conv.toPhysicalValue(123.0d));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java b/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.java
deleted file mode 100644
index 41c301e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/convert/StringToIntegerConverterTest.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.convert;
-
-import junit.framework.TestCase;
-
-public class StringToIntegerConverterTest extends TestCase {
-
- private StringToIntegerConverter conv = new StringToIntegerConverter();
-
- public void testToVirtual() throws Exception {
- assertNull(conv.toVirtualValue(null));
- assertNull(conv.toVirtualValue(""));
- assertEquals(123, conv.toVirtualValue("123").intValue());
- }
-
- public void testToPhysical() throws Exception {
- assertNull(conv.toPhysicalValue(null));
- assertEquals("123", conv.toPhysicalValue(123));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java
deleted file mode 100644
index b5a44aa..0000000
--- a/core/src/test/java/org/eobjects/metamodel/create/AbstractCreateTableBuilderTest.java
+++ /dev/null
@@ -1,110 +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.create;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-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.MutableRef;
-
-public class AbstractCreateTableBuilderTest extends TestCase {
-
- public void testExecute() throws Exception {
- final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
-
- Schema schema = new MutableSchema("schema");
- AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
- schema, "tablename") {
- @Override
- public Table execute() throws MetaModelException {
- executed.set(true);
- return getTable();
- }
- };
-
- assertFalse(executed.get().booleanValue());
-
- builder.withColumn("foo").ofType(ColumnType.VARCHAR).asPrimaryKey().ofNativeType("vch").ofSize(1234)
- .nullable(true);
- builder.withColumn("bar").withColumn("baz").nullable(false);
- Table table = builder.execute();
-
- assertTrue(executed.get().booleanValue());
-
- assertEquals("tablename", table.getName());
- assertEquals(3, table.getColumnCount());
- assertEquals(
- "Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
- table.getColumns()[0].toString());
- assertEquals(
- "Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
- table.getColumns()[1].toString());
- assertEquals(
- "Column[name=baz,columnNumber=2,type=null,nullable=false,nativeType=null,columnSize=null]",
- table.getColumns()[2].toString());
-
- assertEquals("CREATE TABLE schema.tablename (foo VARCHAR(1234) PRIMARY KEY,bar,baz NOT NULL)", builder.toSql());
- }
-
- public void testLike() throws Exception {
- final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
-
- Schema schema = new MutableSchema("schema");
- AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
- schema, "tablename") {
- @Override
- public Table execute() throws MetaModelException {
- executed.set(true);
- return toTable();
- }
- };
-
- assertFalse(executed.get().booleanValue());
-
- MutableTable likeTable = new MutableTable("blablablabla");
- likeTable.addColumn(new MutableColumn("foo", ColumnType.VARCHAR, likeTable, 0, 1234, "vch", true, null, false,
- null));
- likeTable.addColumn(new MutableColumn("bar"));
- likeTable.addColumn(new MutableColumn("baz"));
-
- builder.like(likeTable);
- Table table = builder.execute();
-
- assertTrue(executed.get().booleanValue());
-
- assertEquals("tablename", table.getName());
- assertEquals(3, table.getColumnCount());
- assertEquals(
- "Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
- table.getColumns()[0].toString());
- assertEquals(
- "Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
- table.getColumns()[1].toString());
- assertEquals(
- "Column[name=baz,columnNumber=2,type=null,nullable=null,nativeType=null,columnSize=null]",
- table.getColumns()[2].toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java b/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.java
deleted file mode 100644
index 264fd91..0000000
--- a/core/src/test/java/org/eobjects/metamodel/create/SyntaxExamplesTest.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.create;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public abstract class SyntaxExamplesTest extends TestCase {
-
- private TableCreatable dc;
- private Table table;
- private Column col;
- private Schema schema;
-
- public void testCreateLikeExistingStructure() throws Exception {
- dc.createTable(schema, "foo").like(table).withColumn("bar").like(col)
- .nullable(false).execute();
- }
-}
\ 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/data/DataSetIteratorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java b/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java
deleted file mode 100644
index 96443d2..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/DataSetIteratorTest.java
+++ /dev/null
@@ -1,74 +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.data;
-
-import org.easymock.EasyMock;
-
-import junit.framework.TestCase;
-
-public class DataSetIteratorTest extends TestCase {
-
- public void testHasNextAndNextAndClose() throws Exception {
- DataSet ds = EasyMock.createMock(DataSet.class);
- Row row = EasyMock.createMock(Row.class);
-
- EasyMock.expect(ds.next()).andReturn(true);
- EasyMock.expect(ds.getRow()).andReturn(row);
- EasyMock.expect(ds.next()).andReturn(true);
- EasyMock.expect(ds.getRow()).andReturn(row);
- EasyMock.expect(ds.next()).andReturn(false);
- ds.close();
-
- EasyMock.replay(ds, row);
-
- DataSetIterator it = new DataSetIterator(ds);
-
- // multiple hasNext calls does not iterate before next is called
- assertTrue(it.hasNext());
- assertTrue(it.hasNext());
- assertTrue(it.hasNext());
-
- assertSame(row, it.next());
-
- assertTrue(it.hasNext());
- assertTrue(it.hasNext());
-
- assertSame(row, it.next());
- assertFalse(it.hasNext());
- assertFalse(it.hasNext());
- assertFalse(it.hasNext());
-
- assertNull(it.next());
-
- EasyMock.verify(ds, row);
- }
-
- public void testRemove() throws Exception {
- DataSet ds = EasyMock.createMock(DataSet.class);
- DataSetIterator it = new DataSetIterator(ds);
-
- try {
- it.remove();
- fail("Exception expected");
- } catch (UnsupportedOperationException e) {
- assertEquals("DataSet is read-only, remove() is not supported.",
- e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java b/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java
deleted file mode 100644
index b125f8f..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/DataSetTableModelTest.java
+++ /dev/null
@@ -1,57 +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.data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.table.TableModel;
-
-import org.eobjects.metamodel.MetaModelHelper;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-
-import junit.framework.TestCase;
-
-public class DataSetTableModelTest extends TestCase {
-
- public void testToTableModel() throws Exception {
- SelectItem[] selectItems = MetaModelHelper.createSelectItems(new MutableColumn("CUSTOMERNUMBER"),
- new MutableColumn("CUSTOMERNAME"), new MutableColumn("CONTACTLASTNAME"));
- CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
- List<Row> rows = new ArrayList<Row>();
- rows.add(new DefaultRow(header, new Object[] { 1, "John", "Doe" }));
- rows.add(new DefaultRow(header, new Object[] { 2, "John", "Taylor" }));
- DataSet data = new InMemoryDataSet(header, rows);
-
- @SuppressWarnings("deprecation")
- TableModel tableModel = data.toTableModel();
- data.close();
-
- assertEquals(3, tableModel.getColumnCount());
- assertEquals("CUSTOMERNUMBER", tableModel.getColumnName(0));
- assertEquals("CUSTOMERNAME", tableModel.getColumnName(1));
- assertEquals("CONTACTLASTNAME", tableModel.getColumnName(2));
- assertEquals(2, tableModel.getRowCount());
-
- // Take a small sample from the data
- assertEquals("Taylor", tableModel.getValueAt(1, 2).toString());
-
- }
-}
\ 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/data/DefaultRowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java b/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java
deleted file mode 100644
index 0cac74f..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/DefaultRowTest.java
+++ /dev/null
@@ -1,109 +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.data;
-
-import java.io.FileInputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Field;
-
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.util.FileHelper;
-
-import junit.framework.TestCase;
-
-public class DefaultRowTest extends TestCase {
-
- SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foo")),
- new SelectItem(new MutableColumn("bar")) };
- Object[] values = new Object[] { "foo", "bar" };
-
- public void testDeserializeBackwardsCompatible() throws Exception {
- Object obj;
- FileInputStream fileIn = new FileInputStream("src/test/resources/metamodel-3.0-default-row.ser");
- try {
- ObjectInputStream ois = new ObjectInputStream(fileIn);
- obj = ois.readObject();
- ois.close();
- } finally {
- FileHelper.safeClose(fileIn);
- }
-
- assertTrue(obj instanceof Row);
- assertTrue(obj instanceof DefaultRow);
-
- Row row = (Row) obj;
- assertEquals(2, row.size());
- SelectItem[] selectItems = row.getSelectItems();
- assertEquals("foo", selectItems[0].toString());
- assertEquals("bar", selectItems[1].toString());
-
- assertEquals("foo", row.getValue(0));
- assertEquals("bar", row.getValue(1));
-
- assertEquals(Style.NO_STYLE, row.getStyle(0));
- assertEquals(Style.NO_STYLE, row.getStyle(1));
- }
-
- public void testGetValueOfColumn() throws Exception {
- DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values);
- assertEquals("foo", row.getValue(new MutableColumn("foo")));
- assertNull(row.getValue(new MutableColumn("hello world")));
- }
-
- public void testCustomStyles() throws Exception {
- Style[] styles = new Style[] { Style.NO_STYLE, new StyleBuilder().bold().create() };
- DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values, styles);
-
- Field field = DefaultRow.class.getDeclaredField("_styles");
- assertNotNull(field);
-
- field.setAccessible(true);
- assertNotNull(field.get(row));
-
- assertEquals(Style.NO_STYLE, row.getStyle(0));
- assertEquals("font-weight: bold;", row.getStyle(1).toCSS());
- }
-
- public void testNoStylesReference() throws Exception {
- Style[] styles = new Style[] { Style.NO_STYLE, Style.NO_STYLE };
- DefaultRow row = new DefaultRow(new SimpleDataSetHeader(items), values, styles);
-
- Field field = DefaultRow.class.getDeclaredField("_styles");
- assertNotNull(field);
-
- field.setAccessible(true);
- assertNull(field.get(row));
-
- assertEquals(Style.NO_STYLE, row.getStyle(0));
- assertEquals(Style.NO_STYLE, row.getStyle(items[0]));
- assertEquals(Style.NO_STYLE, row.getStyle(items[0].getColumn()));
- }
-
- public void testNullStyle() throws Exception {
- Style[] styles = new Style[] { Style.NO_STYLE, null };
-
- try {
- new DefaultRow(new SimpleDataSetHeader(items), values, styles);
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Elements in the style array cannot be null", e.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java b/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java
deleted file mode 100644
index 645dbbe..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/FirstRowDataSetTest.java
+++ /dev/null
@@ -1,83 +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.data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-
-import junit.framework.TestCase;
-
-public class FirstRowDataSetTest extends TestCase {
-
- private List<Row> rows;
- private SelectItem[] items = new SelectItem[] { new SelectItem(new MutableColumn("foobar")) };
- private DataSetHeader header = new SimpleDataSetHeader(items);
- private InMemoryDataSet dataSet;
-
- protected void setUp() throws Exception {
- rows = new ArrayList<Row>();
- rows.add(new DefaultRow(header, new Object[] { 1 }));
- rows.add(new DefaultRow(header, new Object[] { 2 }));
- rows.add(new DefaultRow(header, new Object[] { 3 }));
- rows.add(new DefaultRow(header, new Object[] { 4 }));
- rows.add(new DefaultRow(header, new Object[] { 5 }));
- dataSet = new InMemoryDataSet(header, rows);
- };
-
- public void testHighestPossibleOffset() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 5);
- assertTrue(ds.next());
- assertEquals(5, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testOffsetHigherThanSize() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 8);
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testOneOffset() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 1);
- assertTrue(ds.next());
- assertEquals(1, ds.getRow().getValue(0));
- ds.close();
- }
-
- public void testVanillaScenario() throws Exception {
- FirstRowDataSet ds = new FirstRowDataSet(dataSet, 2);
- assertTrue(ds.next());
- assertEquals(2, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(3, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(4, ds.getRow().getValue(0));
- assertTrue(ds.next());
- assertEquals(5, ds.getRow().getValue(0));
- assertFalse(ds.next());
-
- ds.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java b/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java
deleted file mode 100644
index 03b078e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/RowPublisherDataSetTest.java
+++ /dev/null
@@ -1,89 +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.data;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.util.Action;
-
-public class RowPublisherDataSetTest extends TestCase {
-
- public void testMaxSize() throws Exception {
- SelectItem[] selectItems = new SelectItem[2];
- selectItems[0] = new SelectItem(new MutableColumn("foos"));
- selectItems[1] = new SelectItem(new MutableColumn("bars"));
- DataSet ds = new RowPublisherDataSet(selectItems, 5,
- new Action<RowPublisher>() {
- @Override
- public void run(RowPublisher publisher) throws Exception {
-
- // we want to exceed the buffer size
- int iterations = RowPublisherImpl.BUFFER_SIZE * 2;
-
- for (int i = 0; i < iterations; i++) {
- publisher.publish(new Object[] { "foo" + i,
- "bar" + i });
- }
- }
- });
-
- assertTrue(ds.next());
- assertEquals("Row[values=[foo0, bar0]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertTrue(ds.next());
- assertTrue(ds.next());
- assertTrue(ds.next());
- assertEquals("Row[values=[foo4, bar4]]", ds.getRow().toString());
- assertFalse(ds.next());
-
- ds.close();
- }
-
- public void testExceptionInAction() throws Exception {
- SelectItem[] selectItems = new SelectItem[2];
- selectItems[0] = new SelectItem(new MutableColumn("foos"));
- selectItems[1] = new SelectItem(new MutableColumn("bars"));
- DataSet ds = new RowPublisherDataSet(selectItems, 5,
- new Action<RowPublisher>() {
- @Override
- public void run(RowPublisher publisher) throws Exception {
- publisher.publish(new Object[] { "foo0", "bar0" });
- publisher.publish(new Object[] { "foo1", "bar1" });
- throw new IllegalStateException("foobar!");
- }
- });
-
- assertTrue(ds.next());
- assertEquals("Row[values=[foo0, bar0]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[foo1, bar1]]", ds.getRow().toString());
-
- try {
- ds.next();
- fail("Exception expected");
- } catch (Exception e) {
- assertEquals("foobar!", e.getMessage());
- assertEquals(IllegalStateException.class, e.getClass());
- } finally {
- ds.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/data/RowTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/RowTest.java b/core/src/test/java/org/eobjects/metamodel/data/RowTest.java
deleted file mode 100644
index 4c8628e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/RowTest.java
+++ /dev/null
@@ -1,57 +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.data;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class RowTest extends MetaModelTestCase {
-
- public void testRow() throws Exception {
- Schema schema = getExampleSchema();
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- SelectItem item = new SelectItem(projectTable.getColumns()[0]);
- SelectItem[] items = { item };
- DataSetHeader header = new CachingDataSetHeader(items);
- Object[] values = { "foobar" };
- Row row = new DefaultRow(header, values);
- assertEquals("Row[values=[foobar]]", row.toString());
- assertEquals("foobar", row.getValue(0));
- assertEquals("foobar", row.getValues()[0]);
- assertEquals("foobar", row.getValue(item));
- assertEquals(item, row.getSelectItems()[0]);
- }
-
- public void testGetSubSelection() throws Exception {
- Schema schema = getExampleSchema();
- Table projectTable = schema.getTableByName(TABLE_PROJECT);
- SelectItem item1 = new SelectItem(projectTable.getColumns()[0]);
- SelectItem item2 = new SelectItem(projectTable.getColumns()[0]);
- SelectItem[] items = { item1, item2 };
- DataSetHeader header = new CachingDataSetHeader(items);
- Object[] values = { "foo", "bar" };
- Row row = new DefaultRow(header, values);
- row = row.getSubSelection(new SimpleDataSetHeader(new SelectItem[] { item1 }));
- assertEquals(1, row.getSelectItems().length);
- assertEquals(1, row.getValues().length);
- assertEquals("foo", row.getValue(0));
- }
-}
\ 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/data/StyleBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java
deleted file mode 100644
index e75c5b0..0000000
--- a/core/src/test/java/org/eobjects/metamodel/data/StyleBuilderTest.java
+++ /dev/null
@@ -1,60 +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.data;
-
-import org.eobjects.metamodel.data.Style.Color;
-
-import junit.framework.TestCase;
-
-public class StyleBuilderTest extends TestCase {
-
- public void testDefaultColors() throws Exception {
- StyleBuilder sb = new StyleBuilder();
-
- sb.foreground(1, 1, 1);
- assertEquals("color: rgb(1,1,1);", sb.create().toCSS());
-
- sb.foreground(0, 0, 0);
- assertEquals("", sb.create().toCSS());
-
- sb.background(0, 0, 0);
- assertEquals("background-color: rgb(0,0,0);", sb.create().toCSS());
-
- sb.background(255, 255, 255);
- assertEquals("", sb.create().toCSS());
- }
-
- public void testCreateNoStyle() throws Exception {
- Style style = new StyleBuilder().create();
- assertEquals(Style.NO_STYLE, style);
- assertSame(Style.NO_STYLE, style);
- }
-
- public void testCreateColor() throws Exception {
- Color col1 = StyleBuilder.createColor("eeEE00");
- assertEquals("Color[238,238,0]", col1.toString());
-
- Color col2 = StyleBuilder.createColor(238, 238, 0);
-
- // cache should ensure that these two colors are not only equal, but
- // also the same!
- assertEquals(col1, col2);
- assertSame(col1, col2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java b/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java
deleted file mode 100644
index d5447ba..0000000
--- a/core/src/test/java/org/eobjects/metamodel/delete/AbstractRowDeletionCallbackTest.java
+++ /dev/null
@@ -1,76 +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.delete;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.schema.Table;
-
-public class AbstractRowDeletionCallbackTest extends TestCase {
-
- public void testDelete() throws Exception {
- final MockUpdateableDataContext dc = new MockUpdateableDataContext();
- final Table table = dc.getDefaultSchema().getTables()[0];
- DataSet ds = dc.query().from(table).selectCount().execute();
- assertTrue(ds.next());
- assertEquals("3", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- callback.update(table).value("bar", "baz").execute();
- callback.update(table).value("foo", "4").where("foo").eq("3").execute();
- }
- });
-
- ds = dc.query().from(table).select(table.getColumns()).execute();
- assertTrue(ds.next());
- assertEquals("Row[values=[1, baz]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[2, baz]]", ds.getRow().toString());
- assertTrue(ds.next());
- assertEquals("Row[values=[4, baz]]", ds.getRow().toString());
- assertFalse(ds.next());
- ds.close();
-
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback callback) {
- RowDeletionBuilder delete = callback.deleteFrom(table);
- assertEquals("DELETE FROM schema.table", delete.toSql());
- delete.execute();
-
- assertEquals("DELETE FROM schema.table WHERE table.bar = 'baz'", callback.deleteFrom(table).where("bar")
- .eq("baz").toSql());
- }
- });
-
- ds = dc.query().from(table).selectCount().execute();
- assertTrue(ds.next());
- assertEquals("0", ds.getRow().getValue(0).toString());
- assertFalse(ds.next());
- ds.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java b/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java
deleted file mode 100644
index 27249aa..0000000
--- a/core/src/test/java/org/eobjects/metamodel/insert/AbstractInsertBuilderTest.java
+++ /dev/null
@@ -1,92 +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.insert;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.util.MutableRef;
-
-public class AbstractInsertBuilderTest extends TestCase {
-
- public void testInsertValues() throws Exception {
- final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
- final MutableTable table = new MutableTable("foo");
- table.addColumn(new MutableColumn("foo"));
- table.addColumn(new MutableColumn("bar"));
- table.addColumn(new MutableColumn("baz"));
- RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
- null, table) {
- @Override
- public void execute() throws MetaModelException {
- assertEquals("[1, 2, 3]", Arrays.toString(getValues()));
- executed.set(true);
- }
- };
-
- assertFalse(executed.get().booleanValue());
-
- insertBuilder.value(0, 1).value("bar", 2)
- .value(table.getColumnByName("baz"), 3).execute();
-
- assertTrue(executed.get());
-
- assertEquals("Row[values=[1, 2, 3]]", insertBuilder.toRow().toString());
-
- }
-
- public void testIllegalArguments() throws Exception {
- final MutableTable table = new MutableTable("foo");
- table.addColumn(new MutableColumn("foo"));
- RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
- null, table) {
- @Override
- public void execute() throws MetaModelException {
- }
- };
-
- try {
- insertBuilder.value((Column)null, "foo");
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("Column cannot be null", e.getMessage());
- }
-
- try {
- insertBuilder.value("hmm", "foo");
- fail("Exception expected");
- } catch (IllegalArgumentException e) {
- assertEquals("No such column in table: hmm, available columns are: [Column[name=foo,columnNumber=0,type=null,nullable=null,nativeType=null,columnSize=null]]", e.getMessage());
- }
-
- try {
- insertBuilder.value(4, "foo");
- fail("Exception expected");
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue("4".equals(e.getMessage())
- || "Array index out of range: 4".equals(e.getMessage()));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java b/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java
deleted file mode 100644
index e2ebb50..0000000
--- a/core/src/test/java/org/eobjects/metamodel/insert/SyntaxExamplesTest.java
+++ /dev/null
@@ -1,44 +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.insert;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-public abstract class SyntaxExamplesTest extends TestCase {
-
- private UpdateableDataContext dc;
- private Table table;
- private Column col;
-
- public void testInsertMultipleRows() throws Exception {
- dc.executeUpdate(new UpdateScript() {
- @Override
- public void run(UpdateCallback cb) {
- cb.insertInto(table).value(col, "foo").execute();
- cb.insertInto(table).value(col, "bar").execute();
- }
- });
- }
-}
\ 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/intercept/InterceptableDataContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java b/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java
deleted file mode 100644
index 9eb93c1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptableDataContextTest.java
+++ /dev/null
@@ -1,113 +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.intercept;
-
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.MaxRowsDataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.MutableSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class InterceptableDataContextTest extends TestCase {
-
- private final MockUpdateableDataContext delegateDataContext = new MockUpdateableDataContext();
- private final Table table = delegateDataContext.getDefaultSchema()
- .getTables()[0];
-
- public void testInterceptSchema() throws Exception {
- // without an interceptor
- {
- DataContext dc = new InterceptableDataContext(delegateDataContext);
-
- Schema schema = dc.getDefaultSchema();
- Schema[] schemas = dc.getSchemas();
-
- assertEquals("schema", schema.getName());
- assertEquals(MutableSchema.class, schema.getClass());
- assertEquals("[information_schema, schema]",
- Arrays.toString(dc.getSchemaNames()));
- assertEquals(2, schemas.length);
- assertEquals("information_schema", schemas[0].getName());
- assertEquals("schema", schemas[1].getName());
- }
-
- // with an interceptor
- {
- DataContext dc = new InterceptableDataContext(delegateDataContext)
- .addSchemaInterceptor(new SchemaInterceptor() {
- @Override
- public Schema intercept(Schema input) {
- return new MutableSchema(input.getName() + " foo!");
- }
- });
-
- Schema schema = dc.getDefaultSchema();
- Schema[] schemas = dc.getSchemas();
-
- assertEquals("schema foo!", schema.getName());
- assertEquals(MutableSchema.class, schema.getClass());
- assertEquals("[information_schema foo!, schema foo!]",
- Arrays.toString(dc.getSchemaNames()));
- assertEquals(2, schemas.length);
- assertEquals("information_schema foo!", schemas[0].getName());
- assertEquals("schema foo!", schemas[1].getName());
- }
- }
-
- public void testInterceptDataSet() throws Exception {
- DataContext dc = new InterceptableDataContext(delegateDataContext)
- .addDataSetInterceptor(new DataSetInterceptor() {
- @Override
- public DataSet intercept(DataSet dataSet) {
- return new MaxRowsDataSet(dataSet, 1);
- }
- });
-
- DataSet ds = dc.query().from(table).select("foo").execute();
- assertEquals(MaxRowsDataSet.class, ds.getClass());
- assertEquals(1, ds.toObjectArrays().size());
- }
-
- public void testInterceptQuery() throws Exception {
-
- DataContext dc = new InterceptableDataContext(delegateDataContext)
- .addQueryInterceptor(new QueryInterceptor() {
- @Override
- public Query intercept(Query input) {
- return input.select(table.getColumnByName("foo"));
- }
- }).addQueryInterceptor(new QueryInterceptor() {
- @Override
- public Query intercept(Query input) {
- return input.select(table.getColumnByName("bar"));
-
- }
- });
-
- DataSet ds = dc.executeQuery(new Query().from(table));
- assertEquals("[table.foo, table.bar]", Arrays.toString(ds.getSelectItems()));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java b/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.java
deleted file mode 100644
index 8b965e1..0000000
--- a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorListTest.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.intercept;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MockUpdateableDataContext;
-import org.eobjects.metamodel.convert.ConvertedDataSetInterceptor;
-import org.eobjects.metamodel.data.DataSet;
-
-import junit.framework.TestCase;
-
-public class InterceptorListTest extends TestCase {
-
- public void testGetInterceptorOfType() throws Exception {
- DataContext dc = new MockUpdateableDataContext();
- InterceptableDataContext interceptor = Interceptors.intercept(dc);
-
- InterceptorList<DataSet> list = interceptor.getDataSetInterceptors();
- ConvertedDataSetInterceptor convertedDataSetInterceptor = new ConvertedDataSetInterceptor();
- list.add(convertedDataSetInterceptor);
-
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
-
- class NoopDataSetInterceptor implements DataSetInterceptor {
- @Override
- public DataSet intercept(DataSet dataSet) {
- return dataSet;
- }
- };
-
- NoopDataSetInterceptor noopDataSetInterceptor = new NoopDataSetInterceptor();
- list.add(noopDataSetInterceptor);
-
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
- assertSame(convertedDataSetInterceptor, list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
- assertSame(noopDataSetInterceptor, list.getInterceptorOfType(NoopDataSetInterceptor.class));
-
- list.remove(convertedDataSetInterceptor);
-
- assertSame(noopDataSetInterceptor, list.getInterceptorOfType(DataSetInterceptor.class));
- assertNull(list.getInterceptorOfType(ConvertedDataSetInterceptor.class));
- assertSame(noopDataSetInterceptor, list.getInterceptorOfType(NoopDataSetInterceptor.class));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java b/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java
deleted file mode 100644
index d662c70..0000000
--- a/core/src/test/java/org/eobjects/metamodel/intercept/InterceptorsTest.java
+++ /dev/null
@@ -1,33 +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.intercept;
-
-import org.eobjects.metamodel.MockUpdateableDataContext;
-
-import junit.framework.TestCase;
-
-public class InterceptorsTest extends TestCase {
-
- public void testReuseInterceptor() throws Exception {
- MockUpdateableDataContext original = new MockUpdateableDataContext();
- InterceptableDataContext interceptor1 = Interceptors.intercept(original);
- InterceptableDataContext interceptor2 = Interceptors.intercept(interceptor1);
- assertSame(interceptor1, interceptor2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java b/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java
deleted file mode 100644
index 7d85f5c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/DefaultCompiledQueryTest.java
+++ /dev/null
@@ -1,92 +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.query;
-
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-import org.eobjects.metamodel.schema.MutableTable;
-import org.eobjects.metamodel.schema.TableType;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DefaultCompiledQueryTest {
-
- Query query;
-
- @Before
- public void setup() {
- query = new Query();
-
- MutableTable datastoreTable = new MutableTable("datastore", TableType.TABLE);
-
- MutableColumn dataSourceIdColumn = new MutableColumn("dataSourceIdColumn", ColumnType.VARCHAR);
- MutableColumn dataSourceNameColumn = new MutableColumn("dataSourceNameColumn", ColumnType.VARCHAR);
- MutableColumn versionColumn = new MutableColumn("versionColumn", ColumnType.INTEGER);
- MutableColumn changeSetColumn = new MutableColumn("changeSetColumn", ColumnType.INTEGER);
-
- SelectItem countSelectItem = new SelectItem(FunctionType.COUNT, dataSourceIdColumn);
- SelectItem dsIdSelectItem = new SelectItem(dataSourceIdColumn).setAlias("innerDataSourceRecordId");
- Query leftQuery = new Query();
- leftQuery.select(dsIdSelectItem);
- leftQuery.groupBy(dataSourceIdColumn);
- leftQuery.having(new FilterItem(countSelectItem.toSql() + " " + OperatorType.EQUALS_TO.toSql() + " 2"));
- leftQuery.where(dataSourceNameColumn, OperatorType.EQUALS_TO, new QueryParameter());
- leftQuery.from(datastoreTable);
- FromItem leftFrom = new FromItem(leftQuery);
- leftFrom.setAlias("innerDS");
-
- query.select(changeSetColumn);
- query.from(leftFrom, new FromItem(datastoreTable));
- query.where(versionColumn, OperatorType.EQUALS_TO, 2);
- query.where(changeSetColumn, OperatorType.EQUALS_TO, new QueryParameter());
- // Checks if max count is 2 in order to assert that this record has not
- // been a part of any changeSets previously and not processed by GR
- // creation in the current run.
- query.where(new SelectItem(dsIdSelectItem, leftFrom), OperatorType.EQUALS_TO, dsIdSelectItem);
- query.where(dataSourceNameColumn, OperatorType.EQUALS_TO, new QueryParameter());
- }
-
- @Test
- public void testGetParameterLogic() {
-
- DefaultCompiledQuery defaultCompiledQuery = new DefaultCompiledQuery(query);
- Assert.assertEquals(3, defaultCompiledQuery.getParameters().size());
-
- Assert.assertEquals(
- "DefaultCompiledQuery["
- + "SELECT changeSetColumn FROM (SELECT dataSourceIdColumn AS innerDataSourceRecordId FROM datastore WHERE dataSourceNameColumn = ? GROUP BY dataSourceIdColumn HAVING COUNT(dataSourceIdColumn) = 2) innerDS, datastore "
- + "WHERE versionColumn = 2 AND changeSetColumn = ? AND innerDS.innerDataSourceRecordId = dataSourceIdColumn AND dataSourceNameColumn = ?]",
- defaultCompiledQuery.toString());
-
- defaultCompiledQuery.close();
- }
-
- @Test
- public void testCloneWithParameterValues() {
- DefaultCompiledQuery defaultCompiledQuery = new DefaultCompiledQuery(query);
- Query resultQuery = defaultCompiledQuery.cloneWithParameterValues(new Object[] { "BE", 1, "BE" });
- defaultCompiledQuery.close();
-
- defaultCompiledQuery = new DefaultCompiledQuery(resultQuery);
- Assert.assertEquals(0, defaultCompiledQuery.getParameters().size());
- defaultCompiledQuery.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java
deleted file mode 100644
index 9ed783c..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FilterItemTest.java
+++ /dev/null
@@ -1,413 +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.query;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.MetaModelException;
-import org.eobjects.metamodel.QueryPostprocessDataContext;
-import org.eobjects.metamodel.data.CachingDataSetHeader;
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DataSetHeader;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.InMemoryDataSet;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.ColumnType;
-import org.eobjects.metamodel.schema.MutableColumn;
-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.schema.TableType;
-
-public class FilterItemTest extends TestCase {
-
- public void testExpressionBasedFilter() throws Exception {
- FilterItem filterItem = new FilterItem("foobar");
- assertEquals("foobar", filterItem.getExpression());
-
- try {
- filterItem.evaluate(null);
- fail("Exception should have been thrown");
- } catch (Exception e) {
- assertEquals("Expression-based filters cannot be manually evaluated", e.getMessage());
- }
-
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
- assertEquals("SELECT Col1 WHERE foobar", new Query().select(col1).where(filterItem).toString());
-
- assertEquals("SELECT Col1 WHERE YEAR(Col1) = 2008", new Query().select(col1).where("YEAR(Col1) = 2008")
- .toString());
- }
-
- public void testToSqlWhereItem() throws Exception {
- MutableColumn col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
- SelectItem selectItem = new SelectItem(col1);
- FilterItem c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, null);
- assertEquals("Col1 IS NOT NULL", c.toString());
-
- try {
- c = new FilterItem(selectItem, OperatorType.GREATER_THAN, null);
- fail("Exception should have been thrown");
- } catch (IllegalArgumentException e) {
- assertEquals("Can only use EQUALS or DIFFERENT_FROM operator with null-operand", e.getMessage());
- }
-
- c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo");
- assertEquals("Col1 <> 'foo'", c.toString());
-
- c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "'bar'");
-
- // this will be rewritten so it's not an issue even though it look like
- // it needs an escape-char
- assertEquals("Col1 <> ''bar''", c.toSql());
-
- c = new FilterItem(selectItem, OperatorType.DIFFERENT_FROM, "foo's bar");
- // the same applies here
- assertEquals("Col1 <> 'foo's bar'", c.toSql());
-
- col1.setType(ColumnType.FLOAT);
- c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423);
- assertEquals("Col1 = 423", c.toString());
-
- c = new FilterItem(selectItem, OperatorType.EQUALS_TO, 423426235423.42);
- assertEquals("Col1 = 423426235423.42", c.toString());
-
- c = new FilterItem(selectItem, OperatorType.EQUALS_TO, true);
- assertEquals("Col1 = 1", c.toString());
-
- Column timeColumn = new MutableColumn("TimeCol", ColumnType.TIME);
- selectItem = new SelectItem(timeColumn);
- c = new FilterItem(selectItem, OperatorType.GREATER_THAN, "02:30:05.000");
- assertEquals("TimeCol > TIME '02:30:05'", c.toString());
-
- Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
- c = new FilterItem(new SelectItem(dateColumn), OperatorType.GREATER_THAN, "2000-12-31");
- assertEquals("DateCol > DATE '2000-12-31'", c.toString());
- }
-
- public void testToStringTimeStamp() throws Exception {
- Column timestampColumn = new MutableColumn("TimestampCol", ColumnType.TIMESTAMP);
- FilterItem c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN,
- "2000-12-31 02:30:05.007");
- assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
-
- c = new FilterItem(new SelectItem(timestampColumn), OperatorType.LESS_THAN, "2000-12-31 02:30:05");
- assertEquals("TimestampCol < TIMESTAMP '2000-12-31 02:30:05'", c.toString());
-
- Column dateColumn = new MutableColumn("DateCol", ColumnType.DATE);
- c = new FilterItem(new SelectItem(timestampColumn), OperatorType.GREATER_THAN, new SelectItem(dateColumn));
- assertEquals("TimestampCol > DateCol", c.toString());
- }
-
- public void testEvaluateStrings() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
- Column col2 = new MutableColumn("Col2", ColumnType.VARCHAR);
- SelectItem s1 = new SelectItem(col1);
- SelectItem s2 = new SelectItem(col2);
- SelectItem[] selectItems = new SelectItem[] { s1, s2 };
- SimpleDataSetHeader header = new SimpleDataSetHeader(selectItems);
- Row row;
- FilterItem c;
-
- row = new DefaultRow(header, new Object[] { "foo", "bar" });
- c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, s2);
- assertTrue(c.evaluate(row));
-
- row = new DefaultRow(header, new Object[] { "aaa", "bbb" });
- c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.LESS_THAN, s2);
- assertTrue(c.evaluate(row));
-
- row = new DefaultRow(header, new Object[] { "aaa", "aaa" });
- c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.LIKE, s2);
- row = new DefaultRow(header, new Object[] { "foobar", "fo%b%r" });
- assertTrue(c.evaluate(row));
-
- row = new DefaultRow(header, new Object[] { "foobbdbafsdfr", "fo%b%r" });
- assertTrue(c.evaluate(row));
- }
-
- public void testEvaluateNull() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.INTEGER);
- Column col2 = new MutableColumn("Col2", ColumnType.DECIMAL);
- SelectItem s1 = new SelectItem(col1);
- SelectItem s2 = new SelectItem(col2);
- SelectItem[] selectItems = new SelectItem[] { s1, s2 };
- CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
-
- FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, null);
-
- Row row = new DefaultRow(header, new Object[] { 1, 1 });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.EQUALS_TO, 1);
-
- row = new DefaultRow(header, new Object[] { 1, 1 });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.DIFFERENT_FROM, 5);
-
- row = new DefaultRow(header, new Object[] { 1, 1 });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.GREATER_THAN, s2);
-
- row = new DefaultRow(header, new Object[] { 5, 1 });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, 1 });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { 1, null });
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.EQUALS_TO, s2);
- row = new DefaultRow(header, new Object[] { 1, null });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { null, null });
- assertTrue(c.evaluate(row));
- }
-
- public void testEvaluateDates() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.DATE);
- SelectItem s1 = new SelectItem(col1);
- SelectItem[] selectItems = new SelectItem[] { s1 };
- CachingDataSetHeader header = new CachingDataSetHeader(selectItems);
-
- long currentTimeMillis = System.currentTimeMillis();
- FilterItem c = new FilterItem(s1, OperatorType.LESS_THAN, new java.sql.Date(currentTimeMillis));
-
- Row row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis) });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis + 10000000) });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { new java.sql.Date(currentTimeMillis - 10000000) });
- assertTrue(c.evaluate(row));
- }
-
- public void testEvaluateBooleans() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.BIT);
- SelectItem s1 = new SelectItem(col1);
- SelectItem[] selectItems = new SelectItem[] { s1 };
- DataSetHeader header = new SimpleDataSetHeader(selectItems);
-
- FilterItem c = new FilterItem(s1, OperatorType.EQUALS_TO, true);
-
- Row row = new DefaultRow(header, new Object[] { true });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { false });
- assertFalse(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.EQUALS_TO, false);
- row = new DefaultRow(header, new Object[] { true });
- assertFalse(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { false });
- assertTrue(c.evaluate(row));
-
- c = new FilterItem(s1, OperatorType.GREATER_THAN, false);
- row = new DefaultRow(header, new Object[] { true });
- assertTrue(c.evaluate(row));
- row = new DefaultRow(header, new Object[] { false });
- assertFalse(c.evaluate(row));
- }
-
- /**
- * 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 {
- Column col1 = new MutableColumn("Col1", ColumnType.BIT);
-
- FilterItem c1 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
- FilterItem c2 = new FilterItem(new SelectItem(col1), OperatorType.EQUALS_TO, true);
- assertEquals(c1, c2);
- assertEquals(c1.hashCode(), c2.hashCode());
-
- c2 = new FilterItem(new SelectItem(col1), OperatorType.GREATER_THAN, true);
- assertFalse(c1.equals(c2));
- assertFalse(c1.hashCode() == c2.hashCode());
-
- Column col2 = new MutableColumn("Col2", ColumnType.VARBINARY);
- c2 = new FilterItem(new SelectItem(col2), OperatorType.EQUALS_TO, true);
- assertFalse(c1.equals(c2));
- assertFalse(c1.hashCode() == c2.hashCode());
- }
-
- public void testOrFilterItem() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
-
- SelectItem s1 = new SelectItem(col1);
- FilterItem c1 = new FilterItem(s1, OperatorType.EQUALS_TO, "foo");
- FilterItem c2 = new FilterItem(s1, OperatorType.EQUALS_TO, "bar");
- FilterItem c3 = new FilterItem(s1, OperatorType.EQUALS_TO, "foobar");
-
- FilterItem filter = new FilterItem(c1, c2, c3);
- assertEquals("(Col1 = 'foo' OR Col1 = 'bar' OR Col1 = 'foobar')", filter.toString());
-
- DataSetHeader header = new SimpleDataSetHeader(new SelectItem[] { s1 });
-
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "bar" })));
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
-
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foob" })));
- }
-
- public void testAndFilterItem() throws Exception {
- Column col1 = new MutableColumn("Col1", ColumnType.VARCHAR);
-
- SelectItem s1 = new SelectItem(col1);
- FilterItem c1 = new FilterItem(s1, OperatorType.LIKE, "foo%");
- FilterItem c2 = new FilterItem(s1, OperatorType.LIKE, "%bar");
- FilterItem c3 = new FilterItem(s1, OperatorType.DIFFERENT_FROM, "foobar");
-
- FilterItem filter = new FilterItem(LogicalOperator.AND, c1, c2, c3);
- assertEquals("(Col1 LIKE 'foo%' AND Col1 LIKE '%bar' AND Col1 <> 'foobar')", filter.toString());
-
- SelectItem[] items = new SelectItem[] { s1 };
- CachingDataSetHeader header = new CachingDataSetHeader(items);
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foo bar" })));
- assertTrue(filter.evaluate(new DefaultRow(header, new Object[] { "foosenbar" })));
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foo" })));
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "hello world" })));
- assertFalse(filter.evaluate(new DefaultRow(header, new Object[] { "foobar" })));
- }
-
- // Ticket #410
- public void testOrFilterItemWithoutSelectingActualItmes() throws Exception {
-
- // define the schema
- final MutableSchema schema = new MutableSchema("s");
- MutableTable table = new MutableTable("persons", TableType.TABLE, schema);
- schema.addTable(table);
- final Column col1 = new MutableColumn("name", ColumnType.VARCHAR, table, 1, true);
- final Column col2 = new MutableColumn("role", ColumnType.VARCHAR, table, 2, true);
- final Column col3 = new MutableColumn("column_number", ColumnType.INTEGER, table, 3, true);
- table.addColumn(col1);
- table.addColumn(col2);
- table.addColumn(col3);
-
- Query q = new Query();
- q.select(col3);
- q.from(col1.getTable());
-
- SelectItem selectItem1 = new SelectItem(col1);
- SelectItem selectItem2 = new SelectItem(col2);
-
- FilterItem item1 = new FilterItem(selectItem1, OperatorType.EQUALS_TO, "kasper");
- FilterItem item2 = new FilterItem(selectItem2, OperatorType.EQUALS_TO, "user");
-
- q.where(new FilterItem(item1, item2));
-
- assertEquals(
- "SELECT persons.column_number FROM s.persons WHERE (persons.name = 'kasper' OR persons.role = 'user')",
- q.toString());
-
- DataContext dc = new QueryPostprocessDataContext() {
-
- @Override
- public DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
- assertEquals(3, columns.length);
- assertEquals("column_number", columns[0].getName());
- assertEquals("name", columns[1].getName());
- assertEquals("role", columns[2].getName());
- SelectItem[] selectItems = new SelectItem[] { new SelectItem(col1), new SelectItem(col2),
- new SelectItem(col3) };
- DataSetHeader header = new CachingDataSetHeader(selectItems);
- List<Row> rows = new LinkedList<Row>();
- rows.add(new DefaultRow(header, new Object[] { "foo", "bar", 1 }));
- rows.add(new DefaultRow(header, new Object[] { "kasper", "developer", 2 }));
- rows.add(new DefaultRow(header, new Object[] { "admin", "admin", 3 }));
- rows.add(new DefaultRow(header, new Object[] { "elikeon", "user", 4 }));
- rows.add(new DefaultRow(header, new Object[] { "someuser", "user", 5 }));
- rows.add(new DefaultRow(header, new Object[] { "hmm", "what-the", 6 }));
-
- return new InMemoryDataSet(header, rows);
- }
-
- @Override
- protected String getMainSchemaName() throws MetaModelException {
- return "s";
- }
-
- @Override
- protected Schema getMainSchema() throws MetaModelException {
- return schema;
- }
- };
-
- DataSet result = dc.executeQuery(q);
- List<Object[]> objectArrays = result.toObjectArrays();
- assertEquals(3, objectArrays.size());
- assertEquals(2, objectArrays.get(0)[0]);
- assertEquals(4, objectArrays.get(1)[0]);
- assertEquals(5, objectArrays.get(2)[0]);
- }
-
- public void testInOperandSql() throws Exception {
- SelectItem selectItem = new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR, null, 1, null, null, true,
- null, false, null));
- Object operand = new String[] { "foo", "bar" };
- assertEquals("foo IN ('foo' , 'bar')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
-
- operand = Arrays.asList("foo", "bar", "baz");
- assertEquals("foo IN ('foo' , 'bar' , 'baz')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
-
- operand = "foo";
- assertEquals("foo IN ('foo')", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
-
- operand = new ArrayList<Object>();
- assertEquals("foo IN ()", new FilterItem(selectItem, OperatorType.IN, operand).toSql());
- }
-
- public void testInOperandEvaluate() throws Exception {
- SelectItem selectItem = new SelectItem(new MutableColumn("foo", ColumnType.VARCHAR, null, 1, null, null, true,
- null, false, null));
- Object operand = new String[] { "foo", "bar" };
-
- FilterItem filterItem = new FilterItem(selectItem, OperatorType.IN, operand);
- SelectItem[] selectItems = new SelectItem[] { selectItem };
- DataSetHeader header = new CachingDataSetHeader(selectItems);
-
- assertTrue(filterItem.evaluate(new DefaultRow(header, new Object[] { "foo" })));
- assertTrue(filterItem.evaluate(new DefaultRow(header, new Object[] { "bar" })));
- assertFalse(filterItem.evaluate(new DefaultRow(header, new Object[] { "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/query/FromClauseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.java b/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.java
deleted file mode 100644
index 074a3b4..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FromClauseTest.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.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class FromClauseTest extends MetaModelTestCase {
-
- public void testGetItemByReference() throws Exception {
- Schema exampleSchema = getExampleSchema();
- Table table = exampleSchema.getTableByName(TABLE_CONTRIBUTOR);
-
- Query query = new Query();
- query.from(table, "foobar");
-
- assertNull(query.getFromClause().getItemByReference("foob"));
- assertNull(query.getFromClause().getItemByReference(TABLE_CONTRIBUTOR));
- assertEquals("MetaModelSchema.contributor foobar", query
- .getFromClause().getItemByReference("foobar").toString());
-
- query = new Query();
- query.from(table);
- assertNull(query.getFromClause().getItemByReference("foob"));
- assertEquals("MetaModelSchema.contributor", query.getFromClause()
- .getItemByReference(TABLE_CONTRIBUTOR).toString());
- assertNull(query.getFromClause().getItemByReference("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/query/FromItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java b/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java
deleted file mode 100644
index fb4c09e..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FromItemTest.java
+++ /dev/null
@@ -1,101 +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.query;
-
-import org.eobjects.metamodel.MetaModelTestCase;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Relationship;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-public class FromItemTest extends MetaModelTestCase {
-
- private Schema _schema = getExampleSchema();
-
- public void testExpressionBased() throws Exception {
- FromItem fromItem = new FromItem("foobar");
- assertEquals("foobar", fromItem.toString());
- fromItem.setAlias("f");
- assertEquals("foobar f", fromItem.toString());
-
- assertEquals("SELECT COUNT(*) FROM foobar", new Query().selectCount().from(
- "foobar").toString());
- }
-
- public void testRelationJoinToString() throws Exception {
- Table contributorTable = _schema.getTableByName(TABLE_CONTRIBUTOR);
- Table roleTable = _schema.getTableByName(TABLE_ROLE);
- Relationship[] relationships = roleTable
- .getRelationships(contributorTable);
- FromItem from = new FromItem(JoinType.INNER, relationships[0]);
- assertEquals(
- "MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id",
- from.toString());
-
- from.setAlias("myJoin");
- assertEquals(
- "(MetaModelSchema.contributor INNER JOIN MetaModelSchema.role ON contributor.contributor_id = role.contributor_id) myJoin",
- from.toString());
-
- from.getLeftSide().setAlias("a");
- assertEquals(
- "(MetaModelSchema.contributor a INNER JOIN MetaModelSchema.role ON a.contributor_id = role.contributor_id) myJoin",
- from.toString());
- }
-
- public void testSubQueryJoinToString() throws Exception {
- Table projectTable = _schema.getTableByName(TABLE_PROJECT);
- Table roleTable = _schema.getTableByName(TABLE_ROLE);
-
- Column projectIdColumn = projectTable
- .getColumnByName(COLUMN_PROJECT_PROJECT_ID);
-
- FromItem leftSide = new FromItem(projectTable);
- leftSide.setAlias("a");
- SelectItem[] leftOn = new SelectItem[] { new SelectItem(projectIdColumn) };
-
- Column[] columns = roleTable.getColumns();
-
- Query subQuery = new Query();
- FromItem subQueryFrom = new FromItem(roleTable);
- subQuery.from(subQueryFrom);
- subQuery.select(columns);
- SelectItem subQuerySelectItem = subQuery.getSelectClause().getItems()
- .get(1);
- FromItem rightSide = new FromItem(subQuery);
- rightSide.setAlias("b");
- SelectItem[] rightOn = new SelectItem[] { subQuerySelectItem };
- FromItem from = new FromItem(JoinType.LEFT, leftSide, rightSide,
- leftOn, rightOn);
-
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT role.contributor_id, role.project_id, role.name FROM MetaModelSchema.role) b ON a.project_id = b.project_id",
- from.toString());
-
- subQueryFrom.setAlias("c");
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.project_id",
- from.toString());
-
- subQuerySelectItem.setAlias("foobar");
- assertEquals(
- "MetaModelSchema.project a LEFT JOIN (SELECT c.contributor_id, c.project_id AS foobar, c.name FROM MetaModelSchema.role c) b ON a.project_id = b.foobar",
- from.toString());
- }
-}
\ 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/query/FunctionTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java b/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java
deleted file mode 100644
index 1161550..0000000
--- a/core/src/test/java/org/eobjects/metamodel/query/FunctionTypeTest.java
+++ /dev/null
@@ -1,42 +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.query;
-
-import junit.framework.TestCase;
-
-public class FunctionTypeTest extends TestCase {
-
- public void testEvaluateNumbers() throws Exception {
- assertEquals(2.5, FunctionType.AVG.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(10.0, FunctionType.SUM.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(4l, FunctionType.COUNT.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(1.5, FunctionType.MIN.evaluate(1.5, 2, null, 3, 3.5));
- assertEquals(3.5, FunctionType.MAX.evaluate(1.5, 2, null, 3, 3.5));
- }
-
- public void testEvaluateStrings() throws Exception {
- assertEquals(2.5, FunctionType.AVG.evaluate("1.5", "2", null, "3",
- "3.5"));
- assertEquals(10.0, FunctionType.SUM.evaluate("1.5", "2", null, "3",
- "3.5"));
- assertEquals(2l, FunctionType.COUNT.evaluate("foo", "BAR", null));
- assertEquals("a", FunctionType.MIN.evaluate("abc", "a", null, "bcd"));
- assertEquals("bcd", FunctionType.MAX.evaluate("abc", "a", null, "bcd"));
- }
-}
\ No newline at end of file