Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RPCResolvedExceptionTest and port exception to kotlin. #78

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
package org.openbase.jul.communication.exception

import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.openbase.jul.exception.CouldNotPerformException
import org.openbase.jul.exception.ExceptionProcessor
import org.openbase.jul.exception.NotAvailableException
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.junit.jupiter.api.TestInstance
import org.openbase.type.communication.mqtt.ResponseType

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class RPCResolvedExceptionTest {
internal class RPCResolvedExceptionTest {

companion object {
const val missingEntity = "mize"
const val rootMessage = "root cause"
const val secondLevelMessage = "second level cause"
}

@Test
fun testExceptionResolution() {

val testException = CouldNotPerformException(
message = rootMessage,
cause = CouldNotPerformException(
message = secondLevelMessage,
cause = NotAvailableException(missingEntity)
)
)

RPCException(message = testException.stackTraceToString()).let { rpcException ->

// resolve exception via explicit method call
RPCResolvedException
.resolveRPCException(rpcException)
.let { result ->
ExceptionProcessor.getInitialCause(result).let { initialCause ->
Assertions.assertEquals(initialCause.message, NotAvailableException(missingEntity).message)
}
}

// resolve exception via constructor call
RPCResolvedException(rpcException)
.let { result ->
ExceptionProcessor.getInitialCause(result).let { initialCause ->
Assertions.assertEquals(initialCause.message, NotAvailableException(missingEntity).message)
}
}
}
}

@Test
fun testExceptionResolving() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.openbase.jul.communication.config.CommunicatorConfig
import org.openbase.jul.communication.exception.RPCException
import org.openbase.jul.communication.exception.RPCResolvedException
import org.openbase.jul.exception.CouldNotPerformException
import org.openbase.jul.exception.ExceptionProcessor
import org.openbase.jul.exception.NotAvailableException
import org.openbase.jul.extension.type.processing.ScopeProcessor
import org.openbase.jul.schedule.GlobalCachedExecutorService
Expand Down Expand Up @@ -165,12 +166,6 @@ internal class RPCServerImplTest {
callback.accept(clientRequest)
}

@Test
@Timeout(value = 30)
fun `test bad request id`() {
//TODO: verify that id is a valid uuid
}

/**
* Verify that no matter the request, the server
* always responds with an acknowledgement first.
Expand Down Expand Up @@ -209,7 +204,7 @@ internal class RPCServerImplTest {
actualResponse.hasResult() shouldBe false

val error = RPCResolvedException.resolveRPCException(RPCException(actualResponse.error))
error shouldBe NotAvailableException("Method $methodName")
ExceptionProcessor.getInitialCause(error) shouldBe NotAvailableException("Method $methodName")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.openbase.jul.exception
/*
* #%L
* JUL Exception
* %%
* Copyright (C) 2015 - 2022 openbase.org
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/ /**
* @author [Divine Threepwood](mailto:[email protected])
*/
open class CouldNotPerformException : Exception {
/**
* {@inheritDoc}
*
* @param message {@inheritDoc}
*/
constructor(message: String?) : super(message)

/**
* {@inheritDoc}
*
* @param message {@inheritDoc}
* @param cause {@inheritDoc}
*/
constructor(message: String?, cause: Throwable?) : super(message, cause)

/**
* {@inheritDoc}
*
* @param cause {@inheritDoc}
*/
constructor(cause: Throwable?) : super(cause)

/**
* {@inheritDoc}
*
* @param message {@inheritDoc}
* @param cause {@inheritDoc}
* @param enableSuppression {@inheritDoc}
* @param writableStackTrace {@inheritDoc}
*/
constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(
message,
cause,
enableSuppression,
writableStackTrace
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openbase.jul.exception;
package org.openbase.jul.exception

/*
* #%L
Expand All @@ -20,41 +20,32 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/ /**
*
* @author [Divine Threepwood](mailto:[email protected])
*/


/**
* @author <a href="mailto:[email protected]">Divine Threepwood</a>
*/
public class CouldNotPerformException extends Exception {

class CouldNotProcessException : RuntimeException {
/**
* {@inheritDoc}
*
* @param message {@inheritDoc}
*/
public CouldNotPerformException(String message) {
super(message);
}
constructor(message: String?) : super(message)

/**
* {@inheritDoc}
*
* @param message {@inheritDoc}
* @param cause {@inheritDoc}
*/
public CouldNotPerformException(String message, Throwable cause) {
super(message, cause);
}
constructor(message: String?, cause: Throwable?) : super(message, cause)

/**
* {@inheritDoc}
*
* @param cause {@inheritDoc}
*/
public CouldNotPerformException(Throwable cause) {
super(cause);
}
constructor(cause: Throwable?) : super(cause)

/**
* {@inheritDoc}
Expand All @@ -64,7 +55,10 @@ public CouldNotPerformException(Throwable cause) {
* @param enableSuppression {@inheritDoc}
* @param writableStackTrace {@inheritDoc}
*/
public CouldNotPerformException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(
message,
cause,
enableSuppression,
writableStackTrace
)
}