[Major] Implemented querying Activities by state and resolves #3
This commit is contained in:
parent
fbb2bc85db
commit
6afba02c59
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* 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 li.strolch.runtime.query.inmemory;
|
||||
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ActivityStateSelector implements Selector<Activity> {
|
||||
|
||||
private State state;
|
||||
|
||||
/**
|
||||
* @param state
|
||||
*/
|
||||
public ActivityStateSelector(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean select(Activity element) {
|
||||
return this.state.equals(element.getState());
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
|||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.ActivityQueryVisitor;
|
||||
import li.strolch.model.query.ActivityStateSelection;
|
||||
import li.strolch.model.query.StrolchTypeNavigation;
|
||||
import li.strolch.model.visitor.ActivityVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
@ -62,4 +63,9 @@ public class InMemoryActivityQueryVisitor extends InMemoryQueryVisitor<Activity>
|
|||
public void visit(StrolchTypeNavigation navigation) {
|
||||
setNavigator(new ActivityTypeNavigator(navigation.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ActivityStateSelection selection) {
|
||||
addSelector(new ActivityStateSelector(selection.getState()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import li.strolch.model.Order;
|
|||
import li.strolch.model.query.DateSelection;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.OrderQueryVisitor;
|
||||
import li.strolch.model.query.StateSelection;
|
||||
import li.strolch.model.query.OrderStateSelection;
|
||||
import li.strolch.model.query.StrolchTypeNavigation;
|
||||
import li.strolch.model.visitor.OrderVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
@ -71,7 +71,7 @@ public class InMemoryOrderQueryVisitor extends InMemoryQueryVisitor<Order> imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public void visit(StateSelection selection) {
|
||||
addSelector(new StateSelector(selection.getState()));
|
||||
public void visit(OrderStateSelection selection) {
|
||||
addSelector(new OrderStateSelector(selection.getState()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,15 @@ import li.strolch.model.State;
|
|||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public class StateSelector implements Selector<Order> {
|
||||
public class OrderStateSelector implements Selector<Order> {
|
||||
|
||||
private State state;
|
||||
|
||||
/**
|
||||
* @param state
|
||||
*/
|
||||
public StateSelector(State state) {
|
||||
public OrderStateSelector(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
|
@ -19,7 +19,9 @@ import org.junit.Test;
|
|||
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.ParameterBag;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.model.parameter.BooleanParameter;
|
||||
|
@ -30,6 +32,7 @@ import li.strolch.model.parameter.LongListParameter;
|
|||
import li.strolch.model.parameter.StringListParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.ActivityStateSelection;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
|
@ -251,10 +254,10 @@ public class InMemoryActivityQueryTest {
|
|||
@Test
|
||||
public void shouldQueryByName() {
|
||||
|
||||
List<Activity> activitys = getActivities();
|
||||
activitys.add(getBallActivity());
|
||||
List<Activity> activities = getActivities();
|
||||
activities.add(getBallActivity());
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activitys);
|
||||
dao.saveAll(activities);
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("Ball");
|
||||
ballQuery.with(new NameSelection("ball ", ci()));
|
||||
|
@ -263,6 +266,25 @@ public class InMemoryActivityQueryTest {
|
|||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByState() {
|
||||
|
||||
List<Activity> activities = getActivities();
|
||||
InMemoryActivityDao dao = daoInstance();
|
||||
dao.saveAll(activities);
|
||||
|
||||
ActivityQuery<Activity> ballQuery = ActivityQuery.query("MyType1");
|
||||
ballQuery.with(new ActivityStateSelection(State.STOPPED));
|
||||
|
||||
List<Activity> result = dao.doQuery(ballQuery);
|
||||
assertEquals(2, result.size());
|
||||
|
||||
ballQuery = ActivityQuery.query("MyType2");
|
||||
ballQuery.with(new ActivityStateSelection(State.STOPPED));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
private Activity getBallActivity() {
|
||||
Activity res1 = new Activity("childrensBall", "Ball 1", "Ball", TimeOrdering.SERIES);
|
||||
Version.setInitialVersionFor(res1, "test");
|
||||
|
@ -281,19 +303,32 @@ public class InMemoryActivityQueryTest {
|
|||
}
|
||||
|
||||
private List<Activity> getActivities() {
|
||||
Activity res1 = ModelGenerator.createActivity("@1", "Activity 1", "MyType1", TimeOrdering.SERIES);
|
||||
Activity res2 = ModelGenerator.createActivity("@2", "Activity 2", "MyType1", TimeOrdering.SERIES);
|
||||
Activity res3 = ModelGenerator.createActivity("@3", "Activity 3", "MyType2", TimeOrdering.SERIES);
|
||||
Activity res4 = ModelGenerator.createActivity("@4", "Activity 4", "MyType2", TimeOrdering.SERIES);
|
||||
Activity res5 = ModelGenerator.createActivity("@5", "Activity 5", "MyType3", TimeOrdering.SERIES);
|
||||
Activity res6 = ModelGenerator.createActivity("@6", "Activity 6", "MyType3", TimeOrdering.SERIES);
|
||||
|
||||
Activity activity1 = ModelGenerator.createActivity("@1", "Activity 1", "MyType1", TimeOrdering.SERIES);
|
||||
((Action) activity1.getElement("action_" + activity1.getId())).setState(State.STOPPED);
|
||||
|
||||
Activity activity2 = ModelGenerator.createActivity("@2", "Activity 2", "MyType1", TimeOrdering.SERIES);
|
||||
((Action) activity2.getElement("action_" + activity2.getId())).setState(State.STOPPED);
|
||||
|
||||
Activity activity3 = ModelGenerator.createActivity("@3", "Activity 3", "MyType2", TimeOrdering.SERIES);
|
||||
((Action) activity3.getElement("action_" + activity3.getId())).setState(State.STOPPED);
|
||||
|
||||
Activity activity4 = ModelGenerator.createActivity("@4", "Activity 4", "MyType2", TimeOrdering.SERIES);
|
||||
((Action) activity4.getElement("action_" + activity4.getId())).setState(State.PLANNING);
|
||||
|
||||
Activity activity5 = ModelGenerator.createActivity("@5", "Activity 5", "MyType3", TimeOrdering.SERIES);
|
||||
((Action) activity5.getElement("action_" + activity5.getId())).setState(State.ERROR);
|
||||
|
||||
Activity activity6 = ModelGenerator.createActivity("@6", "Activity 6", "MyType3", TimeOrdering.SERIES);
|
||||
((Action) activity6.getElement("action_" + activity6.getId())).setState(State.CLOSED);
|
||||
|
||||
List<Activity> activitys = new ArrayList<>();
|
||||
activitys.add(res1);
|
||||
activitys.add(res2);
|
||||
activitys.add(res3);
|
||||
activitys.add(res4);
|
||||
activitys.add(res5);
|
||||
activitys.add(res6);
|
||||
activitys.add(activity1);
|
||||
activitys.add(activity2);
|
||||
activitys.add(activity3);
|
||||
activitys.add(activity4);
|
||||
activitys.add(activity5);
|
||||
activitys.add(activity6);
|
||||
|
||||
for (Activity activity : activitys) {
|
||||
Version.setInitialVersionFor(activity, "test");
|
||||
|
|
|
@ -48,6 +48,7 @@ import li.strolch.model.parameter.StringParameter;
|
|||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.OrderStateSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.persistence.inmemory.InMemoryOrderDao;
|
||||
|
||||
|
@ -283,6 +284,25 @@ public class InMemoryOrderQueryTest {
|
|||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryByState() {
|
||||
|
||||
List<Order> orders = getOrders();
|
||||
InMemoryOrderDao dao = daoInstance();
|
||||
dao.saveAll(orders);
|
||||
|
||||
OrderQuery<Order> ballQuery = OrderQuery.query("MyType1");
|
||||
ballQuery.with(new OrderStateSelection(State.STOPPED));
|
||||
|
||||
List<Order> result = dao.doQuery(ballQuery);
|
||||
assertEquals(2, result.size());
|
||||
|
||||
ballQuery = OrderQuery.query("MyType2");
|
||||
ballQuery.with(new OrderStateSelection(State.STOPPED));
|
||||
result = dao.doQuery(ballQuery);
|
||||
assertEquals(1, result.size());
|
||||
}
|
||||
|
||||
private Order getBallOrder() {
|
||||
Order o1 = new Order("childrensBall", "Ball 1", "Ball");
|
||||
Version.setInitialVersionFor(o1, "test");
|
||||
|
@ -301,12 +321,12 @@ public class InMemoryOrderQueryTest {
|
|||
}
|
||||
|
||||
private List<Order> getOrders() {
|
||||
Order res1 = ModelGenerator.createOrder("@1", "Order 1", "MyType1", new Date(), State.CREATED);
|
||||
Order res2 = ModelGenerator.createOrder("@2", "Order 2", "MyType1", new Date(), State.CREATED);
|
||||
Order res3 = ModelGenerator.createOrder("@3", "Order 3", "MyType2", new Date(), State.CREATED);
|
||||
Order res4 = ModelGenerator.createOrder("@4", "Order 4", "MyType2", new Date(), State.CREATED);
|
||||
Order res5 = ModelGenerator.createOrder("@5", "Order 5", "MyType3", new Date(), State.CREATED);
|
||||
Order res6 = ModelGenerator.createOrder("@6", "Order 6", "MyType3", new Date(), State.CREATED);
|
||||
Order res1 = ModelGenerator.createOrder("@1", "Order 1", "MyType1", new Date(), State.STOPPED);
|
||||
Order res2 = ModelGenerator.createOrder("@2", "Order 2", "MyType1", new Date(), State.STOPPED);
|
||||
Order res3 = ModelGenerator.createOrder("@3", "Order 3", "MyType2", new Date(), State.STOPPED);
|
||||
Order res4 = ModelGenerator.createOrder("@4", "Order 4", "MyType2", new Date(), State.PLANNING);
|
||||
Order res5 = ModelGenerator.createOrder("@5", "Order 5", "MyType3", new Date(), State.ERROR);
|
||||
Order res6 = ModelGenerator.createOrder("@6", "Order 6", "MyType3", new Date(), State.CLOSED);
|
||||
List<Order> orders = new ArrayList<>();
|
||||
orders.add(res1);
|
||||
orders.add(res2);
|
||||
|
|
|
@ -20,8 +20,8 @@ import li.strolch.model.query.ordering.StrolchQueryOrderingVisitor;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface ActivityQueryVisitor extends StrolchRootElementSelectionVisitor, ParameterSelectionVisitor,
|
||||
StrolchQueryOrderingVisitor {
|
||||
public interface ActivityQueryVisitor
|
||||
extends ActivitySelectionVisitor, ParameterSelectionVisitor, StrolchQueryOrderingVisitor {
|
||||
|
||||
// marker interface
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* 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 li.strolch.model.query;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public abstract class ActivitySelection implements Selection {
|
||||
|
||||
@Override
|
||||
public void accept(QueryVisitor visitor) {
|
||||
accept((ActivitySelectionVisitor) visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSelection() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void accept(ActivitySelectionVisitor visitor);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* 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 li.strolch.model.query;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface ActivitySelectionVisitor extends StrolchRootElementSelectionVisitor {
|
||||
|
||||
public void visit(ActivityStateSelection selection);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* 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 li.strolch.model.query;
|
||||
|
||||
import li.strolch.model.State;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ActivityStateSelection extends ActivitySelection {
|
||||
|
||||
private State state;
|
||||
|
||||
public ActivityStateSelection(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ActivitySelectionVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
|
@ -17,11 +17,10 @@ package li.strolch.model.query;
|
|||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public interface OrderSelectionVisitor extends StrolchRootElementSelectionVisitor {
|
||||
|
||||
public void visit(DateSelection selection);
|
||||
|
||||
public void visit(StateSelection selection);
|
||||
public void visit(OrderStateSelection selection);
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ import li.strolch.model.State;
|
|||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class StateSelection extends OrderSelection {
|
||||
public class OrderStateSelection extends OrderSelection {
|
||||
|
||||
private State state;
|
||||
|
||||
public StateSelection(State state) {
|
||||
public OrderStateSelection(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
protected void internalSave(final Activity activity) {
|
||||
|
||||
String sql = "insert into " + getTableName()
|
||||
+ " (id, version, created_by, created_at, deleted, latest, name, type, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
+ " (id, version, created_by, created_at, deleted, latest, name, type, state, asxml) values (?, ?, ?, ?, ?, ?, ?, ?, ?::order_state, ?)";
|
||||
|
||||
try (PreparedStatement preparedStatement = tx().getConnection().prepareStatement(sql)) {
|
||||
|
||||
|
@ -118,9 +118,10 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
// attributes
|
||||
preparedStatement.setString(7, activity.getName());
|
||||
preparedStatement.setString(8, activity.getType());
|
||||
preparedStatement.setString(9, activity.getState().name());
|
||||
|
||||
SQLXML sqlxml = createSqlXml(activity, preparedStatement);
|
||||
preparedStatement.setSQLXML(9, sqlxml);
|
||||
preparedStatement.setSQLXML(10, sqlxml);
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
@ -189,7 +190,7 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
}
|
||||
|
||||
String sql = "update " + getTableName()
|
||||
+ " set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, asxml = ? where id = ? and version = ?";
|
||||
+ " set created_by = ?, created_at = ?, deleted = ?, latest = ?, name = ?, type = ?, state = ?, asxml = ? where id = ? and version = ?";
|
||||
|
||||
try (PreparedStatement preparedStatement = tx().getConnection().prepareStatement(sql)) {
|
||||
|
||||
|
@ -204,13 +205,14 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
// attributes
|
||||
preparedStatement.setString(5, activity.getName());
|
||||
preparedStatement.setString(6, activity.getType());
|
||||
preparedStatement.setString(7, activity.getState().name());
|
||||
|
||||
SQLXML sqlxml = createSqlXml(activity, preparedStatement);
|
||||
preparedStatement.setSQLXML(7, sqlxml);
|
||||
preparedStatement.setSQLXML(8, sqlxml);
|
||||
|
||||
// primary key
|
||||
preparedStatement.setString(8, activity.getId());
|
||||
preparedStatement.setInt(9, activity.getVersion().getVersion());
|
||||
preparedStatement.setString(9, activity.getId());
|
||||
preparedStatement.setInt(10, activity.getVersion().getVersion());
|
||||
|
||||
try {
|
||||
int modCount = preparedStatement.executeUpdate();
|
||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.persistence.postgresql;
|
|||
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.query.ActivityQueryVisitor;
|
||||
import li.strolch.model.query.ActivityStateSelection;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -39,4 +40,11 @@ public class PostgreSqlActivityQueryVisitor extends PostgreSqlQueryVisitor imple
|
|||
protected String getTableName() {
|
||||
return PostgreSqlActivityDao.ACTIVITIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ActivityStateSelection selection) {
|
||||
this.sb.append(this.indent);
|
||||
this.sb.append("state = ?::order_state\n");
|
||||
this.values.add(selection.getState().name());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ package li.strolch.persistence.postgresql;
|
|||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.query.DateSelection;
|
||||
import li.strolch.model.query.OrderQueryVisitor;
|
||||
import li.strolch.model.query.StateSelection;
|
||||
import li.strolch.model.query.OrderStateSelection;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -48,7 +48,7 @@ public class PostgreSqlOrderQueryVisitor extends PostgreSqlQueryVisitor implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public void visit(StateSelection selection) {
|
||||
public void visit(OrderStateSelection selection) {
|
||||
this.sb.append(this.indent);
|
||||
this.sb.append("state = ?::order_state\n");
|
||||
this.values.add(selection.getState().name());
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
DROP TABLE IF EXISTS resources;
|
||||
DROP TABLE IF EXISTS orders;
|
||||
DROP TABLE IF EXISTS activities;
|
||||
|
||||
DROP TABLE IF EXISTS audits;
|
||||
|
||||
DROP TABLE IF EXISTS db_version;
|
||||
|
||||
DROP TYPE IF EXISTS order_state;
|
||||
DROP TYPE IF EXISTS access_type;
|
|
@ -0,0 +1,141 @@
|
|||
|
||||
-- DB_VERSION
|
||||
CREATE TABLE IF NOT EXISTS db_version (
|
||||
id serial primary key not null,
|
||||
app varchar(255) not null,
|
||||
version varchar(255) not null,
|
||||
description varchar(255) not null,
|
||||
created timestamp with time zone not null
|
||||
);
|
||||
|
||||
-- RESOURCES
|
||||
CREATE TABLE IF NOT EXISTS resources (
|
||||
id varchar(255) not null,
|
||||
version integer not null,
|
||||
created_by varchar(255) not null,
|
||||
created_at timestamp with time zone not null,
|
||||
deleted boolean not null,
|
||||
latest boolean not null,
|
||||
name varchar(255) not null,
|
||||
type varchar(255) not null,
|
||||
asxml xml not null,
|
||||
|
||||
PRIMARY KEY (id, version)
|
||||
);
|
||||
|
||||
-- ORDERS
|
||||
CREATE TYPE order_state AS ENUM ('CREATED', 'OPEN', 'EXECUTION', 'CLOSED');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
id varchar(255) not null,
|
||||
version integer not null,
|
||||
created_by varchar(255) not null,
|
||||
created_at timestamp with time zone not null,
|
||||
deleted boolean,
|
||||
latest boolean not null,
|
||||
name varchar(255),
|
||||
type varchar(255),
|
||||
state order_state,
|
||||
date timestamp with time zone,
|
||||
asxml xml not null,
|
||||
|
||||
PRIMARY KEY (id, version)
|
||||
);
|
||||
|
||||
-- ACTIVITIES
|
||||
CREATE TABLE IF NOT EXISTS activities (
|
||||
id varchar(255) not null,
|
||||
version integer not null,
|
||||
created_by varchar(255) not null,
|
||||
created_at timestamp with time zone not null,
|
||||
deleted boolean not null,
|
||||
latest boolean not null,
|
||||
name varchar(255) not null,
|
||||
type varchar(255) not null,
|
||||
state order_state,
|
||||
asxml xml not null,
|
||||
|
||||
PRIMARY KEY (id, version)
|
||||
);
|
||||
|
||||
-- AUDITS
|
||||
CREATE TYPE access_type AS ENUM ('READ', 'CREATE', 'UPDATE', 'DELETE');
|
||||
CREATE TABLE IF NOT EXISTS audits (
|
||||
id bigint PRIMARY KEY,
|
||||
username varchar(255) NOT NULL,
|
||||
firstname varchar(255) NOT NULL,
|
||||
lastname varchar(255) NOT NULL,
|
||||
date timestamp with time zone NOT NULL,
|
||||
|
||||
element_type varchar(255) NOT NULL,
|
||||
element_sub_type varchar(255) NOT NULL,
|
||||
element_accessed varchar(255) NOT NULL,
|
||||
new_version timestamp with time zone,
|
||||
|
||||
action varchar(255) NOT NULL,
|
||||
access_type access_type NOT NULL
|
||||
);
|
||||
|
||||
-- set version
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.1.0',
|
||||
'strolch',
|
||||
'Initial schema version',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.2.0',
|
||||
'strolch',
|
||||
'Added new table for audits',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.2.1',
|
||||
'strolch',
|
||||
'Added new column app to table table version',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.3.0',
|
||||
'strolch',
|
||||
'Added new column element_sub_type to table audits',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.4.0',
|
||||
'strolch',
|
||||
'Added new table activities',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.5.0',
|
||||
'strolch',
|
||||
'Added versioning to root elements',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.5.1',
|
||||
'strolch',
|
||||
'Added state column to activity',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
-- add version columns
|
||||
ALTER TABLE activities ADD COLUMN state order_state;
|
||||
|
||||
INSERT INTO db_version
|
||||
(version, app, description, created)
|
||||
values(
|
||||
'0.5.1',
|
||||
'strolch',
|
||||
'Added state column to activity',
|
||||
CURRENT_TIMESTAMP
|
||||
);
|
|
@ -1,2 +1,2 @@
|
|||
# Property file defining what the currently expected version is supposed to be
|
||||
db_version=0.5.0
|
||||
db_version=0.5.1
|
||||
|
|
|
@ -0,0 +1,251 @@
|
|||
package li.strolch.persistence.postgresql.dao.test;
|
||||
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.CONFIG_SRC;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_PASSWORD;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_STORE_PATH_DIR;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_URL;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_USERNAME;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.RUNTIME_PATH;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.dropSchema;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.agent.api.ActivityMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.activity.TimeOrdering;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.ActivityStateSelection;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ordering.OrderById;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
import li.strolch.utils.StringMatchMode;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
|
||||
public class ActivityQueryTest extends QueryTest {
|
||||
|
||||
private static RuntimeMock runtimeMock;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
runtimeMock = new RuntimeMock();
|
||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
Certificate cert = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes());
|
||||
StrolchRealm realm = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM);
|
||||
try (StrolchTransaction tx = realm.openTx(cert, "test")) {
|
||||
ActivityMap activityMap = tx.getActivityMap();
|
||||
|
||||
Activity activity = ModelGenerator.createActivity("@1", "Activity 1", "MyType1", TimeOrdering.SERIES);
|
||||
activityMap.add(tx, activity);
|
||||
|
||||
activity = ModelGenerator.createActivity("@2", "Activity 2", "MyType1", TimeOrdering.SERIES);
|
||||
((Action) activity.getElement("action_" + activity.getId())).setState(State.EXECUTION);
|
||||
activityMap.add(tx, activity);
|
||||
|
||||
activity = ModelGenerator.createActivity("@3", "Activity 3", "MyType1", TimeOrdering.SERIES);
|
||||
((Action) activity.getElement("action_" + activity.getId())).setState(State.CLOSED);
|
||||
activityMap.add(tx, activity);
|
||||
|
||||
activity = ModelGenerator.createActivity("@4", "Activity 4", "MyType2", TimeOrdering.SERIES);
|
||||
((Action) activity.getElement("action_" + activity.getId())).setState(State.CREATED);
|
||||
activityMap.add(tx, activity);
|
||||
|
||||
activity = ModelGenerator.createActivity("@5", "Activity 5", "MyType2", TimeOrdering.SERIES);
|
||||
((Action) activity.getElement("action_" + activity.getId())).setState(State.CLOSED);
|
||||
activityMap.add(tx, activity);
|
||||
|
||||
activity = ModelGenerator.createActivity("@6", "Activity 6", "MyType2", TimeOrdering.SERIES);
|
||||
((Action) activity.getElement("action_" + activity.getId())).setState(State.CLOSED);
|
||||
activityMap.add(tx, activity);
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
|
||||
public Connection openConn() throws SQLException {
|
||||
String url = "jdbc:postgresql://localhost/testdb";
|
||||
String username = "testuser";
|
||||
String password = "test";
|
||||
Connection connection = DriverManager.getConnection(url, username, password);
|
||||
connection.setAutoCommit(false);
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityAll() throws SQLException {
|
||||
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.withAny();
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByState() throws SQLException {
|
||||
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1");
|
||||
query.and().with(new ActivityStateSelection(State.CREATED));
|
||||
performActivityQuery(query, Arrays.asList("@1"));
|
||||
|
||||
query = ActivityQuery.query("MyType1");
|
||||
query.and().with(new ActivityStateSelection(State.EXECUTION));
|
||||
performActivityQuery(query, Arrays.<String> asList("@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivity1() throws SQLException {
|
||||
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("Activity 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performActivityQuery(query, Arrays.asList("@1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivity2() throws SQLException {
|
||||
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.or().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("activity 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByBooleParam() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByFloatParam() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.floatSelection("@bag01", "@param2", 44.3));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByIntegerParam() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.integerSelection("@bag01", "@param3", 77));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByLongParam() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType2", new OrderById());
|
||||
query.and().with(ParameterSelection.longSelection("@bag01", "@param4", 4453234566L));
|
||||
performActivityQuery(query, Arrays.asList("@4", "@5", "@6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByStringParam() throws SQLException {
|
||||
|
||||
List<String> expected = Arrays.asList("@1", "@2", "@3");
|
||||
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performActivityQuery(query, expected);
|
||||
|
||||
query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performActivityQuery(query, Arrays.<String> asList());
|
||||
|
||||
query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
performActivityQuery(query, expected);
|
||||
|
||||
query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE));
|
||||
performActivityQuery(query, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByDateParam() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateSelection("@bag01", "@param6", new Date(1354295525628L)));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Ignore("Not yet implemented")
|
||||
@Test
|
||||
public void shouldQueryActivityByDateRange() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateRangeSelection("@bag01", "@param6",
|
||||
new DateRange().from(new Date(1354295525627L), false).to(new Date(1354295525629L), false)));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByDurationParam() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.durationSelection("@bag01", "@param8", "P1D"));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByNullParam1() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param6"));
|
||||
performActivityQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByNullParam2() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param"));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByBag() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new ParameterBagSelection("@bag01"));
|
||||
performActivityQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryActivityByNullBag() throws SQLException {
|
||||
ActivityQuery<Activity> query = ActivityQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new NullParameterBagSelection("@bag01"));
|
||||
performActivityQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,298 @@
|
|||
package li.strolch.persistence.postgresql.dao.test;
|
||||
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.CONFIG_SRC;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_PASSWORD;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_STORE_PATH_DIR;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_URL;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_USERNAME;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.RUNTIME_PATH;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.dropSchema;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.query.DateSelection;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.OrderStateSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ordering.OrderById;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
import li.strolch.utils.StringMatchMode;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
|
||||
public class OrderQueryTest extends QueryTest {
|
||||
|
||||
private static RuntimeMock runtimeMock;
|
||||
|
||||
private static Date past;
|
||||
private static Date earlier;
|
||||
private static Date current;
|
||||
private static Date later;
|
||||
private static Date future;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
runtimeMock = new RuntimeMock();
|
||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(2000, 1, 1);
|
||||
past = cal.getTime();
|
||||
cal.set(2000, 4, 1);
|
||||
earlier = cal.getTime();
|
||||
cal.set(2000, 6, 1);
|
||||
current = cal.getTime();
|
||||
cal.set(2000, 8, 1);
|
||||
later = cal.getTime();
|
||||
cal.set(2000, 11, 1);
|
||||
future = cal.getTime();
|
||||
|
||||
Certificate cert = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes());
|
||||
StrolchRealm realm = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM);
|
||||
try (StrolchTransaction tx = realm.openTx(cert, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@1", "Order 1", "MyType1", earlier, State.CREATED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@2", "Order 2", "MyType1", current, State.EXECUTION));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@3", "Order 3", "MyType1", later, State.CLOSED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@4", "Order 4", "MyType2", earlier, State.CREATED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@5", "Order 5", "MyType2", current, State.CLOSED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@6", "Order 6", "MyType2", later, State.CLOSED));
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
|
||||
public Connection openConn() throws SQLException {
|
||||
String url = "jdbc:postgresql://localhost/testdb";
|
||||
String username = "testuser";
|
||||
String password = "test";
|
||||
Connection connection = DriverManager.getConnection(url, username, password);
|
||||
connection.setAutoCommit(false);
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderAll() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.withAny();
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByDate() throws SQLException {
|
||||
|
||||
// range
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new DateSelection().from(earlier, false).to(later, false));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
|
||||
// equals current
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(current, false).to(current, false));
|
||||
performOrderQuery(query, Arrays.asList("@2"));
|
||||
|
||||
// equals later
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(later, false).to(later, false));
|
||||
performOrderQuery(query, Arrays.<String> asList("@3"));
|
||||
|
||||
// equals earlier
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(earlier, false).to(earlier, false));
|
||||
performOrderQuery(query, Arrays.<String> asList("@1"));
|
||||
|
||||
// past
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().to(past, false));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
|
||||
// future
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(future, false));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
|
||||
// earlier
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(past, false).to(earlier, true));
|
||||
performOrderQuery(query, Arrays.<String> asList("@1"));
|
||||
|
||||
// later
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(later, false).to(future, true));
|
||||
performOrderQuery(query, Arrays.<String> asList("@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByState() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1");
|
||||
query.and().with(new OrderStateSelection(State.CREATED));
|
||||
performOrderQuery(query, Arrays.asList("@1"));
|
||||
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new OrderStateSelection(State.EXECUTION));
|
||||
performOrderQuery(query, Arrays.<String> asList("@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrder1() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("Order 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, Arrays.asList("@1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrder2() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.or().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("order 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByBooleParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByFloatParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.floatSelection("@bag01", "@param2", 44.3));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByIntegerParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.integerSelection("@bag01", "@param3", 77));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByLongParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType2", new OrderById());
|
||||
query.and().with(ParameterSelection.longSelection("@bag01", "@param4", 4453234566L));
|
||||
performOrderQuery(query, Arrays.asList("@4", "@5", "@6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByStringParam() throws SQLException {
|
||||
|
||||
List<String> expected = Arrays.asList("@1", "@2", "@3");
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, expected);
|
||||
|
||||
query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
|
||||
query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
performOrderQuery(query, expected);
|
||||
|
||||
query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE));
|
||||
performOrderQuery(query, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByDateParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateSelection("@bag01", "@param6", new Date(1354295525628L)));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Ignore("Not yet implemented")
|
||||
@Test
|
||||
public void shouldQueryOrderByDateRange() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateRangeSelection("@bag01", "@param6",
|
||||
new DateRange().from(new Date(1354295525627L), false).to(new Date(1354295525629L), false)));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByDurationParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.durationSelection("@bag01", "@param8", "P1D"));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByNullParam1() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param6"));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByNullParam2() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param"));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByBag() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new ParameterBagSelection("@bag01"));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByNullBag() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new NullParameterBagSelection("@bag01"));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
}
|
|
@ -15,133 +15,38 @@
|
|||
*/
|
||||
package li.strolch.persistence.postgresql.dao.test;
|
||||
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.CONFIG_SRC;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_PASSWORD;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_STORE_PATH_DIR;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_URL;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_USERNAME;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.RUNTIME_PATH;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.dropSchema;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.State;
|
||||
import li.strolch.model.query.DateSelection;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.OrSelection;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.query.StateSelection;
|
||||
import li.strolch.model.query.ordering.OrderById;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.postgresql.PostgreSqlActivityQueryVisitor;
|
||||
import li.strolch.persistence.postgresql.PostgreSqlOrderQueryVisitor;
|
||||
import li.strolch.persistence.postgresql.PostgreSqlQueryVisitor;
|
||||
import li.strolch.persistence.postgresql.PostgreSqlResourceQueryVisitor;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
import li.strolch.utils.StringMatchMode;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class QueryTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QueryTest.class);
|
||||
private static RuntimeMock runtimeMock;
|
||||
protected static final Logger logger = LoggerFactory.getLogger(QueryTest.class);
|
||||
|
||||
private static Date past;
|
||||
private static Date earlier;
|
||||
private static Date current;
|
||||
private static Date later;
|
||||
private static Date future;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
runtimeMock = new RuntimeMock();
|
||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(2000, 1, 1);
|
||||
past = cal.getTime();
|
||||
cal.set(2000, 4, 1);
|
||||
earlier = cal.getTime();
|
||||
cal.set(2000, 6, 1);
|
||||
current = cal.getTime();
|
||||
cal.set(2000, 8, 1);
|
||||
later = cal.getTime();
|
||||
cal.set(2000, 11, 1);
|
||||
future = cal.getTime();
|
||||
|
||||
Certificate cert = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes());
|
||||
StrolchRealm realm = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM);
|
||||
try (StrolchTransaction tx = realm.openTx(cert, "test")) {
|
||||
OrderMap orderMap = tx.getOrderMap();
|
||||
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@1", "Order 1", "MyType1", earlier, State.CREATED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@2", "Order 2", "MyType1", current, State.EXECUTION));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@3", "Order 3", "MyType1", later, State.CLOSED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@4", "Order 4", "MyType2", earlier, State.CREATED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@5", "Order 5", "MyType2", current, State.CLOSED));
|
||||
orderMap.add(tx, ModelGenerator.createOrder("@6", "Order 6", "MyType2", later, State.CLOSED));
|
||||
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@1", "Resource 1", "MyType1"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@2", "Resource 2", "MyType1"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@3", "Resource 3", "MyType1"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@4", "Resource 4", "MyType2"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@5", "Resource 5", "MyType2"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@6", "Resource 6", "MyType2"));
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
|
||||
public Connection openConn() throws SQLException {
|
||||
protected Connection openConn() throws SQLException {
|
||||
String url = "jdbc:postgresql://localhost/testdb";
|
||||
String username = "testuser";
|
||||
String password = "test";
|
||||
|
@ -150,355 +55,21 @@ public class QueryTest {
|
|||
return connection;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderAll() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.withAny();
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceAll() throws SQLException {
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType2", new OrderById(false));
|
||||
query.withAny();
|
||||
performResourceQuery(query, Arrays.asList("@6", "@5", "@4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByDate() throws SQLException {
|
||||
|
||||
// range
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new DateSelection().from(earlier, false).to(later, false));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
|
||||
// equals current
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(current, false).to(current, false));
|
||||
performOrderQuery(query, Arrays.asList("@2"));
|
||||
|
||||
// equals later
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(later, false).to(later, false));
|
||||
performOrderQuery(query, Arrays.<String> asList("@3"));
|
||||
|
||||
// equals earlier
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(earlier, false).to(earlier, false));
|
||||
performOrderQuery(query, Arrays.<String> asList("@1"));
|
||||
|
||||
// past
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().to(past, false));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
|
||||
// future
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(future, false));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
|
||||
// earlier
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(past, false).to(earlier, true));
|
||||
performOrderQuery(query, Arrays.<String> asList("@1"));
|
||||
|
||||
// later
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new DateSelection().from(later, false).to(future, true));
|
||||
performOrderQuery(query, Arrays.<String> asList("@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByState() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1");
|
||||
query.and().with(new StateSelection(State.CREATED));
|
||||
performOrderQuery(query, Arrays.asList("@1"));
|
||||
|
||||
query = OrderQuery.query("MyType1");
|
||||
query.and().with(new StateSelection(State.EXECUTION));
|
||||
performOrderQuery(query, Arrays.<String> asList("@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrder1() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("Order 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, Arrays.asList("@1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrder2() throws SQLException {
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.or().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("order 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByBooleParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByFloagParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.floatSelection("@bag01", "@param2", 44.3));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByIntegerParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.integerSelection("@bag01", "@param3", 77));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByLongParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType2", new OrderById());
|
||||
query.and().with(ParameterSelection.longSelection("@bag01", "@param4", 4453234566L));
|
||||
performOrderQuery(query, Arrays.asList("@4", "@5", "@6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByStringParam() throws SQLException {
|
||||
|
||||
List<String> expected = Arrays.asList("@1", "@2", "@3");
|
||||
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, expected);
|
||||
|
||||
query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
|
||||
query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
performOrderQuery(query, expected);
|
||||
|
||||
query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE));
|
||||
performOrderQuery(query, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByDateParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateSelection("@bag01", "@param6", new Date(1354295525628L)));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Ignore("Not yet implemented")
|
||||
@Test
|
||||
public void shouldQueryOrderByDateRange() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateRangeSelection("@bag01", "@param6",
|
||||
new DateRange().from(new Date(1354295525627L), false).to(new Date(1354295525629L), false)));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByDurationParam() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.durationSelection("@bag01", "@param8", "P1D"));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByNullParam1() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param6"));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByNullParam2() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param"));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByBag() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new ParameterBagSelection("@bag01"));
|
||||
performOrderQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryOrderByNullBag() throws SQLException {
|
||||
OrderQuery<Order> query = OrderQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new NullParameterBagSelection("@bag01"));
|
||||
performOrderQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResource1() throws SQLException {
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.or().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("Resource 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResource2() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new OrSelection(new IdSelection("@1"), new IdSelection("@2")),
|
||||
new OrSelection(new NameSelection("Resource 1", StringMatchMode.EQUALS_CASE_SENSITIVE),
|
||||
new NameSelection("Resource 2", StringMatchMode.EQUALS_CASE_SENSITIVE)));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByBooleParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByFloagParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.floatSelection("@bag01", "@param2", 44.3));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByIntegerParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.integerSelection("@bag01", "@param3", 77));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByLongParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType2", new OrderById());
|
||||
query.and().with(ParameterSelection.longSelection("@bag01", "@param4", 4453234566L));
|
||||
performResourceQuery(query, Arrays.asList("@4", "@5", "@6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByStringParam() throws SQLException {
|
||||
|
||||
List<String> expected = Arrays.asList("@1", "@2", "@3");
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, Arrays.<String> asList());
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and()
|
||||
.with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE),
|
||||
ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE),
|
||||
ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByAnyTypeParam() throws SQLException {
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.anyTypeSelection("@bag01", "@param6",
|
||||
ISO8601FormatFactory.getInstance().formatDate(new Date(1354295525628L)), StringMatchMode.ci()));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.anyTypeSelection("@bag01", "@param8", "P1D", StringMatchMode.ci()));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByDateParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateSelection("@bag01", "@param6", new Date(1354295525628L)));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Ignore("Not yet implemented")
|
||||
@Test
|
||||
public void shouldQueryResourceByDateRange() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateRangeSelection("@bag01", "@param6",
|
||||
new DateRange().from(new Date(1354295525627L), false).to(new Date(1354295525629L), false)));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByDurationParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.durationSelection("@bag01", "@param8", "P1D"));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByNullParam1() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param6"));
|
||||
performResourceQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByNullParam2() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param"));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByBag() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new ParameterBagSelection("@bag01"));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByNullBag() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new NullParameterBagSelection("@bag01"));
|
||||
performResourceQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
private void performOrderQuery(OrderQuery<Order> query, List<String> expected) throws SQLException {
|
||||
protected void performOrderQuery(OrderQuery<Order> query, List<String> expected) throws SQLException {
|
||||
PostgreSqlOrderQueryVisitor visitor = new PostgreSqlOrderQueryVisitor("id");
|
||||
query.accept(visitor);
|
||||
List<String> ids = queryIds(visitor);
|
||||
assertEquals(expected, ids);
|
||||
}
|
||||
|
||||
private void performResourceQuery(ResourceQuery<Resource> query, List<String> expected) throws SQLException {
|
||||
protected void performActivityQuery(ActivityQuery<Activity> query, List<String> expected) throws SQLException {
|
||||
PostgreSqlActivityQueryVisitor visitor = new PostgreSqlActivityQueryVisitor("id");
|
||||
query.accept(visitor);
|
||||
List<String> ids = queryIds(visitor);
|
||||
assertEquals(expected, ids);
|
||||
}
|
||||
|
||||
protected void performResourceQuery(ResourceQuery<Resource> query, List<String> expected) throws SQLException {
|
||||
PostgreSqlResourceQueryVisitor visitor = new PostgreSqlResourceQueryVisitor("id");
|
||||
query.accept(visitor);
|
||||
List<String> ids = queryIds(visitor);
|
||||
|
|
|
@ -0,0 +1,234 @@
|
|||
package li.strolch.persistence.postgresql.dao.test;
|
||||
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.CONFIG_SRC;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_PASSWORD;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_STORE_PATH_DIR;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_URL;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.DB_USERNAME;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.RUNTIME_PATH;
|
||||
import static li.strolch.persistence.postgresql.dao.test.CachedDaoTest.dropSchema;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.agent.api.StrolchRealm;
|
||||
import li.strolch.model.ModelGenerator;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.query.IdSelection;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.OrSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.query.ordering.OrderById;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
import li.strolch.utils.StringMatchMode;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||
|
||||
public class ResourceDaoTest extends QueryTest {
|
||||
|
||||
private static RuntimeMock runtimeMock;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
dropSchema(DB_URL, DB_USERNAME, DB_PASSWORD);
|
||||
|
||||
File rootPath = new File(RUNTIME_PATH);
|
||||
File configSrc = new File(CONFIG_SRC);
|
||||
runtimeMock = new RuntimeMock();
|
||||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
|
||||
runtimeMock.startContainer();
|
||||
|
||||
Certificate cert = runtimeMock.getPrivilegeHandler().authenticate("test", "test".getBytes());
|
||||
StrolchRealm realm = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM);
|
||||
try (StrolchTransaction tx = realm.openTx(cert, "test")) {
|
||||
|
||||
ResourceMap resourceMap = tx.getResourceMap();
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@1", "Resource 1", "MyType1"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@2", "Resource 2", "MyType1"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@3", "Resource 3", "MyType1"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@4", "Resource 4", "MyType2"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@5", "Resource 5", "MyType2"));
|
||||
resourceMap.add(tx, ModelGenerator.createResource("@6", "Resource 6", "MyType2"));
|
||||
|
||||
tx.commitOnClose();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
if (runtimeMock != null)
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceAll() throws SQLException {
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType2", new OrderById(false));
|
||||
query.withAny();
|
||||
performResourceQuery(query, Arrays.asList("@6", "@5", "@4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResource1() throws SQLException {
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.or().with(new IdSelection("@1", "@2"),
|
||||
new NameSelection("Resource 1", StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResource2() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new OrSelection(new IdSelection("@1"), new IdSelection("@2")),
|
||||
new OrSelection(new NameSelection("Resource 1", StringMatchMode.EQUALS_CASE_SENSITIVE),
|
||||
new NameSelection("Resource 2", StringMatchMode.EQUALS_CASE_SENSITIVE)));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByBooleParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.booleanSelection("@bag01", "@param1", true));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByFloatParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.floatSelection("@bag01", "@param2", 44.3));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByIntegerParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.integerSelection("@bag01", "@param3", 77));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByLongParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType2", new OrderById());
|
||||
query.and().with(ParameterSelection.longSelection("@bag01", "@param4", 4453234566L));
|
||||
performResourceQuery(query, Arrays.asList("@4", "@5", "@6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByStringParam() throws SQLException {
|
||||
|
||||
List<String> expected = Arrays.asList("@1", "@2", "@3");
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, Arrays.<String> asList());
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.EQUALS_CASE_INSENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and()
|
||||
.with(ParameterSelection.stringSelection("@bag01", "@param5", "olch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE),
|
||||
ParameterSelection.stringSelection("@bag01", "@param5", "strolch",
|
||||
StringMatchMode.CONTAINS_CASE_INSENSITIVE),
|
||||
ParameterSelection.stringSelection("@bag01", "@param5", "Strolch",
|
||||
StringMatchMode.EQUALS_CASE_SENSITIVE));
|
||||
performResourceQuery(query, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByAnyTypeParam() throws SQLException {
|
||||
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.anyTypeSelection("@bag01", "@param6",
|
||||
ISO8601FormatFactory.getInstance().formatDate(new Date(1354295525628L)), StringMatchMode.ci()));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
|
||||
query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.anyTypeSelection("@bag01", "@param8", "P1D", StringMatchMode.ci()));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByDateParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateSelection("@bag01", "@param6", new Date(1354295525628L)));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Ignore("Not yet implemented")
|
||||
@Test
|
||||
public void shouldQueryResourceByDateRange() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.dateRangeSelection("@bag01", "@param6",
|
||||
new DateRange().from(new Date(1354295525627L), false).to(new Date(1354295525629L), false)));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByDurationParam() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.durationSelection("@bag01", "@param8", "P1D"));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByNullParam1() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param6"));
|
||||
performResourceQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByNullParam2() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(ParameterSelection.nullSelection("@bag01", "@param"));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByBag() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new ParameterBagSelection("@bag01"));
|
||||
performResourceQuery(query, Arrays.asList("@1", "@2", "@3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldQueryResourceByNullBag() throws SQLException {
|
||||
ResourceQuery<Resource> query = ResourceQuery.query("MyType1", new OrderById());
|
||||
query.and().with(new NullParameterBagSelection("@bag01"));
|
||||
performResourceQuery(query, Arrays.<String> asList());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue