diff --git a/libs/rest/rest-common/src/main/java/net/corda/rest/durablestream/api/package-info.java b/libs/rest/rest-common/src/main/java/net/corda/rest/durablestream/api/package-info.java deleted file mode 100644 index 2966997eebf..00000000000 --- a/libs/rest/rest-common/src/main/java/net/corda/rest/durablestream/api/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@Export -package net.corda.rest.durablestream.api; - -import org.osgi.annotation.bundle.Export; \ No newline at end of file diff --git a/libs/rest/rest-common/src/main/java/net/corda/rest/durablestream/package-info.java b/libs/rest/rest-common/src/main/java/net/corda/rest/durablestream/package-info.java deleted file mode 100644 index c72a53a0932..00000000000 --- a/libs/rest/rest-common/src/main/java/net/corda/rest/durablestream/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@Export -package net.corda.rest.durablestream; - -import org.osgi.annotation.bundle.Export; \ No newline at end of file diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableCursorTransferObject.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableCursorTransferObject.kt deleted file mode 100644 index 5e6163b75a6..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableCursorTransferObject.kt +++ /dev/null @@ -1,37 +0,0 @@ -package net.corda.rest.durablestream - -import net.corda.rest.durablestream.api.Cursor -import net.corda.rest.durablestream.api.FiniteDurableCursor -import net.corda.rest.durablestream.api.FiniteDurableCursorBuilder -import net.corda.rest.durablestream.api.PositionManager -import java.util.function.Supplier - -/** - * Implementation of [FiniteDurableCursorBuilder] which is created on the server side to be marshalled back to the client. - * Methods of [FiniteDurableCursorBuilder] are not meant to be used, it is just a data container that wraps [Cursor.PollResult]. - */ -class DurableCursorTransferObject -(private val pollResult: Cursor.PollResult) : FiniteDurableCursorBuilder, Supplier> { - - companion object { - data class PollResultImpl( - override val positionedValues: List>, - override val remainingElementsCountEstimate: Long?, - override val isLastResult: Boolean - ) : Cursor.PollResult - - data class PositionedValueImpl(override val value: T, override val position: Long) : Cursor.PollResult.PositionedValue - } - - override fun get(): Cursor.PollResult = pollResult - - override var positionManager: PositionManager - get() = throw UnsupportedOperationException("getting position manager not meant to be called") - - @Suppress("unused_parameter") - set(value) = throw UnsupportedOperationException("setting position manager not meant to be called") - - override fun build(): FiniteDurableCursor { - throw UnsupportedOperationException("Method 'build()' is not meant to be called") - } -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableStreamContext.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableStreamContext.kt deleted file mode 100644 index 823cab598e5..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableStreamContext.kt +++ /dev/null @@ -1,3 +0,0 @@ -package net.corda.rest.durablestream - -data class DurableStreamContext(val currentPosition: Long, val maxCount: Int) diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableStreamHelper.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableStreamHelper.kt deleted file mode 100644 index 456d47dff4f..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/DurableStreamHelper.kt +++ /dev/null @@ -1,72 +0,0 @@ -package net.corda.rest.durablestream - -import net.corda.rest.durablestream.api.Cursor -import net.corda.rest.durablestream.api.FiniteDurableCursorBuilder -import net.corda.rest.security.restContext - -/** - * A set of helper method to make working with durable streams constructs easier - */ -object DurableStreamHelper { - - data class DurableStreamContextExecutionOutcome( - val positionedValues: List>, - val remainingElementsCountEstimate: Long?, - val isLastResult: Boolean - ) - - /** - * DSL to unify retrieval of [DurableStreamContext] - * - * @param block function that performs some processing with [DurableStreamContext] - * and returns a result in the form of a [DurableStreamContextExecutionOutcome] - */ - @JvmStatic - fun withDurableStreamContext( - block: DurableStreamContext.() -> DurableStreamContextExecutionOutcome - ): FiniteDurableCursorBuilder { - val durableStreamContext = requireNotNull(restContext()?.invocation?.durableStreamContext) { - "Durable stream context should always be set for durable streams invocation." - } - val (positionedValues, remainingElementsCountEstimate, isLastResult) = block(durableStreamContext) - return DurableCursorTransferObject(pollResult(positionedValues, remainingElementsCountEstimate, isLastResult)) - } - - @JvmStatic - fun positionedValue(value: T, position: Long): Cursor.PollResult.PositionedValue { - return DurableCursorTransferObject.Companion.PositionedValueImpl(value, position) - } - - @JvmStatic - fun pollResult( - positionedValues: List>, - remainingElementsCountEstimate: Long?, - isLastResult: Boolean - ): Cursor.PollResult { - return DurableCursorTransferObject.Companion.PollResultImpl( - positionedValues, - remainingElementsCountEstimate, - isLastResult - ) - } - - @JvmStatic - fun outcome( - positionedValues: List>, - remainingElementsCountEstimate: Long?, - isLastResult: Boolean - ): DurableStreamContextExecutionOutcome = - DurableStreamContextExecutionOutcome(positionedValues, remainingElementsCountEstimate, isLastResult) - - @JvmStatic - fun outcome( - remainingElementsCountEstimate: Long?, - isLastResult: Boolean, - positionedValues: List> - ): DurableStreamContextExecutionOutcome = - DurableStreamContextExecutionOutcome( - positionedValues.map { positionedValue(it.second, it.first) }, - remainingElementsCountEstimate, - isLastResult - ) -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/Cursor.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/Cursor.kt deleted file mode 100644 index e55e0986e75..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/Cursor.kt +++ /dev/null @@ -1,137 +0,0 @@ -package net.corda.rest.durablestream.api - -import net.corda.rest.durablestream.api.Cursor.PollResult -import net.corda.v5.base.annotations.CordaSerializable -import net.corda.v5.base.annotations.DoNotImplement -import net.corda.v5.base.annotations.Suspendable -import java.time.Duration -import java.util.concurrent.CompletableFuture - -/** - * A [Cursor] is a stream that emits elements of type [T], providing [poll] as the mechanism to retrieve elements. - * - * Expected usage of this interface consists of the following steps: - * - * - Call [poll] to retrieve a batch of elements stored in a [PollResult]. - * - Process these elements using either [PollResult.positionedValues] or [PollResult.values]. - * - Depending on whether there are more batches to retrieve, repeat the 2 previous steps. [PollResult.isLastResult] indicates whether the - * returned [PollResult] contains the last batch of elements. - * - * Example usage: - * - * - Kotlin: - * - * ```kotlin - * var result: PollResult = cursor.poll(50, 5.minutes) - * while (!result.isLastResult) { - * for (positionedValue: PositionedValue in result.positionedValues) { - * log.info("Processing value: ${positionedValue.value} at position: ${positionedValue.position}") - * } - * result = cursor.poll(50, 5.minutes) - * } - * ``` - * - * - Java: - * - * ```java - * PollResult result = cursor.poll(50, Duration.of(5, ChronoUnit.MINUTES)); - * while (!result.isLastResult()) { - * for (PositionedValue positionedValue : result.getPositionedValues()) { - * log.info("Processing value: " + positionedValue.getValue() + " at position: " + positionedValue.getPosition()); - * } - * result = cursor.poll(50, Duration.of(5, ChronoUnit.MINUTES)); - * } - * ``` - * - * @see DurableCursor - */ -@DoNotImplement -interface Cursor { - - /** - * Asynchronously tries to retrieve a batch of elements if they are available. - * - * @param maxCount The maximum number of elements to be returned. - * @param awaitForResultTimeout The desired maximum duration to wait for result to become available. The [CompletableFuture] will be - * completed when [maxCount] number of elements is available or [awaitForResultTimeout] has elapsed, whichever happens first. - * - * @return A [CompletableFuture] over [Cursor.PollResult]. - */ - fun asyncPoll(maxCount: Int, awaitForResultTimeout: Duration): CompletableFuture> { - return CompletableFuture.supplyAsync { poll(maxCount, awaitForResultTimeout) } - } - - /** - * Retrieve a batch of elements if they are available. - * - * @param maxCount The maximum number of elements to be returned. - * @param awaitForResultTimeout The desired maximum duration to wait for result to become available. - * - * @return A [PollResult] containing the batch of requested elements. - * - * @throws IllegalArgumentException If the [awaitForResultTimeout] is negative. - */ - @Suspendable - fun poll(maxCount: Int, awaitForResultTimeout: Duration): PollResult - - /** - * A data container which represents a batch of elements along with their positions. - */ - @CordaSerializable - @DoNotImplement - interface PollResult { - - /** - * Values with positions - */ - val positionedValues: List> - - /** - * Convenience property to retrieve just the raw elements. - */ - val values: List get() = positionedValues.map { it.value } - - /** - * First position in the batch. - * - * @throws NoSuchElementException If there are no values. - */ - val firstPosition: Long get() = positionedValues.first().position - - /** - * Last position in the batch. - * - * @throws NoSuchElementException If there are no values. - */ - val lastPosition: Long get() = positionedValues.last().position - - /** - * A non-negative optional estimate for the remaining elements count. - */ - val remainingElementsCountEstimate: Long? - - /** - * Whether this result has no elements. - * - * @returns `true` if there a no elements, `false` otherwise. - */ - val isEmpty: Boolean get() = positionedValues.isEmpty() - - /** - * Whether this result represents the last batch of elements. - * - * @returns `true` if there are no more elements to [poll], `false` otherwise. - */ - val isLastResult: Boolean - - /** - * Position with value data container. - */ - @CordaSerializable - @DoNotImplement - interface PositionedValue { - val value: T - val position: Long - } - } -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/CursorException.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/CursorException.kt deleted file mode 100644 index 42945701bbf..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/CursorException.kt +++ /dev/null @@ -1,5 +0,0 @@ -package net.corda.rest.durablestream.api - -import net.corda.v5.base.exceptions.CordaRuntimeException - -class CursorException(message: String, cause: Exception?) : CordaRuntimeException(message, cause) diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/DurableCursor.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/DurableCursor.kt deleted file mode 100644 index d5d705fdc1f..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/DurableCursor.kt +++ /dev/null @@ -1,167 +0,0 @@ -package net.corda.rest.durablestream.api - -import net.corda.rest.durablestream.api.Cursor.PollResult -import net.corda.v5.base.annotations.DoNotImplement -import java.util.concurrent.CompletableFuture - -/** - * A [DurableCursor] is a stream that emits elements of type [T] and provides management functions to maintain durability across application - * restarts. - * - * A [DurableCursor] can represent both a finite and infinite stream of elements. APIs returning a cursor will determine which type the - * cursor belongs to. - * - * Finite streams should consist of the following steps: - * - * - Call [poll] to retrieve a batch of elements stored in a [PollResult]. - * - Process these elements using either [PollResult.positionedValues] or [PollResult.values]. - * - Call [commit] to update the position that the cursor has successfully processed elements up to. - * - Depending on whether there are more batches to retrieve, repeat the 3 previous steps. [PollResult.isLastResult] indicates whether the - * returned [PollResult] contains the last batch of elements. - * - * Example usage of an finite stream: - * - * - Kotlin: - * - * ```kotlin - * var result: PollResult = cursor.poll(50, 5.minutes) - * while (!result.isLastResult) { - * for (positionedValue: PositionedValue in result.positionedValues) { - * log.info("Processing value: ${positionedValue.value} at position: ${positionedValue.position}") - * } - * cursor.commit(result) - * result = cursor.poll(50, 5.minutes) - * } - * ``` - * - * - Java: - * - * ```java - * PollResult result = cursor.poll(50, Duration.of(5, ChronoUnit.MINUTES)); - * while (!result.isLastResult()) { - * for (PositionedValue positionedValue : result.getPositionedValues()) { - * log.info("Processing value: " + positionedValue.getValue() + " at position: " + positionedValue.getPosition()); - * } - * cursor.commit(result) - * result = cursor.poll(50, Duration.of(5, ChronoUnit.MINUTES)); - * } - * ``` - * - * Infinite streams should consist of the following steps: - * - * - Call [poll] to retrieve a batch of elements stored in a [PollResult]. - * - Process these elements using either [PollResult.positionedValues] or [PollResult.values]. - * - Call [commit] to update the position that the cursor has successfully processed elements up to. - * - Repeat the 3 previous steps. There is no conditional check based on the [PollResult] here because the stream is expected to continue - * infinitely. - * - * Example usage of an infinite stream: - * - * - Kotlin: - * - * ```kotlin - * while (!Thread.currentThread().isInterrupted) { - * val result = cursor.poll(50, 5.minutes); - * for (positionedValue: PositionedValue in result.positionedValues) { - * log.info("Processing value: ${positionedValue.value} at position: ${positionedValue.position}") - * } - * cursor.commit(result.lastPosition) - * } - * ``` - * - * - Java: - * - * ```java - * while (!Thread.currentThread().isInterrupted()) { - * PollResult result = cursor.poll(50, Duration.of(5, ChronoUnit.MINUTES)); - * for (PositionedValue positionedValue : result.getPositionedValues()) { - * log.info("Processing value: " + positionedValue.getValue() + " at position: " + positionedValue.getPosition()); - * } - * cursor.commit(result); - * } - * ``` - * - * @see Cursor - */ -@DoNotImplement -interface DurableCursor : Cursor { - - /** - * Gets the current position of the cursor - * - * @throws CursorException If the cursor fails to return its current position. - */ - @Suppress("TooGenericExceptionCaught") - val currentPosition: Long - get() { - return try { - positionManager.get() - } catch (e: Exception) { - throw CursorException("Failed to retrieve the cursor position", e) - } - } - - /** - * Adjusts the cursor to a specific position either back or forward. [position] may not be less than `-1`. - * - * @throws CursorException If the cursor fails to adjust its position. - */ - @Suppress("TooGenericExceptionCaught") - fun seek(position: Long) = try { - positionManager.accept(position) - } catch (e: Exception) { - throw CursorException("Failed to adjust the cursor position to $position", e) - } - - /** - * Resets the cursor's position to the very beginning of the stream. - * - * @throws CursorException If the cursor fails to adjust its position. - */ - fun reset() = seek(PositionManager.MIN_POSITION) - - /** - * Marks all the elements up to a [position] (inclusive) as consumed. Such that future calls to [poll] will return elements further - * down the stream. - * - * @return A [CompletableFuture] over [Unit] since operation may take some time. - */ - fun asyncCommit(position: Long): CompletableFuture { - return CompletableFuture.supplyAsync { commit(position) } - } - - /** - * Marks all the elements up to a [position] (inclusive) as consumed. Such that future calls to [poll] will return elements further - * down the stream. - * - * @param position The position to commit. - * - * @throws CursorException If the new position fails to commit. - */ - @Suppress("TooGenericExceptionCaught") - fun commit(position: Long) { - try { - positionManager.accept(position) - } catch (e: Exception) { - throw CursorException("Failed to commit the cursor position as $position", e) - } - } - - /** - * Convenience method that commits [Cursor.PollResult.lastPosition] for non-empty results. - * - * @param result The [Cursor.PollResult] who's [Cursor.PollResult.lastPosition] will be committed. - * - * @throws CursorException If the new position fails to commit. - */ - fun commit(result: PollResult) { - if (!result.isEmpty) { - commit(result.lastPosition) - } - } - - /** - * Gets the [PositionManager] of the cursor. - */ - val positionManager: PositionManager -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/DurableCursorBuilder.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/DurableCursorBuilder.kt deleted file mode 100644 index c7867b25b7f..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/DurableCursorBuilder.kt +++ /dev/null @@ -1,18 +0,0 @@ -package net.corda.rest.durablestream.api - -import net.corda.v5.base.annotations.DoNotImplement - -/** - * Responsible for building [DurableCursor], allowing to assign values to mutable properties before method - * [build] is called. - */ -@DoNotImplement -interface DurableCursorBuilder { - - /** - * Allows getting and setting [PositionManager] which will be used for this [DurableCursor]. - */ - var positionManager: PositionManager - - fun build(): DurableCursor -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/FiniteDurableCursor.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/FiniteDurableCursor.kt deleted file mode 100644 index 66e3b87014b..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/FiniteDurableCursor.kt +++ /dev/null @@ -1,17 +0,0 @@ -package net.corda.rest.durablestream.api - -import net.corda.v5.base.annotations.DoNotImplement -import java.time.Duration - -/** - * Extension of [DurableCursor] which hints that returned stream will be finite, i.e. it will have an end. - * Also, finite cursors indicate that a full result set is available on the server side and the client can consume - * the whole result at their convenience. - */ -@DoNotImplement -interface FiniteDurableCursor : DurableCursor { - /** - * Convenience method over [DurableCursor.poll] which instructs not to spend any time waiting for result on the server side. - */ - fun take(maxCount: Int): Cursor.PollResult = poll(maxCount, Duration.ZERO) -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/FiniteDurableCursorBuilder.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/FiniteDurableCursorBuilder.kt deleted file mode 100644 index 3051f40be78..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/FiniteDurableCursorBuilder.kt +++ /dev/null @@ -1,13 +0,0 @@ -package net.corda.rest.durablestream.api - -import net.corda.v5.base.annotations.DoNotImplement - -/** - * Responsible for building [FiniteDurableCursor], allowing to assign values to mutable properties before method - * [build] is called. - */ -@DoNotImplement -interface FiniteDurableCursorBuilder : DurableCursorBuilder { - - override fun build(): FiniteDurableCursor -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/Method.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/Method.kt deleted file mode 100644 index 7a2450c5396..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/Method.kt +++ /dev/null @@ -1,10 +0,0 @@ -@file:JvmName("MethodUtils") - -package net.corda.rest.durablestream.api - -import java.lang.reflect.Method - -fun Method.returnsDurableCursorBuilder() = DurableCursorBuilder::class.java.isAssignableFrom(returnType) - -fun Method.isFiniteDurableStreamsMethod() = - FiniteDurableCursorBuilder::class.java.isAssignableFrom(returnType) diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/PositionManager.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/PositionManager.kt deleted file mode 100644 index 896796a4702..00000000000 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/durablestream/api/PositionManager.kt +++ /dev/null @@ -1,28 +0,0 @@ -package net.corda.rest.durablestream.api - -import java.util.function.Consumer -import java.util.function.Supplier - -/** - * Responsible for storage and retrieval of the current position used by [DurableCursor] - * By current position we mean position that has been already consumed and entities associated with this position - * processed. - * - * API users can create their own implementations of this interface which can be assigned to [DurableCursor]. - * - * In relation to multithreaded aspect of this interface: - * Since it is really the caller of the [DurableCursor.poll] and [DurableCursor.commit] who controls the thread which - * will be used for [PositionManager] invocations, there are no special provisions made to ensure thread safety of the - * invocation to this interface. - * The key principle here is that: Whichever position committed by calling [PositionManager.accept] should be available - * when [PositionManager.get] is called. - */ -interface PositionManager : Supplier, Consumer { - companion object { - /** - * Constant indicating position before the very first element of the stream. - * I.e. this is the minimal possible value of the stream position. - */ - const val MIN_POSITION = -1L - } -} diff --git a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/security/InvocationContext.kt b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/security/InvocationContext.kt index 8d456735760..8047fad1ab8 100644 --- a/libs/rest/rest-common/src/main/kotlin/net/corda/rest/security/InvocationContext.kt +++ b/libs/rest/rest-common/src/main/kotlin/net/corda/rest/security/InvocationContext.kt @@ -1,6 +1,5 @@ package net.corda.rest.security -import net.corda.rest.durablestream.DurableStreamContext import net.corda.v5.base.types.MemberX500Name import java.security.Principal @@ -13,7 +12,6 @@ import java.security.Principal data class InvocationContext( val actor: Actor, val arguments: List = emptyList(), - val durableStreamContext: DurableStreamContext? = null, val clientId: String? = null ) { /** diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/CursorExceptionJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/CursorExceptionJavaApiTest.java deleted file mode 100644 index be35133c0a1..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/CursorExceptionJavaApiTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.corda.rest.durablestream.api; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -public class CursorExceptionJavaApiTest { - - @Test - public void initialize() { - final Exception exception = new Exception(); - final CursorException cursorException = new CursorException("msg", null); - final CursorException cursorException1 = new CursorException("msg", exception); - - Assertions.assertThat(cursorException).isNotNull(); - Assertions.assertThat(cursorException1).isNotNull(); - } -} diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/CursorJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/CursorJavaApiTest.java deleted file mode 100644 index ccc00b754e0..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/CursorJavaApiTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.corda.rest.durablestream.api; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import java.time.Duration; -import java.util.concurrent.CompletableFuture; - -public class CursorJavaApiTest { - - @SuppressWarnings("unchecked") - private final Cursor cursor = Mockito.mock(Cursor.class); - private final Duration duration = Duration.ofHours(5); - private final Integer integer = 5; - - @Test - public void asyncPoll() { - @SuppressWarnings("unchecked") - final CompletableFuture> future = Mockito.mock(CompletableFuture.class); - Mockito.when(cursor.asyncPoll(integer, duration)).thenReturn(future); - - final CompletableFuture> futureTest = cursor.asyncPoll(integer, duration); - - Assertions.assertThat(futureTest).isNotNull(); - Assertions.assertThat(futureTest).isEqualTo(future); - } - - @Test - public void poll() { - @SuppressWarnings("unchecked") - final Cursor.PollResult pollResult = Mockito.mock(Cursor.PollResult.class); - Mockito.when(cursor.poll(integer, duration)).thenReturn(pollResult); - - final Cursor.PollResult pollResultTest = cursor.poll(integer, duration); - - Assertions.assertThat(pollResultTest).isNotNull(); - Assertions.assertThat(pollResultTest).isEqualTo(pollResult); - } -} diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/DurableCursorBuilderJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/DurableCursorBuilderJavaApiTest.java deleted file mode 100644 index 9c30800a8f4..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/DurableCursorBuilderJavaApiTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.corda.rest.durablestream.api; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -public class DurableCursorBuilderJavaApiTest { - - @SuppressWarnings("unchecked") - private final DurableCursorBuilder durableCursorBuilder = Mockito.mock(DurableCursorBuilder.class); - - @Test - public void positionManager() { - final PositionManager positionManager = Mockito.mock(PositionManager.class); - Mockito.when(durableCursorBuilder.getPositionManager()).thenReturn(positionManager); - - final PositionManager positionManagerTest = durableCursorBuilder.getPositionManager(); - - Assertions.assertThat(positionManagerTest).isNotNull(); - Assertions.assertThat(positionManagerTest).isEqualTo(positionManager); - } - - @Test - public void build() { - @SuppressWarnings("unchecked") - final DurableCursor durableCursor = Mockito.mock(DurableCursor.class); - Mockito.when(durableCursorBuilder.build()).thenReturn(durableCursor); - - final DurableCursor durableCursorTest = durableCursorBuilder.build(); - - Assertions.assertThat(durableCursorTest).isNotNull(); - Assertions.assertThat(durableCursorTest).isEqualTo(durableCursor); - } -} diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/DurableCursorJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/DurableCursorJavaApiTest.java deleted file mode 100644 index f6300cb9366..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/DurableCursorJavaApiTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.corda.rest.durablestream.api; - -import kotlin.Unit; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import java.util.concurrent.CompletableFuture; - -public class DurableCursorJavaApiTest { - - @SuppressWarnings("unchecked") - private final DurableCursor durableCursor = Mockito.mock(DurableCursor.class); - - @Test - public void currentPosition() { - Mockito.when(durableCursor.getCurrentPosition()).thenReturn(5L); - - final Long aLong = durableCursor.getCurrentPosition(); - - Assertions.assertThat(aLong).isNotNull(); - Assertions.assertThat(aLong).isEqualTo(5L); - } - - @Test - public void seek() { - durableCursor.seek(5L); - - Mockito.verify(durableCursor, Mockito.times(1)).seek(5L); - } - - @Test - public void reset() { - durableCursor.reset(); - - Mockito.verify(durableCursor, Mockito.times(1)).reset(); - } - - @Test - public void asyncCommit() { - @SuppressWarnings("unchecked") - CompletableFuture future = Mockito.mock(CompletableFuture.class); - Mockito.when(durableCursor.asyncCommit(5L)).thenReturn(future); - - CompletableFuture futureTest = durableCursor.asyncCommit(5L); - - Assertions.assertThat(futureTest).isNotNull(); - Assertions.assertThat(futureTest).isEqualTo(future); - } - - @Test - public void commit_withLong() { - durableCursor.commit(5L); - - Mockito.verify(durableCursor, Mockito.times(1)).commit(5L); - } - - @Test - public void commit_withPollResult() { - @SuppressWarnings("unchecked") - final Cursor.PollResult pollResult = Mockito.mock(Cursor.PollResult.class); - durableCursor.commit(pollResult); - - Mockito.verify(durableCursor, Mockito.times(1)).commit(pollResult); - } - - @Test - public void positionManager() { - final PositionManager positionManager = Mockito.mock(PositionManager.class); - Mockito.when(durableCursor.getPositionManager()).thenReturn(positionManager); - - final PositionManager positionManagerTest = durableCursor.getPositionManager(); - - Assertions.assertThat(positionManagerTest).isNotNull(); - Assertions.assertThat(positionManagerTest).isEqualTo(positionManager); - } -} diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/FiniteDurableCursorJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/FiniteDurableCursorJavaApiTest.java deleted file mode 100644 index 89b1d566126..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/FiniteDurableCursorJavaApiTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.corda.rest.durablestream.api; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -public class FiniteDurableCursorJavaApiTest { - - @Test - @SuppressWarnings("unchecked") - public void take() { - final FiniteDurableCursor finiteDurableCursor = Mockito.mock(FiniteDurableCursor.class); - final Cursor.PollResult pollResult = Mockito.mock(Cursor.PollResult.class); - Mockito.when(finiteDurableCursor.take(5)).thenReturn(pollResult); - - final Cursor.PollResult pollResultTest = finiteDurableCursor.take(5); - - Assertions.assertThat(pollResultTest).isNotNull(); - Assertions.assertThat(pollResultTest).isEqualTo(pollResult); - } -} diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/PollResultJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/PollResultJavaApiTest.java deleted file mode 100644 index 235e3c44942..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/PollResultJavaApiTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package net.corda.rest.durablestream.api; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import java.util.List; - - -public class PollResultJavaApiTest { - - @SuppressWarnings("unchecked") - private final Cursor.PollResult pollResult = Mockito.mock(Cursor.PollResult.class); - - @Test - public void positionedValues() { - @SuppressWarnings("unchecked") - final List> positionedValues = Mockito.mock(List.class); - Mockito.when(pollResult.getPositionedValues()).thenReturn(positionedValues); - - final List> positionedValuesTest = pollResult.getPositionedValues(); - - Assertions.assertThat(positionedValuesTest).isNotNull(); - Assertions.assertThat(positionedValuesTest).isEqualTo(positionedValues); - } - - @Test - public void values() { - final List integers = List.of(5, 6); - Mockito.when(pollResult.getValues()).thenReturn(integers); - - final List integersTest = pollResult.getValues(); - - Assertions.assertThat(integersTest).isNotNull(); - Assertions.assertThat(integersTest).isEqualTo(integers); - } - - @Test - public void firstPosition() { - Mockito.when(pollResult.getFirstPosition()).thenReturn(5L); - - final Long aLong = pollResult.getFirstPosition(); - - Assertions.assertThat(aLong).isNotNull(); - Assertions.assertThat(aLong).isEqualTo(5L); - } - - @Test - public void lastPosition() { - Mockito.when(pollResult.getLastPosition()).thenReturn(5L); - - final Long aLong = pollResult.getLastPosition(); - - Assertions.assertThat(aLong).isNotNull(); - Assertions.assertThat(aLong).isEqualTo(5L); - } - - @Test - public void remainingElementsCountEstimate() { - Mockito.when(pollResult.getRemainingElementsCountEstimate()).thenReturn(5L); - - final Long aLong = pollResult.getRemainingElementsCountEstimate(); - - Assertions.assertThat(aLong).isNotNull(); - Assertions.assertThat(aLong).isEqualTo(5L); - } - - @Test - public void remainingElementsCountEstimate_without_shouldReturnNull() { - Mockito.when(pollResult.getRemainingElementsCountEstimate()).thenReturn(null); - - final Long aLong = pollResult.getRemainingElementsCountEstimate(); - - Assertions.assertThat(aLong).isNull(); - } - - @Test - public void isEmpty() { - Mockito.when(pollResult.isEmpty()).thenReturn(false); - - final Boolean isEmpty = pollResult.isEmpty(); - - Assertions.assertThat(isEmpty).isNotNull(); - Assertions.assertThat(isEmpty).isFalse(); - } - - @Test - public void isLastResult() { - Mockito.when(pollResult.isLastResult()).thenReturn(false); - - final Boolean isLastResult = pollResult.isLastResult(); - - Assertions.assertThat(isLastResult).isNotNull(); - Assertions.assertThat(isLastResult).isFalse(); - } -} diff --git a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/PositionedValueJavaApiTest.java b/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/PositionedValueJavaApiTest.java deleted file mode 100644 index bb9b4342df5..00000000000 --- a/libs/rest/rest-common/src/test/java/net/corda/rest/durablestream/api/PositionedValueJavaApiTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.corda.rest.durablestream.api; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -public class PositionedValueJavaApiTest { - @SuppressWarnings("unchecked") - private final Cursor.PollResult.PositionedValue positionedValue = Mockito.mock(Cursor.PollResult.PositionedValue.class); - - @Test - public void value() { - Mockito.when(positionedValue.getValue()).thenReturn(5); - - final Integer integer = positionedValue.getValue(); - - Assertions.assertThat(integer).isNotNull(); - Assertions.assertThat(integer).isEqualTo(5); - } - - @Test - public void position() { - Mockito.when(positionedValue.getPosition()).thenReturn(5L); - - final Long aLong = positionedValue.getPosition(); - - Assertions.assertThat(aLong).isNotNull(); - Assertions.assertThat(aLong).isEqualTo(5L); - } -} diff --git a/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerDurableStreamsRequestsTest.kt b/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerDurableStreamsRequestsTest.kt deleted file mode 100644 index 73b30fb2599..00000000000 --- a/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerDurableStreamsRequestsTest.kt +++ /dev/null @@ -1,146 +0,0 @@ -package net.corda.rest.server.impl - -import net.corda.rest.server.config.models.RestServerSettings -import net.corda.rest.server.impl.utils.compact -import net.corda.rest.test.CalendarRestResourceImpl -import net.corda.rest.test.CustomSerializationAPIImpl -import net.corda.rest.test.NumberSequencesRestResourceImpl -import net.corda.rest.test.TestHealthCheckAPIImpl -import net.corda.rest.test.utils.FakeSecurityManager -import net.corda.rest.test.utils.TestHttpClientUnirestImpl -import net.corda.rest.test.utils.WebRequest -import net.corda.rest.test.utils.multipartDir -import net.corda.utilities.NetworkHostAndPort -import org.apache.http.HttpStatus -import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test -import kotlin.test.assertEquals - -class RestServerDurableStreamsRequestsTest : RestServerTestBase() { - - companion object { - @BeforeAll - @JvmStatic - fun setUpBeforeClass() { - val restServerSettings = RestServerSettings( - NetworkHostAndPort("localhost", 0), - context, - null, - null, - RestServerSettings.MAX_CONTENT_LENGTH_DEFAULT_VALUE, - 20000L - ) - server = RestServerImpl( - listOf( - NumberSequencesRestResourceImpl(), - CalendarRestResourceImpl(), - TestHealthCheckAPIImpl(), - CustomSerializationAPIImpl() - ), - { FakeSecurityManager() }, - restServerSettings, - multipartDir, - true - ).apply { start() } - client = TestHttpClientUnirestImpl( - "http://${restServerSettings.address.host}:${server.port}/" + - "${restServerSettings.context.basePath}/${apiVersion.versionPath}/" - ) - } - - @AfterAll - @JvmStatic - fun cleanUpAfterClass() { - if (isServerInitialized()) { - server.close() - } - } - } - - @Test - fun `POST to numberseq_retrieve should return correct values`() { - val requestBody = """ { - "context": {"currentPosition": 1, "maxCount": 1}, - "type": "ODD" - }""" - - val responseBody = """{ - |"positionedValues":[{"value":5,"position":2}], - |"remainingElementsCountEstimate":9223372036854775807 - |}""".compact() - - val response = client.call( - net.corda.rest.tools.HttpVerb.POST, - WebRequest("numberseq/retrieve", requestBody), - userName, - password - ) - - assertEquals(HttpStatus.SC_OK, response.responseStatus, response.toString()) - assertEquals(responseBody, response.body) - } - - @Test - fun `POST to numberseq_retrieve with updated position should return correct values`() { - val requestBodyNewPosition = """ { - "context": {"currentPosition": 2, "maxCount": 2}, - "type": "ODD" - }""" - - val responseBodyNewPosition = """{ - |"positionedValues":[{"value":7,"position":3},{"value":9,"position":4}], - |"remainingElementsCountEstimate":9223372036854775807 - |}""".compact() - val secondResponse = client.call( - net.corda.rest.tools.HttpVerb.POST, - WebRequest("numberseq/retrieve", requestBodyNewPosition), - userName, - password - ) - assertEquals(HttpStatus.SC_OK, secondResponse.responseStatus) - assertEquals(responseBodyNewPosition, secondResponse.body) - } - - @Test - fun `POST to calendar_daysoftheyear should return correct values`() { - val requestBody = """{ - "context": {"currentPosition": 1, "maxCount": 1}, - "year": "2020"}""" - val responseBody = """{ - |"positionedValues":[{"value":{"dayOfWeek":"FRIDAY","dayOfYear":"2020-01-03"},"position":2}], - |"remainingElementsCountEstimate":363, - |"isLastResult":false}""".compact() - - val response = client.call( - net.corda.rest.tools.HttpVerb.POST, - WebRequest("calendar/daysoftheyear", requestBody), - userName, - password - ) - - assertEquals(HttpStatus.SC_OK, response.responseStatus) - assertEquals(responseBody, response.body) - } - - @Test - fun `POST to calendar_daysoftheyear with update position should return correct values`() { - val requestBodyNewPosition = """{ - "context": {"currentPosition": 2, "maxCount": 2}, - "year": "2020"}""" - - val responseBodyNewPosition = """{ - |"positionedValues":[{"value":{"dayOfWeek":"SATURDAY","dayOfYear":"2020-01-04"},"position":3},{"value":{"dayOfWeek":"SUNDAY","dayOfYear":"2020-01-05"},"position":4}], - |"remainingElementsCountEstimate":361, - |"isLastResult":false}""".compact() - - val secondResponse = client.call( - net.corda.rest.tools.HttpVerb.POST, - WebRequest("calendar/daysoftheyear", requestBodyNewPosition), - userName, - password - ) - assertEquals(HttpStatus.SC_OK, secondResponse.responseStatus) - assertEquals(responseBodyNewPosition, secondResponse.body) - } -} diff --git a/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerOpenApiTest.kt b/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerOpenApiTest.kt index 0ae2cc77bfb..e5fd20f21b9 100644 --- a/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerOpenApiTest.kt +++ b/libs/rest/rest-server-impl/src/integrationTest/kotlin/net/corda/rest/server/impl/RestServerOpenApiTest.kt @@ -8,7 +8,6 @@ import io.swagger.v3.oas.models.media.Schema import net.corda.rest.server.config.models.RestServerSettings import net.corda.rest.server.impl.internal.OptionalDependency import net.corda.rest.server.impl.utils.compact -import net.corda.rest.test.CalendarRestResourceImpl import net.corda.rest.test.ObjectsInJsonEndpointImpl import net.corda.rest.test.TestEntityRestResourceImpl import net.corda.rest.test.TestFileUploadImpl @@ -47,7 +46,6 @@ class RestServerOpenApiTest : RestServerTestBase() { fun setUpBeforeClass() { server = RestServerImpl( listOf( - CalendarRestResourceImpl(), TestHealthCheckAPIImpl(), TestEntityRestResourceImpl(), TestFileUploadImpl(), @@ -85,33 +83,6 @@ class RestServerOpenApiTest : RestServerTestBase() { val openAPI = Json.mapper().readValue(body, OpenAPI::class.java) - val path = openAPI.paths["/calendar/daysoftheyear"] - assertNotNull(path) - - val requestBody = path.post.requestBody - assertTrue(requestBody.content.containsKey("application/json")) - - val mediaType = requestBody.content["application/json"] - assertNotNull(mediaType) - assertEquals("#/components/schemas/DaysOfTheYearWrapperRequest", mediaType.schema.`$ref`) - - val responseOk = path.post.responses["200"] - assertNotNull(responseOk) - // need to assert that FiniteDurableReturnResult is generated as a referenced schema rather than inline content - assertEquals( - "#/components/schemas/FiniteDurableReturnResult_of_CalendarDay", - responseOk.content["application/json"]!!.schema.`$ref` - ) - - val compactBody = body.compact() - - // need to assert "items" by contains this way because when serializing the Schema is not delegated to ArraySchema - assertThat(compactBody).contains(finiteDurableReturnResultRef.compact()) - assertThat(compactBody).contains(schemaDef.compact()) - - assertTrue(openAPI.components.schemas.containsKey("FiniteDurableReturnResult_of_CalendarDay")) - assertThat(compactBody).contains(finiteDurableReturnResultSchemaWithCalendarDayRef.compact()) - assertTrue(openAPI.components.schemas.containsKey("TimeCallDto")) val timeCallDto = openAPI.components.schemas["TimeCallDto"] assertNotNull(timeCallDto) @@ -237,7 +208,10 @@ class RestServerOpenApiTest : RestServerTestBase() { with(openAPI.paths["/fileupload/upload"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(1, multipartFormData.schema.properties.size) val file = multipartFormData.schema.properties["file"] @@ -251,7 +225,10 @@ class RestServerOpenApiTest : RestServerTestBase() { with(openAPI.paths["/fileupload/uploadwithname"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(2, multipartFormData.schema.properties.size) val fileName = multipartFormData.schema.properties["name"] @@ -269,7 +246,10 @@ class RestServerOpenApiTest : RestServerTestBase() { with(openAPI.paths["/fileupload/uploadwithoutparameterannotations"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(2, multipartFormData.schema.properties.size) val fileName = multipartFormData.schema.properties["fileName"] @@ -287,7 +267,10 @@ class RestServerOpenApiTest : RestServerTestBase() { with(openAPI.paths["/fileupload/fileuploadobject"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(1, multipartFormData.schema.properties.size) val file = multipartFormData.schema.properties["file"] @@ -301,7 +284,10 @@ class RestServerOpenApiTest : RestServerTestBase() { with(openAPI.paths["/fileupload/multifileuploadobject"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(2, multipartFormData.schema.properties.size) val file1 = multipartFormData.schema.properties["file1"] @@ -309,19 +295,30 @@ class RestServerOpenApiTest : RestServerTestBase() { assertEquals("string", file1.type, "Multipart file type should be a string.") assertEquals("binary", file1.format, "Multipart file format should be binary.") assertFalse(file1.nullable) - assertEquals("A content of the file to upload.", file1.description, "File upload should have a description.") + assertEquals( + "A content of the file to upload.", + file1.description, + "File upload should have a description." + ) val file2 = multipartFormData.schema.properties["file2"] assertNotNull(file2) assertEquals("string", file2.type, "Multipart file type should be a string.") assertEquals("binary", file2.format, "Multipart file format should be binary.") assertFalse(file2.nullable) - assertEquals("A content of the file to upload.", file2.description, "File upload should have a description.") + assertEquals( + "A content of the file to upload.", + file2.description, + "File upload should have a description." + ) } with(openAPI.paths["/fileupload/multiinputstreamfileupload"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(2, multipartFormData.schema.properties.size) val file1 = multipartFormData.schema.properties["file1"] @@ -329,19 +326,30 @@ class RestServerOpenApiTest : RestServerTestBase() { assertEquals("string", file1.type, "Multipart file type should be a string.") assertEquals("binary", file1.format, "Multipart file format should be binary.") assertFalse(file1.nullable) - assertEquals("A content of the file to upload.", file1.description, "File upload should have a description.") + assertEquals( + "A content of the file to upload.", + file1.description, + "File upload should have a description." + ) val file2 = multipartFormData.schema.properties["file2"] assertNotNull(file2) assertEquals("string", file2.type, "Multipart file type should be a string.") assertEquals("binary", file2.format, "Multipart file format should be binary.") assertFalse(file2.nullable) - assertEquals("A content of the file to upload.", file2.description, "File upload should have a description.") + assertEquals( + "A content of the file to upload.", + file2.description, + "File upload should have a description." + ) } with(openAPI.paths["/fileupload/fileuploadobjectlist"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(1, multipartFormData.schema.properties.size) val files = multipartFormData.schema.properties["files"] @@ -359,7 +367,10 @@ class RestServerOpenApiTest : RestServerTestBase() { assertEquals("tenant", queryParam.name) assertFalse(queryParam.required) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(1, multipartFormData.schema.properties.size) val file = multipartFormData.schema.properties["file"] @@ -376,7 +387,10 @@ class RestServerOpenApiTest : RestServerTestBase() { val queryParam = post.parameters.first() assertEquals("tenant", queryParam.name) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(1, multipartFormData.schema.properties.size) val file = multipartFormData.schema.properties["file"] @@ -390,7 +404,10 @@ class RestServerOpenApiTest : RestServerTestBase() { with(openAPI.paths["/fileupload/uploadwithnameinannotation"]) { assertNotNull(this) val multipartFormData = post.requestBody.content["multipart/form-data"] - assertNotNull(multipartFormData, "Multipart file upload should be under multipart form-data content in request body.") + assertNotNull( + multipartFormData, + "Multipart file upload should be under multipart form-data content in request body." + ) assertEquals("object", multipartFormData.schema.type, "Multipart file content should be in an object.") assertEquals(1, multipartFormData.schema.properties.size) val file = multipartFormData.schema.properties["differentName"] @@ -498,7 +515,8 @@ class RestServerOpenApiTest : RestServerTestBase() { val baseClient = TestHttpClientUnirestImpl("http://${restServerSettings.address.host}:${server.port}/") val swaggerUIversion = OptionalDependency.SWAGGERUI.version val swagger = baseClient.call(GET, WebRequest("api/${apiVersion.versionPath}/swagger")) - val swaggerUIBundleJS = baseClient.call(GET, WebRequest("webjars/swagger-ui/$swaggerUIversion/swagger-ui-bundle.js")) + val swaggerUIBundleJS = + baseClient.call(GET, WebRequest("webjars/swagger-ui/$swaggerUIversion/swagger-ui-bundle.js")) val swaggerUIcss = baseClient.call(GET, WebRequest("webjars/swagger-ui/$swaggerUIversion/swagger-ui.css")) assertEquals(HttpStatus.SC_OK, swagger.responseStatus) @@ -525,39 +543,4 @@ class RestServerOpenApiTest : RestServerTestBase() { } } """.trimIndent() - - private val finiteDurableReturnResultSchemaWithCalendarDayRef = """"FiniteDurableReturnResult_of_CalendarDay" : { - "required" : [ "isLastResult", "positionedValues" ], - "type" : "object", - "properties" : { - "isLastResult" : { - "type" : "boolean", - "nullable" : false, - "example" : true - }, - "positionedValues" : { - "uniqueItems" : false, - "type" : "array", - "nullable" : false, - "items" : { - "type" : "object", - "properties" : { - "position" : { - "type" : "integer", - "format" : "int64", - "nullable" : false, - "example" : 0 - }, - "value" : { - "${"$"}ref" : "#/components/schemas/CalendarDay" - } - }, - "example" : "No example available for this type" - } - } - """.trimIndent() - - private val finiteDurableReturnResultRef = """ - ref" : "#/components/schemas/FiniteDurableReturnResult_of_CalendarDay - """.trimIndent() } diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/APIStructureRetriever.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/APIStructureRetriever.kt index 3066a003ebd..a166c6fca79 100644 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/APIStructureRetriever.kt +++ b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/APIStructureRetriever.kt @@ -10,9 +10,6 @@ import net.corda.rest.annotations.HttpRestResource import net.corda.rest.annotations.HttpWS import net.corda.rest.annotations.isRestEndpointAnnotation import net.corda.rest.annotations.retrieveApiVersionsSet -import net.corda.rest.durablestream.DurableStreamContext -import net.corda.rest.durablestream.api.isFiniteDurableStreamsMethod -import net.corda.rest.durablestream.api.returnsDurableCursorBuilder import net.corda.rest.response.ResponseEntity import net.corda.rest.server.impl.apigen.models.Endpoint import net.corda.rest.server.impl.apigen.models.EndpointMethod @@ -20,8 +17,6 @@ import net.corda.rest.server.impl.apigen.models.EndpointParameter import net.corda.rest.server.impl.apigen.models.InvocationMethod import net.corda.rest.server.impl.apigen.models.Resource import net.corda.rest.server.impl.apigen.models.ResponseBody -import net.corda.rest.server.impl.apigen.processing.streams.DurableReturnResult -import net.corda.rest.server.impl.apigen.processing.streams.FiniteDurableReturnResult import net.corda.rest.tools.annotations.extensions.name import net.corda.rest.tools.annotations.extensions.path import net.corda.rest.tools.annotations.extensions.title @@ -261,7 +256,7 @@ internal class APIStructureRetriever(private val opsImplList: List { - ResponseBody( - responseDescription, - successCode, - DurableReturnResult::class.java, - this.toClassAndParameterizedTypes().second, - isReturnTypeNullable - ) - } - - this.isFiniteDurableStreamsMethod() -> { - ResponseBody( - responseDescription, - successCode, - FiniteDurableReturnResult::class.java, - this.toClassAndParameterizedTypes().second, - isReturnTypeNullable - ) - } - - else -> { - ResponseBody( - responseDescription, - successCode, - this.toClassAndParameterizedTypes().first, - this.toClassAndParameterizedTypes().second, - isReturnTypeNullable - ) - } - } - return responseBody + return ResponseBody( + responseDescription, + successCode, + this.toClassAndParameterizedTypes().first, + this.toClassAndParameterizedTypes().second, + isReturnTypeNullable + ) } private fun Method.toPUTEndpoint(annotation: HttpPUT): Endpoint { @@ -313,7 +283,7 @@ internal class APIStructureRetriever(private val opsImplList: List { + private fun Method.retrieveParameters(): List { try { log.trace { """Retrieve parameters for method "$name".""" } val methodParams = this.kotlinValueKParameters().map { ParametersTransformerFactory.create(it).transform() } - val contextParam = ParametersTransformerFactory.create( - "context", - DurableStreamContext::class.java.toEndpointParameterParameterizedType()!! - ) - .transform() - - return when { - returnsDurableCursorBuilder() && includeContextParam -> methodParams.plus(contextParam) - else -> methodParams - }.also { log.trace { """Retrieve parameters for method "$name" completed.""" } } + log.trace { """Retrieve parameters for method "$name" completed.""" } + return methodParams } catch (e: Exception) { """Error during Retrieve parameters for method "$name".""".let { log.error("$it: ${e.message}") diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvoker.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvoker.kt index c4d98cec7f0..0dd96145c32 100644 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvoker.kt +++ b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvoker.kt @@ -1,17 +1,10 @@ package net.corda.rest.server.impl.apigen.processing import net.corda.lifecycle.Lifecycle -import net.corda.rest.durablestream.DurableStreamContext -import net.corda.rest.durablestream.api.Cursor import net.corda.rest.exception.ServiceUnavailableException -import net.corda.rest.security.CURRENT_REST_CONTEXT import net.corda.rest.server.impl.apigen.models.InvocationMethod -import net.corda.rest.server.impl.apigen.processing.streams.DurableReturnResult -import net.corda.rest.server.impl.apigen.processing.streams.FiniteDurableReturnResult import net.corda.utilities.trace import org.slf4j.LoggerFactory -import java.util.function.Supplier -import javax.security.auth.login.FailedLoginException /** * [MethodInvoker] implementations are responsible for doing method invocations using the arguments provided. @@ -52,72 +45,3 @@ internal open class DefaultMethodInvoker(private val invocationMethod: Invocatio } } } - -internal open class DurableStreamsMethodInvoker(private val invocationMethod: InvocationMethod) : - DefaultMethodInvoker(invocationMethod) { - private companion object { - private val log = LoggerFactory.getLogger(this::class.java.enclosingClass) - } - - override fun invoke(vararg args: Any?): DurableReturnResult { - log.trace { "Invoke method \"${invocationMethod.method.name}\" with args size: ${args.size}." } - @Suppress("SpreadOperator") - val pollResult = invokeDurableStreamMethod(*args) - - return DurableReturnResult( - pollResult.positionedValues, - pollResult.remainingElementsCountEstimate - ).also { log.trace { "Invoke method \"${invocationMethod.method.name}\" with args size: ${args.size} completed." } } - } - - @Suppress("ThrowsCount") - internal fun invokeDurableStreamMethod(vararg args: Any?): Cursor.PollResult { - log.trace { """Invoke durable streams method "${invocationMethod.method.name}" with args size: ${args.size}.""" } - require(args.isNotEmpty()) { throw IllegalArgumentException("Method returning Durable Streams was invoked without arguments.") } - - val (durableContexts, methodArgs) = args.partition { it is DurableStreamContext } - if (durableContexts.size != 1) { - val message = - """Exactly one of the arguments is expected to be DurableStreamContext, actual: $durableContexts""" - throw IllegalArgumentException(message) - } - val durableStreamContext = durableContexts.single() as DurableStreamContext - - val restAuthContext = CURRENT_REST_CONTEXT.get() ?: throw FailedLoginException("Missing authentication context.") - with(restAuthContext) { - val restContextWithDurableStreamContext = - this.copy(invocation = this.invocation.copy(durableStreamContext = durableStreamContext)) - CURRENT_REST_CONTEXT.set(restContextWithDurableStreamContext) - } - - @Suppress("SpreadOperator") - val returnValue = super.invoke(*methodArgs.toTypedArray()) - - @Suppress("unchecked_cast") - val durableCursorTransferObject = returnValue as Supplier> - return durableCursorTransferObject.get() - .also { - log.trace { - """Invoke durable streams method "${invocationMethod.method.name}" with args size: ${args.size} completed.""" - } - } - } -} - -internal class FiniteDurableStreamsMethodInvoker(private val invocationMethod: InvocationMethod) : - DurableStreamsMethodInvoker(invocationMethod) { - private companion object { - private val log = LoggerFactory.getLogger(this::class.java.enclosingClass) - } - - override fun invoke(vararg args: Any?): FiniteDurableReturnResult { - log.trace { "Invoke method \"${invocationMethod.method.name}\" with args size: ${args.size}." } - @Suppress("SpreadOperator") - val pollResult = invokeDurableStreamMethod(*args) - return FiniteDurableReturnResult( - pollResult.positionedValues, - pollResult.remainingElementsCountEstimate, - pollResult.isLastResult - ).also { log.trace { "Invoke method \"${invocationMethod.method.name}\" with args size: ${args.size} completed." } } - } -} diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/RouteProvider.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/RouteProvider.kt index b406e62590a..dbd2909b26e 100644 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/RouteProvider.kt +++ b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/RouteProvider.kt @@ -2,8 +2,6 @@ package net.corda.rest.server.impl.apigen.processing import io.javalin.websocket.WsConfig import net.corda.rest.annotations.RestApiVersion -import net.corda.rest.durablestream.api.isFiniteDurableStreamsMethod -import net.corda.rest.durablestream.api.returnsDurableCursorBuilder import net.corda.rest.server.impl.apigen.models.Endpoint import net.corda.rest.server.impl.apigen.models.EndpointMethod import net.corda.rest.server.impl.apigen.models.EndpointParameter @@ -114,14 +112,7 @@ internal class RouteInfo( val method get() = endpoint.invocationMethod val isMultipartFileUpload get() = endpoint.parameters.any { it.isFile } - private val methodInvoker = when { - endpoint.invocationMethod.method.isFiniteDurableStreamsMethod() -> - FiniteDurableStreamsMethodInvoker(endpoint.invocationMethod) - endpoint.invocationMethod.method.returnsDurableCursorBuilder() && - !endpoint.invocationMethod.method.isFiniteDurableStreamsMethod() -> - DurableStreamsMethodInvoker(endpoint.invocationMethod) - else -> DefaultMethodInvoker(endpoint.invocationMethod) - } + private val methodInvoker = DefaultMethodInvoker(endpoint.invocationMethod) @Suppress("SpreadOperator") fun invokeDelegatedMethod(vararg args: Any?): Any? { diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProvider.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProvider.kt index 92cc69ff09c..b8815af5ebb 100644 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProvider.kt +++ b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProvider.kt @@ -12,7 +12,6 @@ import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.Sche import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaDateBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaDateTimeBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaDoubleBuilder -import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaDurableReturnResultBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaDurationBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaEnumBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaFloatBuilder @@ -23,7 +22,6 @@ import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.Sche import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaMapBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaObjectBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaPairBuilder -import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaPositionedValueBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaSetBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaStringBuilder import net.corda.rest.server.impl.apigen.processing.openapi.schema.builders.SchemaUUIDBuilder @@ -84,8 +82,6 @@ internal class DefaultSchemaModelProvider(private val schemaModelContextHolder: SchemaDurationBuilder(), StringSchemaModelBuilder(), SchemaPairBuilder(this), - SchemaDurableReturnResultBuilder(this), - SchemaPositionedValueBuilder(this), JsonSchemaBuilder(), HttpResponseTypeBuilder(this) ) diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/builders/SchemaDurableReturnResultBuilder.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/builders/SchemaDurableReturnResultBuilder.kt deleted file mode 100644 index c0e555d38c3..00000000000 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/builders/SchemaDurableReturnResultBuilder.kt +++ /dev/null @@ -1,54 +0,0 @@ -package net.corda.rest.server.impl.apigen.processing.openapi.schema.builders - -import net.corda.rest.server.impl.apigen.models.GenericParameterizedType -import net.corda.rest.server.impl.apigen.processing.openapi.schema.ParameterizedClass -import net.corda.rest.server.impl.apigen.processing.openapi.schema.SchemaModelProvider -import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaDurableReturnResultModel -import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaModel -import net.corda.rest.server.impl.apigen.processing.streams.DurableReturnResult -import net.corda.rest.server.impl.apigen.processing.streams.FiniteDurableReturnResult -import net.corda.rest.server.impl.apigen.processing.toEndpointParameterParameterizedType -import kotlin.reflect.KClass -import kotlin.reflect.KVisibility -import kotlin.reflect.full.memberProperties -import kotlin.reflect.jvm.javaType - -internal class SchemaDurableReturnResultBuilder(private val schemaModelProvider: SchemaModelProvider) : SchemaBuilder { - override val keys: List> = listOf(FiniteDurableReturnResult::class.java, DurableReturnResult::class.java) - - override fun build(clazz: Class<*>, parameterizedClassList: List): SchemaModel { - val positionedValueType = parameterizedClassList.single() - - return SchemaDurableReturnResultModel( - clazz.kotlin.memberProperties.filter { it.visibility == KVisibility.PUBLIC } - .associate { - val endpointParameterParameterizedTypes = it.returnType.arguments.mapNotNull { argument -> - argument.type?.javaType?.toEndpointParameterParameterizedType() - } - .run { if (it.name == "positionedValues") toPositionedValuesGenericTypes(positionedValueType) else this } - - it.name to schemaModelProvider.toSchemaModel( - ParameterizedClass( - (it.returnType.classifier as? KClass<*>?)?.java ?: Any::class.java, - endpointParameterParameterizedTypes, - it.returnType.isMarkedNullable - ) - ) - }.toSortedMap() - ) - } - - private fun List.toPositionedValuesGenericTypes(positionedValueType: GenericParameterizedType) = - this.let { genericParameterizedTypes -> - if (genericParameterizedTypes.size == 1 && genericParameterizedTypes.single().nestedParameterizedTypes.size == 1) { - listOf( - GenericParameterizedType( - genericParameterizedTypes.single().clazz, - listOf(positionedValueType) - ) - ) - } else { - genericParameterizedTypes - } - } -} diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/builders/SchemaPositionedValueBuilder.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/builders/SchemaPositionedValueBuilder.kt deleted file mode 100644 index 70d552c7829..00000000000 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/builders/SchemaPositionedValueBuilder.kt +++ /dev/null @@ -1,43 +0,0 @@ -package net.corda.rest.server.impl.apigen.processing.openapi.schema.builders - -import net.corda.rest.durablestream.api.Cursor -import net.corda.rest.server.impl.apigen.models.GenericParameterizedType -import net.corda.rest.server.impl.apigen.processing.openapi.schema.ParameterizedClass -import net.corda.rest.server.impl.apigen.processing.openapi.schema.SchemaModelProvider -import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaModel -import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaPositionedValueModel -import net.corda.rest.server.impl.apigen.processing.toEndpointParameterParameterizedType -import kotlin.reflect.KClass -import kotlin.reflect.KProperty1 -import kotlin.reflect.KVisibility -import kotlin.reflect.full.memberProperties -import kotlin.reflect.jvm.javaType - -internal class SchemaPositionedValueBuilder(private val schemaModelProvider: SchemaModelProvider) : SchemaBuilder { - override val keys: List> = listOf(Cursor.PollResult.PositionedValue::class.java) - - override fun build(clazz: Class<*>, parameterizedClassList: List): SchemaModel { - return SchemaPositionedValueModel( - clazz.kotlin.memberProperties.filter { it.visibility == KVisibility.PUBLIC } - .associate { - if (it.name == "value" && parameterizedClassList.size == 1) { - it.getPositionedValueObject(parameterizedClassList.single()) - } else { - it.name to schemaModelProvider.toSchemaModel( - ParameterizedClass( - (it.returnType.classifier as? KClass<*>?)?.java ?: Any::class.java, - it.returnType.arguments.mapNotNull { argument -> - argument.type?.javaType?.toEndpointParameterParameterizedType() - }, - it.returnType.isMarkedNullable - ) - - ) - } - }.toSortedMap() - ) - } - - private fun KProperty1.getPositionedValueObject(type: GenericParameterizedType) = - this.name to schemaModelProvider.toSchemaModel(ParameterizedClass(type.clazz, type.nestedParameterizedTypes)) -} diff --git a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/streams/StreamResponseObjects.kt b/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/streams/StreamResponseObjects.kt deleted file mode 100644 index 98d21dea1c3..00000000000 --- a/libs/rest/rest-server-impl/src/main/kotlin/net/corda/rest/server/impl/apigen/processing/streams/StreamResponseObjects.kt +++ /dev/null @@ -1,14 +0,0 @@ -package net.corda.rest.server.impl.apigen.processing.streams - -import net.corda.rest.durablestream.api.Cursor - -open class DurableReturnResult( - val positionedValues: List>, - val remainingElementsCountEstimate: Long? -) - -class FiniteDurableReturnResult( - positionedValues: List>, - remainingElementsCountEstimate: Long?, - val isLastResult: Boolean -) : DurableReturnResult(positionedValues, remainingElementsCountEstimate) diff --git a/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/APIStructureRetrieverTest.kt b/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/APIStructureRetrieverTest.kt index a2c3ae375c2..ae7fb99ac2c 100644 --- a/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/APIStructureRetrieverTest.kt +++ b/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/APIStructureRetrieverTest.kt @@ -1,70 +1,17 @@ package net.corda.rest.server.impl.apigen -import net.corda.rest.durablestream.DurableStreamContext import net.corda.rest.server.apigen.test.TestJavaPrimitivesRestResourceImpl -import net.corda.rest.server.impl.apigen.models.EndpointMethod -import net.corda.rest.server.impl.apigen.models.GenericParameterizedType -import net.corda.rest.server.impl.apigen.models.ParameterType import net.corda.rest.server.impl.apigen.processing.APIStructureRetriever -import net.corda.rest.server.impl.apigen.processing.streams.FiniteDurableReturnResult import net.corda.rest.server.impl.rest.resources.impl.TestDuplicateProtocolVersionAPIImpl import net.corda.rest.server.impl.rest.resources.impl.TestRestAPIAnnotatedImpl import net.corda.rest.server.impl.rest.resources.impl.TestRestApiImpl -import net.corda.rest.test.CalendarRestResource -import net.corda.rest.test.CalendarRestResourceImpl import net.corda.rest.test.TestHealthCheckAPIImpl import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test -import kotlin.reflect.jvm.javaMethod internal class APIStructureRetrieverTest { - @Test - @Suppress("ComplexMethod") - fun `structure withSimpleClass shouldSucceed`() { - val retriever = APIStructureRetriever(listOf(CalendarRestResourceImpl())) - - val resources = retriever.structure - - assertEquals(1, resources.size) - - with(resources.single()) { - assertEquals(2, endpoints.size) - assert(endpoints.any { it.path == "getprotocolversion" }) - assert(endpoints.any { it.path == "daysoftheyear" }) - - with(endpoints.single { it.path == "daysoftheyear" }) { - assertEquals("", description) - assertEquals("daysOfTheYear", title) - assertEquals("", description) - assertEquals(EndpointMethod.POST, method) - assertEquals(2, parameters.size) - assert(parameters.any { it.classType == DurableStreamContext::class.java }) - assert(parameters.any { it.classType == Int::class.java }) - with(parameters.single { it.classType == Int::class.java }) { - assertEquals("year", id) - assertEquals("year", name) - assertEquals("", description) - assertTrue(required) - assertNull(default) - assertEquals(ParameterType.BODY, type) - } - with(responseBody) { - assertEquals("", description) - assertEquals(FiniteDurableReturnResult::class.java, type) - assertEquals(listOf(GenericParameterizedType(CalendarRestResource.CalendarDay::class.java)), parameterizedTypes) - } - with(invocationMethod) { - assertEquals(CalendarRestResource::daysOfTheYear.javaMethod, method) - assertEquals(CalendarRestResourceImpl::class.java, instance::class.java) - } - } - } - } - @Test fun `structure withNonRESTInterface shouldIgnoreItSuccessfully`() { val retriever = APIStructureRetriever(listOf(TestHealthCheckAPIImpl(), TestRestApiImpl())) diff --git a/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvokerTest.kt b/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvokerTest.kt deleted file mode 100644 index c5e61d446a0..00000000000 --- a/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/MethodInvokerTest.kt +++ /dev/null @@ -1,49 +0,0 @@ -package net.corda.rest.server.impl.apigen.processing - -import net.corda.rest.durablestream.DurableStreamContext -import net.corda.rest.security.CURRENT_REST_CONTEXT -import net.corda.rest.server.impl.apigen.models.InvocationMethod -import net.corda.rest.test.TestHealthCheckAPI -import net.corda.rest.test.TestHealthCheckAPIImpl -import org.assertj.core.api.Assertions.assertThatThrownBy -import org.junit.jupiter.api.Test -import javax.security.auth.login.FailedLoginException -import kotlin.reflect.jvm.javaMethod - -internal class MethodInvokerTest { - - private val invoker = DurableStreamsMethodInvoker( - InvocationMethod( - TestHealthCheckAPI::bodyPlayground.javaMethod!!, - TestHealthCheckAPIImpl() - ) - ) - - @Test - fun `invoke durableStreamsMethodInvoker withNoArgs throws`() { - assertThatThrownBy { invoker.invokeDurableStreamMethod() } - .isInstanceOf(IllegalArgumentException::class.java) - .hasMessage("Method returning Durable Streams was invoked without arguments.") - } - - @Test - fun `invoke durableStreamsMethodInvoker withoutContextArg throws`() { - assertThatThrownBy { invoker.invokeDurableStreamMethod("test") } - .isInstanceOf(IllegalArgumentException::class.java) - } - - @Test - fun `invoke durableStreamsMethodInvoker withMoreThan1ContextArg throws`() { - assertThatThrownBy { - invoker.invokeDurableStreamMethod(DurableStreamContext(1, 1), DurableStreamContext(1, 1)) - }.isInstanceOf(IllegalArgumentException::class.java) - } - - @Test - fun `invoke durableStreamsMethodInvoker withContextNotSet throws`() { - CURRENT_REST_CONTEXT.remove() - assertThatThrownBy { invoker.invokeDurableStreamMethod(DurableStreamContext(1L, 1)) } - .isInstanceOf(FailedLoginException::class.java) - .hasMessage("Missing authentication context.") - } -} diff --git a/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProviderTest.kt b/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProviderTest.kt index 7fed1345b39..70f2a1550bf 100644 --- a/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProviderTest.kt +++ b/libs/rest/rest-server-impl/src/test/kotlin/net/corda/rest/server/impl/apigen/processing/openapi/schema/SchemaModelProviderTest.kt @@ -1,7 +1,6 @@ package net.corda.rest.server.impl.apigen.processing.openapi.schema import net.corda.rest.HttpFileUpload -import net.corda.rest.durablestream.api.Cursor import net.corda.rest.server.apigen.processing.openapi.schema.TestNestedClass import net.corda.rest.server.impl.apigen.models.EndpointParameter import net.corda.rest.server.impl.apigen.models.GenericParameterizedType @@ -13,8 +12,6 @@ import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaE import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaMapModel import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaPairModel import net.corda.rest.server.impl.apigen.processing.openapi.schema.model.SchemaRefObjectModel -import net.corda.rest.server.impl.apigen.processing.streams.DurableReturnResult -import net.corda.rest.server.impl.apigen.processing.streams.FiniteDurableReturnResult import net.corda.v5.base.types.MemberX500Name import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull @@ -314,7 +311,7 @@ class SchemaModelProviderTest { assertEquals(null, result.type) assertEquals(null, result.format) - assertEquals(2, (result as SchemaEnumModel).enum!!.size) + assertEquals(1, (result as SchemaEnumModel).enum!!.size) } @Test @@ -328,7 +325,7 @@ class SchemaModelProviderTest { assertEquals(null, result.type) assertEquals(null, result.format) - assertEquals(2, (result as SchemaEnumModel).enum!!.size) + assertEquals(1, (result as SchemaEnumModel).enum!!.size) } @Test @@ -608,41 +605,6 @@ class SchemaModelProviderTest { } } - @Test - fun `build with DurableReturnResult succeeds`() { - val schemaModelContextHolder = SchemaModelContextHolder() - val provider = DefaultSchemaModelProvider(schemaModelContextHolder) - val data = DurableReturnResult(listOf(testPositionedValue("a")), 1) - val mockParam = endpointParameter( - data::class.javaObjectType, - listOf(GenericParameterizedType(String::class.java, emptyList())) - ) - - val result = provider.toSchemaModel(mockParam) - assertNull(result.format) - assertNull(result.type) - result as SchemaRefObjectModel - assertEquals("DurableReturnResult_of_String", result.ref) - } - - @Test - fun `build with FiniteDurableReturnResult succeeds`() { - val schemaModelContextHolder = SchemaModelContextHolder() - val provider = DefaultSchemaModelProvider(schemaModelContextHolder) - val data = FiniteDurableReturnResult(listOf(testPositionedValue("a")), 1, false) - val mockParam = endpointParameter( - data::class.javaObjectType, - listOf(GenericParameterizedType(String::class.java, emptyList())) - ) - - val result = provider.toSchemaModel(mockParam) - - assertNull(result.type) - assertNull(result.format) - result as SchemaRefObjectModel - assertEquals("FiniteDurableReturnResult_of_String", result.ref) - } - @Test fun `build with multiple generics types succeeds`() { val schemaModelContextHolder = SchemaModelContextHolder() @@ -660,45 +622,6 @@ class SchemaModelProviderTest { assertEquals("TestClass_of_String_int", (result as SchemaRefObjectModel).ref) } - @Test - fun `build with same class name in different packages succeeds`() { - val schemaModelContextHolder = SchemaModelContextHolder() - val provider = DefaultSchemaModelProvider(schemaModelContextHolder) - - val result = - provider.toSchemaModel( - ParameterizedClass(net.corda.rest.server.impl.apigen.processing.DurableStreamsMethodInvoker::class.java) - ) - assertEquals("DurableStreamsMethodInvoker", (result as SchemaRefObjectModel).ref) - - val result2 = provider.toSchemaModel(ParameterizedClass(DurableStreamsMethodInvoker::class.java)) - assertEquals("DurableStreamsMethodInvoker_1", (result2 as SchemaRefObjectModel).ref) - } - - @Test - fun `build with same class succeeds`() { - val schemaModelContextHolder = SchemaModelContextHolder() - val provider = DefaultSchemaModelProvider(schemaModelContextHolder) - - val result = provider.toSchemaModel( - ParameterizedClass( - DurableStreamsMethodInvoker::class.java, - listOf(GenericParameterizedType(String::class.java)) - ) - ) - assertEquals("DurableStreamsMethodInvoker_of_String", (result as SchemaRefObjectModel).ref) - - val result2 = provider.toSchemaModel( - ParameterizedClass( - DurableStreamsMethodInvoker::class.java, - listOf(GenericParameterizedType(Date::class.java)) - ) - ) - assertEquals("DurableStreamsMethodInvoker_of_Date", (result2 as SchemaRefObjectModel).ref) - } - - class DurableStreamsMethodInvoker - class NestedTestClass( val aa: List = listOf("aa"), val bb: Int = 1, @@ -726,15 +649,6 @@ class SchemaModelProviderTest { } private enum class TestEnum { - ONE, TWO - } - - private fun testPositionedValue(value: T): Cursor.PollResult.PositionedValue { - return object : Cursor.PollResult.PositionedValue { - override val position: Long - get() = 1 - override val value: T - get() = value - } + ONE } } diff --git a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/CalendarRestResource.kt b/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/CalendarRestResource.kt deleted file mode 100644 index 78d61326a18..00000000000 --- a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/CalendarRestResource.kt +++ /dev/null @@ -1,16 +0,0 @@ -package net.corda.rest.test - -import net.corda.rest.RestResource -import net.corda.rest.annotations.HttpPOST -import net.corda.rest.annotations.HttpRestResource -import net.corda.rest.durablestream.api.FiniteDurableCursorBuilder -import java.time.DayOfWeek - -@HttpRestResource(name = "CalendarRestResource", description = "Calendar REST resource", path = "calendar") -interface CalendarRestResource : RestResource { - - data class CalendarDay(val dayOfWeek: DayOfWeek, val dayOfYear: String) - - @HttpPOST(path = "daysOfTheYear") - fun daysOfTheYear(year: Int): FiniteDurableCursorBuilder -} diff --git a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/CalendarRestResourceImpl.kt b/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/CalendarRestResourceImpl.kt deleted file mode 100644 index d5a7281d98e..00000000000 --- a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/CalendarRestResourceImpl.kt +++ /dev/null @@ -1,45 +0,0 @@ -package net.corda.rest.test - -import net.corda.rest.PluggableRestResource -import net.corda.rest.durablestream.DurableStreamHelper -import net.corda.rest.durablestream.api.FiniteDurableCursorBuilder -import java.time.DayOfWeek -import java.time.format.DateTimeFormatter -import java.util.Calendar -import java.util.GregorianCalendar - -@Suppress("MagicNumber") -class CalendarRestResourceImpl : CalendarRestResource, PluggableRestResource { - - override val targetInterface: Class - get() = CalendarRestResource::class.java - - override val protocolVersion = 1000 - - override fun daysOfTheYear(year: Int): FiniteDurableCursorBuilder { - return DurableStreamHelper.withDurableStreamContext { - val calendar = GregorianCalendar().apply { - set(Calendar.YEAR, year) - set(Calendar.HOUR, 10) - set(Calendar.MINUTE, 0) - set(Calendar.SECOND, 0) - set(Calendar.MILLISECOND, 0) - } - val daysPerYear = if (calendar.isLeapYear(year)) 366L else 365L - - val longRange = (currentPosition + 1)..(currentPosition + maxCount).coerceAtMost(daysPerYear - 1) - val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") - val positionedValues = longRange.map { pos -> - val dayOfYear = pos.toInt() + 1 - calendar.set(Calendar.DAY_OF_YEAR, dayOfYear) - val zdt = calendar.toZonedDateTime() - val dayOfWeek = DayOfWeek.from(zdt) - val dateAsString = formatter.format(zdt) - pos to CalendarRestResource.CalendarDay(dayOfWeek, dateAsString) - } - - val remainingElementsCountEstimate = daysPerYear - longRange.last - 1 - DurableStreamHelper.outcome(remainingElementsCountEstimate, remainingElementsCountEstimate == 0L, positionedValues) - } - } -} diff --git a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/NumberSequencesRestResource.kt b/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/NumberSequencesRestResource.kt deleted file mode 100644 index a7f8476244c..00000000000 --- a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/NumberSequencesRestResource.kt +++ /dev/null @@ -1,20 +0,0 @@ -package net.corda.rest.test - -import net.corda.rest.RestResource -import net.corda.rest.annotations.HttpPOST -import net.corda.rest.annotations.HttpRestResource -import net.corda.rest.durablestream.api.DurableCursorBuilder - -enum class NumberTypeEnum { - EVEN, ODD -} - -@HttpRestResource( - name = "net.corda.rest.server.impl.rest.resource.NumberSequencesRestResource", - description = "Number Sequences Rest Resource", - path = "numberseq" -) -interface NumberSequencesRestResource : RestResource { - @HttpPOST(path = "retrieve") - fun retrieve(type: NumberTypeEnum): DurableCursorBuilder -} diff --git a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/NumberSequencesRestResourceImpl.kt b/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/NumberSequencesRestResourceImpl.kt deleted file mode 100644 index e82f41ea074..00000000000 --- a/libs/rest/rest-test-common/src/main/kotlin/net/corda/rest/test/NumberSequencesRestResourceImpl.kt +++ /dev/null @@ -1,27 +0,0 @@ -package net.corda.rest.test - -import net.corda.rest.PluggableRestResource -import net.corda.rest.durablestream.DurableStreamHelper -import net.corda.rest.durablestream.api.DurableCursorBuilder - -@Suppress("MagicNumber") -class NumberSequencesRestResourceImpl : NumberSequencesRestResource, PluggableRestResource { - - override val targetInterface: Class - get() = NumberSequencesRestResource::class.java - - override val protocolVersion = 1000 - - override fun retrieve(type: NumberTypeEnum): DurableCursorBuilder { - return DurableStreamHelper.withDurableStreamContext { - val pad = when (type) { - NumberTypeEnum.EVEN -> 0 - NumberTypeEnum.ODD -> 1 - } - - val longRange: LongRange = (currentPosition + 1)..(currentPosition + maxCount) - val positionedValues = longRange.map { pos -> pos to (pad + pos * 2) } - DurableStreamHelper.outcome(Long.MAX_VALUE, false, positionedValues) - } - } -} diff --git a/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsContextParameterValidator.kt b/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsContextParameterValidator.kt deleted file mode 100644 index 662b22c4ccc..00000000000 --- a/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsContextParameterValidator.kt +++ /dev/null @@ -1,43 +0,0 @@ -package net.corda.rest.tools.annotations.validation - -import net.corda.rest.RestResource -import net.corda.rest.annotations.HttpPOST -import net.corda.rest.annotations.HttpPUT -import net.corda.rest.durablestream.api.returnsDurableCursorBuilder -import net.corda.rest.tools.annotations.validation.utils.getParameterName -import net.corda.rest.tools.annotations.validation.utils.isBodyParameter -import java.lang.reflect.Method - -/** - * Validates that durable stream methods do not contain a "context" parameter, as it would clash with the implicitly created parameter with - * the same name. - */ -class DurableStreamsContextParameterValidator(private val clazz: Class) : RestValidator { - - companion object { - const val error = "Methods returning DurableCursorBuilder or FiniteDurableCursorBuilder " + - "are not allowed to have a body parameter with the name 'context'" - } - - override fun validate(): RestValidationResult = - clazz.methods.fold(RestValidationResult()) { total, method -> - total + if (method.annotations.any { it is HttpPOST || it is HttpPUT }) { - validateBodyParameterOnPOST(method) - } else { - RestValidationResult() - } - } - - private fun validateBodyParameterOnPOST(method: Method) = - if (method.returnsDurableCursorBuilder()) { - method.parameters.count { it.isBodyParameter() && getParameterName(it) == "context" } - .run { - when (this) { - 0 -> RestValidationResult() - else -> RestValidationResult(listOf(error)) - } - } - } else { - RestValidationResult() - } -} diff --git a/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsEndPointValidator.kt b/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsEndPointValidator.kt deleted file mode 100644 index 5cdaf9e49ec..00000000000 --- a/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsEndPointValidator.kt +++ /dev/null @@ -1,35 +0,0 @@ -package net.corda.rest.tools.annotations.validation - -import net.corda.rest.RestResource -import net.corda.rest.annotations.HttpPOST -import net.corda.rest.annotations.HttpPUT -import net.corda.rest.durablestream.api.returnsDurableCursorBuilder -import java.lang.reflect.Method - -/** - * Validates that durable stream methods are POST or PUT. This is required, as an implicit DurableStreamContext parameter - * will be added to the call. - */ -internal class DurableStreamsEndPointValidator(private val clazz: Class) : RestValidator { - - companion object { - val error = "Methods returning DurableCursorBuilder or FiniteDurableCursorBuilder " + - "can only be exposed via ${HttpPOST::class.simpleName} or ${HttpPUT::class.simpleName}." - } - - override fun validate(): RestValidationResult = - clazz.methods.fold(RestValidationResult()) { total, method -> - total + if (method.annotations.none { it is HttpPOST || it is HttpPUT }) { - validateReturnTypeOnWrongMethod(method) - } else { - RestValidationResult() - } - } - - private fun validateReturnTypeOnWrongMethod(method: Method) = - if (method.returnsDurableCursorBuilder()) { - RestValidationResult(listOf(error)) - } else { - RestValidationResult() - } -} diff --git a/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/RestInterfaceValidator.kt b/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/RestInterfaceValidator.kt index 2e5a8117799..e2b7474fa03 100644 --- a/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/RestInterfaceValidator.kt +++ b/libs/rest/rest-tools/src/main/kotlin/net/corda/rest/tools/annotations/validation/RestInterfaceValidator.kt @@ -25,8 +25,6 @@ object RestInterfaceValidator { ParameterClassTypeValidator(rpcOpsInterface), PathParameterInURLPathValidator(rpcOpsInterface), URLPathParameterNotDeclaredValidator(rpcOpsInterface), - DurableStreamsEndPointValidator(rpcOpsInterface), - DurableStreamsContextParameterValidator(rpcOpsInterface), NestedGenericsParameterTypeValidator(rpcOpsInterface), EndpointMinMaxVersionValidator(rpcOpsInterface), ).fold(RestValidationResult()) { total, next -> total + next.validate() } diff --git a/libs/rest/rest-tools/src/test/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsContextParameterValidatorTest.kt b/libs/rest/rest-tools/src/test/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsContextParameterValidatorTest.kt deleted file mode 100644 index e1c7e2b8975..00000000000 --- a/libs/rest/rest-tools/src/test/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsContextParameterValidatorTest.kt +++ /dev/null @@ -1,108 +0,0 @@ -package net.corda.rest.tools.annotations.validation - -import net.corda.rest.RestResource -import net.corda.rest.annotations.ClientRequestBodyParameter -import net.corda.rest.annotations.HttpGET -import net.corda.rest.annotations.HttpPOST -import net.corda.rest.annotations.HttpRestResource -import net.corda.rest.annotations.RestPathParameter -import net.corda.rest.annotations.RestQueryParameter -import net.corda.rest.durablestream.api.DurableCursorBuilder -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test - -class DurableStreamsContextParameterValidatorTest { - - @Test - fun `validate with POST Endpoint DurableStreamsReturnType Context BodyParameter errorListContainsMessage`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpPOST - abstract fun test(@ClientRequestBodyParameter context: String): DurableCursorBuilder - - @HttpPOST - abstract fun test2(@ClientRequestBodyParameter(name = "context") notContext: String): DurableCursorBuilder - - @HttpPOST - abstract fun testImplicitBodyParam(context: String): DurableCursorBuilder - } - - val result = DurableStreamsContextParameterValidator(TestInterface::class.java).validate() - - Assertions.assertEquals(3, result.errors.size) - Assertions.assertEquals(DurableStreamsContextParameterValidator.error, result.errors.first()) - } - - @Test - fun `validate with POST Endpoint DurableStreamsReturnType Context Query OR Path Parameter errorListEmpty`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpPOST - abstract fun test(@RestQueryParameter context: String): DurableCursorBuilder - - @HttpPOST - abstract fun test2(@RestQueryParameter(name = "context") notContext: String): DurableCursorBuilder - - @HttpPOST - abstract fun test3(@RestPathParameter context: String): DurableCursorBuilder - - @HttpPOST - abstract fun test4(@RestPathParameter(name = "context") notContext: String): DurableCursorBuilder - } - - val result = DurableStreamsContextParameterValidator(TestInterface::class.java).validate() - Assertions.assertEquals(0, result.errors.size) - } - - @Test - fun `validate with GET Endpoint DurableStreamsReturnType Context BodyParameter errorListEmpty`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpGET - abstract fun test(@ClientRequestBodyParameter context: String): DurableCursorBuilder - - @HttpGET - abstract fun test2(@ClientRequestBodyParameter(name = "context") notContext: String): DurableCursorBuilder - - @HttpGET - abstract fun testImplicitBodyParam(context: String): DurableCursorBuilder - } - - val result = DurableStreamsContextParameterValidator(TestInterface::class.java).validate() - Assertions.assertEquals(0, result.errors.size) - } - - @Test - fun `validate with POST Endpoint DurableStreamsReturnType BodyParameter isNotCalledContext errorListEmpty`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpPOST - abstract fun test(@ClientRequestBodyParameter notContext: String): DurableCursorBuilder - - @HttpPOST - abstract fun test2(@ClientRequestBodyParameter(name = "contextOverriden") context: String): DurableCursorBuilder - - @HttpPOST - abstract fun testImplicitBodyParam(notContext: String): DurableCursorBuilder - } - - val result = DurableStreamsContextParameterValidator(TestInterface::class.java).validate() - Assertions.assertEquals(0, result.errors.size) - } -} diff --git a/libs/rest/rest-tools/src/test/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsEndPointValidatorTest.kt b/libs/rest/rest-tools/src/test/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsEndPointValidatorTest.kt deleted file mode 100644 index f68e178d382..00000000000 --- a/libs/rest/rest-tools/src/test/kotlin/net/corda/rest/tools/annotations/validation/DurableStreamsEndPointValidatorTest.kt +++ /dev/null @@ -1,65 +0,0 @@ -package net.corda.rest.tools.annotations.validation - -import net.corda.rest.RestResource -import net.corda.rest.annotations.HttpGET -import net.corda.rest.annotations.HttpPOST -import net.corda.rest.annotations.HttpRestResource -import net.corda.rest.durablestream.api.DurableCursorBuilder -import net.corda.rest.durablestream.api.FiniteDurableCursorBuilder -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.Test - -class DurableStreamsEndPointValidatorTest { - - @Test - fun `validate with GET Endpoint DurableStreamsReturnType errorListContainsMessage`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpGET - abstract fun test(): DurableCursorBuilder - } - - val result = DurableStreamsEndPointValidator(TestInterface::class.java).validate() - - Assertions.assertEquals(1, result.errors.size) - Assertions.assertEquals(DurableStreamsEndPointValidator.error, result.errors.single()) - } - - @Test - fun `validate with GET Endpoint FiniteDurableStreamsReturnType errorListContainsMessage`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpGET - abstract fun test(): FiniteDurableCursorBuilder - } - - val result = DurableStreamsEndPointValidator(TestInterface::class.java).validate() - - Assertions.assertEquals(1, result.errors.size) - Assertions.assertEquals(DurableStreamsEndPointValidator.error, result.errors.single()) - } - - @Test - fun `validate with POST Endpoint DurableStreamsReturnType errorList Is Empty`() { - @Suppress("unused") - @HttpRestResource - abstract class TestInterface : RestResource { - override val protocolVersion: Int - get() = 1 - - @HttpPOST - abstract fun test(): DurableCursorBuilder - } - - val result = DurableStreamsEndPointValidator(TestInterface::class.java).validate() - Assertions.assertEquals(0, result.errors.size) - } -}