-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first test for live command response handling of http-push
Signed-off-by: Joel Bartelheimer <joel.bartelheimer@bosch.io>
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...rg/eclipse/ditto/connectivity/service/messaging/httppush/HttpTestDittoProtocolHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.connectivity.service.messaging.httppush; | ||
|
||
import java.util.Collections; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.ditto.base.model.json.Jsonifiable; | ||
import org.eclipse.ditto.base.model.signals.Signal; | ||
import org.eclipse.ditto.connectivity.api.ExternalMessageFactory; | ||
import org.eclipse.ditto.connectivity.api.OutboundSignal; | ||
import org.eclipse.ditto.connectivity.api.OutboundSignalFactory; | ||
import org.eclipse.ditto.connectivity.model.Target; | ||
import org.eclipse.ditto.protocol.Adaptable; | ||
import org.eclipse.ditto.protocol.ProtocolFactory; | ||
import org.eclipse.ditto.protocol.adapter.DittoProtocolAdapter; | ||
|
||
import akka.actor.ActorRef; | ||
|
||
public final class HttpTestDittoProtocolHelper { | ||
|
||
private HttpTestDittoProtocolHelper() { | ||
throw new AssertionError("nope"); | ||
} | ||
|
||
private static final Function<Signal<?>, Adaptable> TO_ADAPTABLE = DittoProtocolAdapter.newInstance()::toAdaptable; | ||
|
||
public static String signalToJsonString(final Signal<?> signal) { | ||
return TO_ADAPTABLE | ||
.andThen(ProtocolFactory::wrapAsJsonifiableAdaptable) | ||
.andThen(Jsonifiable::toJson) | ||
.andThen(Object::toString) | ||
.apply(signal); | ||
} | ||
|
||
public static OutboundSignal.MultiMapped toMultiMapped(final Signal<?> signal, | ||
final Target target, | ||
final ActorRef sender) { | ||
|
||
final var outboundSignal = | ||
OutboundSignalFactory.newOutboundSignal(signal, Collections.singletonList(target)); | ||
|
||
final var externalMessage = | ||
ExternalMessageFactory.newExternalMessageBuilder(Collections.emptyMap()) | ||
.withText("payload") | ||
.build(); | ||
|
||
return TO_ADAPTABLE | ||
.andThen(a -> OutboundSignalFactory.newMappedOutboundSignal(outboundSignal, a, externalMessage)) | ||
.andThen(Collections::singletonList) | ||
.andThen(ls -> OutboundSignalFactory.newMultiMappedOutboundSignal(ls, sender)) | ||
.apply(signal); | ||
} | ||
} |