From a314f76c0eb33222809fd686d4a41a271e62fcff Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 23 Sep 2006 00:05:31 +0000 Subject: Added notJoinedFrom method. --- .../carbonado/filter/TestFilterAsJoinedFrom.java | 156 ++++++++++++ .../carbonado/filter/TestFilterNotJoinedFrom.java | 271 +++++++++++++++++++++ 2 files changed, 427 insertions(+) create mode 100644 src/test/java/com/amazon/carbonado/filter/TestFilterAsJoinedFrom.java create mode 100644 src/test/java/com/amazon/carbonado/filter/TestFilterNotJoinedFrom.java (limited to 'src/test/java/com/amazon') diff --git a/src/test/java/com/amazon/carbonado/filter/TestFilterAsJoinedFrom.java b/src/test/java/com/amazon/carbonado/filter/TestFilterAsJoinedFrom.java new file mode 100644 index 0000000..3b6bfde --- /dev/null +++ b/src/test/java/com/amazon/carbonado/filter/TestFilterAsJoinedFrom.java @@ -0,0 +1,156 @@ +/* + * Copyright 2006 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed 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 com.amazon.carbonado.filter; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import com.amazon.carbonado.stored.Address; +import com.amazon.carbonado.stored.Order; +import com.amazon.carbonado.stored.Shipment; + +/** + * + * + * @author Brian S O'Neill + */ +public class TestFilterAsJoinedFrom extends TestCase { + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + public static TestSuite suite() { + return new TestSuite(TestFilterAsJoinedFrom.class); + } + + public TestFilterAsJoinedFrom(String name) { + super(name); + } + + public void testOpen() { + Filter
filter = Filter.getOpenFilter(Address.class); + + Filter f2 = filter.asJoinedFrom(Order.class, "address"); + assertTrue(f2 instanceof OpenFilter); + assertEquals(Order.class, f2.getStorableType()); + + Filter f3 = filter.asJoinedFrom(Shipment.class, "order.address"); + assertTrue(f3 instanceof OpenFilter); + assertEquals(Shipment.class, f3.getStorableType()); + + Filter f4 = f2.asJoinedFrom(Shipment.class, "order"); + assertEquals(f3, f4); + assertTrue(f3 == f4); + } + + public void testClosed() { + Filter
filter = Filter.getClosedFilter(Address.class); + + Filter f2 = filter.asJoinedFrom(Order.class, "address"); + assertTrue(f2 instanceof ClosedFilter); + assertEquals(Order.class, f2.getStorableType()); + + Filter f3 = filter.asJoinedFrom(Shipment.class, "order.address"); + assertTrue(f3 instanceof ClosedFilter); + assertEquals(Shipment.class, f3.getStorableType()); + + Filter f4 = f2.asJoinedFrom(Shipment.class, "order"); + assertEquals(f3, f4); + assertTrue(f3 == f4); + } + + public void testSimple() { + Filter
filter = Filter.filterFor(Address.class, "addressCity = ?"); + + Filter f2 = filter.asJoinedFrom(Order.class, "address"); + assertEquals(f2, Filter.filterFor(Order.class, "address.addressCity = ?")); + + Filter f3 = filter.asJoinedFrom(Shipment.class, "order.address"); + assertEquals(f3, Filter.filterFor(Shipment.class, "order.address.addressCity = ?")); + + Filter f4 = f2.asJoinedFrom(Shipment.class, "order"); + assertEquals(f3, f4); + assertTrue(f3 == f4); + } + + public void testAnd() { + Filter
filter = Filter.filterFor + (Address.class, "addressCity = ? & addressZip != ?"); + + Filter f2 = filter.asJoinedFrom(Order.class, "address"); + assertEquals(f2, Filter.filterFor + (Order.class, "address.addressCity = ? & address.addressZip != ?")); + + Filter f3 = filter.asJoinedFrom(Shipment.class, "order.address"); + assertEquals(f3, Filter.filterFor + (Shipment.class, + "order.address.addressCity = ? & order.address.addressZip != ?")); + + Filter f4 = f2.asJoinedFrom(Shipment.class, "order"); + assertEquals(f3, f4); + assertTrue(f3 == f4); + } + + public void testOr() { + Filter
filter = Filter.filterFor + (Address.class, "addressCity = ? | addressZip != ?"); + + Filter f2 = filter.asJoinedFrom(Order.class, "address"); + assertEquals(f2, Filter.filterFor + (Order.class, "address.addressCity = ? | address.addressZip != ?")); + + Filter f3 = filter.asJoinedFrom(Shipment.class, "order.address"); + assertEquals(f3, Filter.filterFor + (Shipment.class, + "order.address.addressCity = ? | order.address.addressZip != ?")); + + Filter f4 = f2.asJoinedFrom(Shipment.class, "order"); + assertEquals(f3, f4); + assertTrue(f3 == f4); + } + + public void testMixed() { + Filter
filter = Filter.filterFor + (Address.class, "addressCity = ? & addressZip != ? | addressState > ?"); + + Filter f2 = filter.asJoinedFrom(Order.class, "address"); + assertEquals + (f2, Filter.filterFor + (Order.class, + "address.addressCity = ? & address.addressZip != ? | address.addressState > ?")); + + Filter f3 = filter.asJoinedFrom(Shipment.class, "order.address"); + assertEquals(f3, Filter.filterFor + (Shipment.class, + "order.address.addressCity = ? & order.address.addressZip != ? " + + " | order.address.addressState > ?")); + Filter f4 = f2.asJoinedFrom(Shipment.class, "order"); + assertEquals(f3, f4); + assertTrue(f3 == f4); + } + + public void testError() { + try { + Filter
filter = Filter.filterFor(Address.class, "addressCity = ?"); + Filter f2 = filter.asJoinedFrom(Order.class, "orderTotal"); + fail(); + } catch (IllegalArgumentException e) { + } + } +} diff --git a/src/test/java/com/amazon/carbonado/filter/TestFilterNotJoinedFrom.java b/src/test/java/com/amazon/carbonado/filter/TestFilterNotJoinedFrom.java new file mode 100644 index 0000000..1e97d89 --- /dev/null +++ b/src/test/java/com/amazon/carbonado/filter/TestFilterNotJoinedFrom.java @@ -0,0 +1,271 @@ +/* + * Copyright 2006 Amazon Technologies, Inc. or its affiliates. + * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks + * of Amazon Technologies, Inc. or its affiliates. All rights reserved. + * + * Licensed 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 com.amazon.carbonado.filter; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import com.amazon.carbonado.stored.Address; +import com.amazon.carbonado.stored.Order; +import com.amazon.carbonado.stored.Shipment; + +/** + * + * + * @author Brian S O'Neill + */ +public class TestFilterNotJoinedFrom extends TestCase { + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + + public static TestSuite suite() { + return new TestSuite(TestFilterNotJoinedFrom.class); + } + + public TestFilterNotJoinedFrom(String name) { + super(name); + } + + public void testOpen() { + Filter filter = Filter.getOpenFilter(Shipment.class); + + Filter.NotJoined nj = filter.notJoinedFrom("order"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + } + + public void testClosed() { + Filter filter = Filter.getClosedFilter(Shipment.class); + + Filter.NotJoined nj = filter.notJoinedFrom("order"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + } + + public void testSimple() { + Filter filter = Filter.filterFor(Shipment.class, "shipmentNotes != ?"); + filter = filter.bind(); + + Filter.NotJoined nj = filter.notJoinedFrom("order"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + filter = Filter.filterFor(Shipment.class, "order.orderTotal < ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor(Order.class, "orderTotal < ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + filter = Filter.filterFor(Shipment.class, "order.address.addressCity = ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor(Order.class, "address.addressCity = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.filterFor(Address.class, "addressCity = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + try { + nj = filter.notJoinedFrom("order.address.addressCity"); + fail(); + } catch (IllegalArgumentException e) { + } + } + + public void testAnd() { + Filter filter = Filter.filterFor + (Shipment.class, "shipmentNotes != ? & shipmentDate > ?"); + filter = filter.bind(); + + Filter.NotJoined nj = filter.notJoinedFrom("order"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + filter = Filter.filterFor + (Shipment.class, + "order.orderTotal < ? & shipmentNotes != ? & order.orderComments = ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor(Order.class, "orderTotal < ? & orderComments = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.filterFor(Shipment.class, "shipmentNotes != ?").bind(), + nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + filter = Filter.filterFor + (Shipment.class, + "order.orderTotal < ? & order.address.addressCity != ? " + + "& order.address.addressZip = ? & shipmentNotes != ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor(Order.class, "orderTotal < ? & address.addressCity != ? " + + "& address.addressZip = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.filterFor(Shipment.class, "shipmentNotes != ?").bind(), + nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.filterFor(Address.class, "addressCity != ? & addressZip = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.filterFor + (Shipment.class, "order.orderTotal < ? & shipmentNotes != ?").bind(), + nj.getRemainderFilter()); + } + + public void testOr() { + Filter filter = Filter.filterFor + (Shipment.class, "shipmentNotes != ? | shipmentDate > ?"); + filter = filter.bind(); + + Filter.NotJoined nj = filter.notJoinedFrom("order"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + filter = Filter.filterFor + (Shipment.class, + "order.orderTotal < ? | order.orderComments = ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor(Order.class, "orderTotal < ? | orderComments = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + filter = Filter.filterFor + (Shipment.class, + "order.orderTotal < ? | shipmentNotes != ? | order.orderComments = ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.getOpenFilter(Order.class), nj.getNotJoinedFilter()); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertTrue(nj.getNotJoinedFilter() instanceof OpenFilter); + assertEquals(filter, nj.getRemainderFilter()); + + filter = Filter.filterFor + (Shipment.class, + "order.address.addressCity != ? | order.address.addressZip = ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor(Order.class, + "address.addressCity != ? | address.addressZip = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.filterFor(Address.class, "addressCity != ? | addressZip = ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + filter = Filter.filterFor + (Shipment.class, + "order.orderTotal < ? | order.address.addressCity != ? " + + "| order.address.addressZip = ? | shipmentNotes != ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order"); + assertEquals(Filter.getOpenFilter(Order.class), nj.getNotJoinedFilter()); + assertEquals(filter, nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.getOpenFilter(Address.class), nj.getNotJoinedFilter()); + assertEquals(filter, nj.getRemainderFilter()); + } + + public void testMixed() { + Filter filter = Filter.filterFor + (Shipment.class, + "(order.address.addressCity = ? & order.address.addressZip = ?) " + + "| order.orderTotal != ?"); + filter = filter.bind(); + + Filter.NotJoined nj = filter.notJoinedFrom("order"); + assertEquals(Filter.filterFor + (Order.class, + "address.addressCity = ? & address.addressZip = ? | orderTotal != ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.getOpenFilter(Shipment.class), nj.getRemainderFilter()); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.getOpenFilter(Address.class), nj.getNotJoinedFilter()); + assertEquals(filter, nj.getRemainderFilter()); + + filter = filter.and("order.address.customData > ?"); + filter = filter.bind(); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.filterFor(Address.class, "customData > ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.filterFor + (Shipment.class, + "(order.address.addressCity = ? | order.orderTotal != ?) " + + "& (order.address.addressZip = ? | order.orderTotal != ?)"), + nj.getRemainderFilter().unbind()); + + filter = filter.disjunctiveNormalForm(); + + nj = filter.notJoinedFrom("order.address"); + assertEquals(Filter.filterFor(Address.class, "customData > ?").bind(), + nj.getNotJoinedFilter()); + assertEquals(Filter.filterFor + (Shipment.class, + "order.address.addressCity = ? & order.address.addressZip = ? " + + "| order.orderTotal != ?").bind(), + nj.getRemainderFilter()); + } +} -- cgit v1.2.3