[New] Added tests for Command.undo() for all Command implementations

Except for the XML Import and Export commands...
This commit is contained in:
Robert von Burg 2014-03-10 22:34:36 +01:00
parent 411b7e00df
commit 5e088b7a52
17 changed files with 916 additions and 20 deletions

View File

@ -0,0 +1,145 @@
/*
* 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.command;
import static li.strolch.service.test.AbstractRealmServiceTest.CONFIG_SRC;
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_CACHED;
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSACTIONAL;
import static li.strolch.service.test.AbstractRealmServiceTest.REALM_TRANSIENT;
import static li.strolch.service.test.AbstractRealmServiceTest.RUNTIME_PATH;
import static li.strolch.service.test.AbstractRealmServiceTest.dropSchema;
import static li.strolch.service.test.AbstractRealmServiceTest.importFromXml;
import java.io.File;
import java.sql.SQLException;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.agent.api.StrolchRealm;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import li.strolch.service.api.ServiceHandler;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractRealmCommandTest {
protected static RuntimeMock runtimeMock;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@BeforeClass
public static void beforeClass() throws SQLException {
dropSchema("jdbc:postgresql://localhost/cacheduserdb", "cacheduser", "test");
dropSchema("jdbc:postgresql://localhost/transactionaluserdb", "transactionaluser", "test");
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
importFromXml(REALM_CACHED, getServiceHandler());
importFromXml(REALM_TRANSACTIONAL, getServiceHandler());
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
}
protected abstract Command getCommandInstance(ComponentContainer container, StrolchTransaction tx);
protected void doCommandAsFail(String realmName) {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Fail on purpose after do command!");
StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName);
try (StrolchTransaction tx = realm.openTx()) {
Command command = getCommandInstance(runtimeMock.getContainer(), tx);
FailCommandFacade commandFacade = new FailCommandFacade(runtimeMock.getContainer(), tx, command);
tx.addCommand(commandFacade);
}
}
protected void doCommand(String realmName) {
StrolchRealm realm = runtimeMock.getContainer().getRealm(realmName);
try (StrolchTransaction tx = realm.openTx()) {
Command command = getCommandInstance(runtimeMock.getContainer(), tx);
tx.addCommand(command);
}
}
@Test
public void shouldFailCommandTransient() {
doCommandAsFail(REALM_TRANSIENT);
}
@Test
public void shouldFailCommandCached() {
doCommandAsFail(REALM_CACHED);
}
@Test
public void shouldFailCommandTransactional() {
doCommandAsFail(REALM_TRANSACTIONAL);
}
private class FailCommandFacade extends Command {
private Command command;
/**
* @param container
* @param tx
*/
public FailCommandFacade(ComponentContainer container, StrolchTransaction tx, Command command) {
super(container, tx);
this.command = command;
}
@Override
public void validate() {
this.command.validate();
}
@Override
public void doCommand() {
this.command.doCommand();
throw new RuntimeException("Fail on purpose after do command!");
}
@Override
public void undo() {
this.command.undo();
}
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.command;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCollectionCommandTest extends AbstractRealmCommandTest {
private List<Order> orders;
@Before
public void before() {
orders = new ArrayList<>();
orders.add(ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders"));
orders.add(ModelGenerator.createOrder("secondOrder", "Second Order", "AdditionalOrders"));
orders.add(ModelGenerator.createOrder("thirdOrder", "Third Order", "AdditionalOrders"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddOrderCollectionCommand command = new AddOrderCollectionCommand(container, tx);
command.setOrders(orders);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.command;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddOrderCommandTest extends AbstractRealmCommandTest {
private Order order;
@Before
public void before() {
order = ModelGenerator.createOrder("firstOrder", "First Order", "AdditionalOrders");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddOrderCommand command = new AddOrderCommand(container, tx);
command.setOrder(order);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.command;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCollectionCommandTest extends AbstractRealmCommandTest {
private List<Resource> resources;
@Before
public void before() {
resources = new ArrayList<>();
resources.add(ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources"));
resources.add(ModelGenerator.createResource("secondRes", "Second Resource", "AdditionalResources"));
resources.add(ModelGenerator.createResource("thirdRes", "Third Resource", "AdditionalResources"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddResourceCollectionCommand command = new AddResourceCollectionCommand(container, tx);
command.setResources(resources);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.command;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddResourceCommandTest extends AbstractRealmCommandTest {
private Resource resource;
@Before
public void before() {
resource = ModelGenerator.createResource("firstRes", "First Resource", "AdditionalResources");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
AddResourceCommand command = new AddResourceCommand(container, tx);
command.setResource(resource);
return command;
}
}

View File

@ -0,0 +1,57 @@
/*
* 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.command;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCollectionCommandTest extends AbstractRealmCommandTest {
private List<Locator> locators;
@Before
public void before() {
locators = new ArrayList<>();
locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@1").build());
locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@2").build());
locators.add(Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build());
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
List<Order> orders = new ArrayList<>(locators.size());
for (Locator locator : locators) {
orders.add((Order) tx.findElement(locator));
}
RemoveOrderCollectionCommand command = new RemoveOrderCollectionCommand(container, tx);
command.setOrders(orders);
return command;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.command;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveOrderCommandTest extends AbstractRealmCommandTest {
private Locator locator;
@Before
public void before() {
locator = Locator.newBuilder(Tags.ORDER).append("TestType").append("@3").build();
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
Order order = tx.findElement(locator);
RemoveOrderCommand command = new RemoveOrderCommand(container, tx);
command.setOrder(order);
return command;
}
}

View File

@ -0,0 +1,57 @@
/*
* 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.command;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCollectionCommandTest extends AbstractRealmCommandTest {
private List<Locator> locators;
@Before
public void before() {
locators = new ArrayList<>();
locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("salutations").build());
locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build());
locators.add(Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("religions").build());
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
List<Resource> resources = new ArrayList<>(locators.size());
for (Locator locator : this.locators) {
resources.add((Resource) tx.findElement(locator));
}
RemoveResourceCollectionCommand command = new RemoveResourceCollectionCommand(container, tx);
command.setResources(resources);
return command;
}
}

View File

@ -0,0 +1,48 @@
/*
* 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.command;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveResourceCommandTest extends AbstractRealmCommandTest {
private Locator locator;
@Before
public void before() {
locator = Locator.newBuilder(Tags.RESOURCE).append("Enumeration").append("sex").build();
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
Resource resource = tx.findElement(locator);
RemoveResourceCommand command = new RemoveResourceCommand(container, tx);
command.setResource(resource);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.command;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCollectionCommandTest extends AbstractRealmCommandTest {
private List<Order> orders;
@Before
public void before() {
orders = new ArrayList<>();
orders.add(ModelGenerator.createOrder("@1", "Modified Test Order", "TestType"));
orders.add(ModelGenerator.createOrder("@2", "Modified Test Order", "TestType"));
orders.add(ModelGenerator.createOrder("@3", "Modified Test Order", "TestType"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateOrderCollectionCommand command = new UpdateOrderCollectionCommand(container, tx);
command.setOrders(orders);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.command;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Order;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateOrderCommandTest extends AbstractRealmCommandTest {
private Order order;
@Before
public void before() {
order = ModelGenerator.createOrder("myCarOrder", "Modified Car Order", "ProductionOrder");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateOrderCommand command = new UpdateOrderCommand(container, tx);
command.setOrder(order);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.command;
import java.util.ArrayList;
import java.util.List;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCollectionCommandTest extends AbstractRealmCommandTest {
private List<Resource> resources;
@Before
public void before() {
resources = new ArrayList<>();
resources.add(ModelGenerator.createResource("salutations", "Modified Enumeration", "Enumeration"));
resources.add(ModelGenerator.createResource("sex", "Modified Enumeration", "Enumeration"));
resources.add(ModelGenerator.createResource("religions", "Modified Enumeration", "Enumeration"));
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateResourceCollectionCommand command = new UpdateResourceCollectionCommand(container, tx);
command.setResources(resources);
return command;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.command;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.model.ModelGenerator;
import li.strolch.model.Resource;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class UpdateResourceCommandTest extends AbstractRealmCommandTest {
private Resource resource;
@Before
public void before() {
resource = ModelGenerator.createResource("yellow", "Modified Yellow Ball", "Ball");
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
UpdateResourceCommand command = new UpdateResourceCommand(container, tx);
command.setResource(resource);
return command;
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.command.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.AbstractRealmCommandTest;
import li.strolch.command.parameter.AddParameterCommand;
import li.strolch.model.Locator;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.parameter.BooleanParameter;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AddParameterCommandTest extends AbstractRealmCommandTest {
private Locator locator;
private Parameter<?> parameter;
@Before
public void before() {
this.locator = Locator.valueOf("Resource/Ball/yellow/parameters");
this.parameter = new BooleanParameter("newParam", "New Param", false);
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
ParameterizedElement element = tx.findElement(locator);
AddParameterCommand command = new AddParameterCommand(container, tx);
command.setElement(element);
command.setParameter(parameter);
return command;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.command.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.AbstractRealmCommandTest;
import li.strolch.model.Locator;
import li.strolch.model.ParameterizedElement;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class RemoveParameterCommandTest extends AbstractRealmCommandTest {
private Locator locator;
private String parameterId;
@Before
public void before() {
this.locator = Locator.valueOf("Resource/Ball/yellow/parameters");
this.parameterId = "owner";
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
ParameterizedElement element = tx.findElement(locator);
RemoveParameterCommand command = new RemoveParameterCommand(container, tx);
command.setElement(element);
command.setParameterId(parameterId);
return command;
}
}

View File

@ -0,0 +1,52 @@
/*
* 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.command.parameter;
import li.strolch.agent.api.ComponentContainer;
import li.strolch.command.AbstractRealmCommandTest;
import li.strolch.command.parameter.SetParameterCommand;
import li.strolch.model.Locator;
import li.strolch.model.parameter.Parameter;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.service.api.Command;
import org.junit.Before;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class SetParameterCommandTest extends AbstractRealmCommandTest {
private Locator locator;
private String valueAsString;
@Before
public void before() {
this.locator = Locator.valueOf("Resource/Ball/yellow/parameters/owner");
this.valueAsString = "someOtherDude";
}
@Override
protected Command getCommandInstance(ComponentContainer container, StrolchTransaction tx) {
Parameter<?> parameter = tx.findElement(locator);
SetParameterCommand command = new SetParameterCommand(container, tx);
command.setValueAsString(valueAsString);
command.setParameter(parameter);
return command;
}
}

View File

@ -41,11 +41,11 @@ import org.junit.Test;
*/
public abstract class AbstractRealmServiceTest {
protected static final String REALM_CACHED = "svcCached";
protected static final String REALM_TRANSACTIONAL = "svcTransactional";
protected static final String REALM_TRANSIENT = "svcTransient";
protected static final String RUNTIME_PATH = "target/svcTestRuntime/"; //$NON-NLS-1$
protected static final String CONFIG_SRC = "src/test/resources/svctest"; //$NON-NLS-1$
public static final String REALM_CACHED = "svcCached";
public static final String REALM_TRANSACTIONAL = "svcTransactional";
public static final String REALM_TRANSIENT = "svcTransient";
public static final String RUNTIME_PATH = "target/svcTestRuntime/"; //$NON-NLS-1$
public static final String CONFIG_SRC = "src/test/resources/svctest"; //$NON-NLS-1$
protected static RuntimeMock runtimeMock;
@ -61,11 +61,16 @@ public abstract class AbstractRealmServiceTest {
runtimeMock.mockRuntime(rootPath, configSrc);
runtimeMock.startContainer();
importFromXml(REALM_CACHED);
importFromXml(REALM_TRANSACTIONAL);
importFromXml(REALM_CACHED, getServiceHandler());
importFromXml(REALM_TRANSACTIONAL, getServiceHandler());
}
private static void dropSchema(String dbUrl, String dbUsername, String dbPassword) throws SQLException {
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public static void dropSchema(String dbUrl, String dbUsername, String dbPassword) throws SQLException {
String dbVersion = DbSchemaVersionCheck.getExpectedDbVersion();
String sql = DbSchemaVersionCheck.getSql(dbVersion, "drop"); //$NON-NLS-1$
try (Connection connection = DriverManager.getConnection(dbUrl, dbUsername, dbPassword)) {
@ -73,13 +78,13 @@ public abstract class AbstractRealmServiceTest {
}
}
private static void importFromXml(String realm) {
public static void importFromXml(String realm, ServiceHandler serviceHandler) {
XmlImportModelService svc = new XmlImportModelService();
XmlImportModelArgument arg = new XmlImportModelArgument();
arg.realm = realm;
arg.modelFileName = "StrolchModel.xml";
ServiceResult result = getServiceHandler().doService(null, svc, arg);
ServiceResult result = serviceHandler.doService(null, svc, arg);
assertServiceResult(ServiceResultState.SUCCESS, ServiceResult.class, result);
}
@ -91,24 +96,19 @@ public abstract class AbstractRealmServiceTest {
assertServiceResult(expectedState, expectedServiceResultType, result);
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
}
@Test
public void shouldPerformServiceTransient() {
doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg());
}
public abstract <T extends ServiceArgument> T getArg();
public abstract <T extends ServiceArgument, U extends ServiceResult> Service<T, U> getSvc();
@Test
public void shouldPerformServiceTransient() {
doService(REALM_TRANSIENT, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg());
}
@Test
public void shouldPerformServiceCached() {
doService(REALM_CACHED, ServiceResultState.SUCCESS, ServiceResult.class, getSvc(), getArg());