diff --git a/ch.eitchnet.utils b/ch.eitchnet.utils index d0691e4d3..540dbeab3 160000 --- a/ch.eitchnet.utils +++ b/ch.eitchnet.utils @@ -1 +1 @@ -Subproject commit d0691e4d35220d94d29d642694749524b66fc66c +Subproject commit 540dbeab32f542b7f4e3747c191d06c66b5108a9 diff --git a/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 1dfe229e7..cfc86fe94 100644 --- a/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -21,21 +21,23 @@ import static org.junit.Assert.fail; import java.io.File; import java.text.MessageFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.eitchnet.privilege.model.Certificate; +import ch.eitchnet.utils.helper.FileHelper; +import ch.eitchnet.utils.helper.StringHelper; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchAgent; import li.strolch.agent.api.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.PrivilegeHandler; +import li.strolch.service.api.Service; +import li.strolch.service.api.ServiceArgument; import li.strolch.service.api.ServiceHandler; import li.strolch.service.api.ServiceResult; import li.strolch.service.api.ServiceResultState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import ch.eitchnet.utils.helper.FileHelper; -import ch.eitchnet.utils.helper.StringHelper; - public final class RuntimeMock { private static final Logger logger = LoggerFactory.getLogger(RuntimeMock.class); @@ -66,6 +68,14 @@ public final class RuntimeMock { return this.container.getRealm(realm); } + public Certificate loginAdmin() { + return getPrivilegeHandler().authenticate("admin", "admin".getBytes()); + } + + public boolean logout(Certificate cert) { + return getPrivilegeHandler().invalidateSession(cert); + } + public void mockRuntime(File targetPathF, File srcPathF) { this.targetPathF = targetPathF; @@ -150,14 +160,40 @@ public final class RuntimeMock { } } + public U doService(Certificate certificate, + Service service, T argument) { + U result = getServiceHandler().doService(certificate, service, argument); + assertServiceResult(ServiceResultState.SUCCESS, result); + return result; + } + public static void assertServiceResult(ServiceResultState expectedState, Class expectedResultType, ServiceResult result) { assertEquals("Expected service result of type " + expectedResultType + " but was " + result.getClass(), expectedResultType, result.getClass()); if (!expectedState.equals(result.getState())) { + String errorMsg; + if (result.getThrowable() == null) + errorMsg = result.getMessage(); + else + errorMsg = StringHelper.formatException(result.getThrowable()); + fail("Expected service result state " + expectedState + " but was " + result.getState() + ": Reason: " - + StringHelper.formatException(result.getThrowable())); + + errorMsg); + } + } + + public static void assertServiceResult(ServiceResultState expectedState, ServiceResult result) { + if (!expectedState.equals(result.getState())) { + String errorMsg; + if (result.getThrowable() == null) + errorMsg = result.getMessage(); + else + errorMsg = StringHelper.formatException(result.getThrowable()); + + fail("Expected service result state " + expectedState + " but was " + result.getState() + ": Reason: " + + errorMsg); } } }