ConnectivityProxyActor extends AbstractActor { public static Props props(final ActorRef conciergeForwarder) { return Props.create(ConnectivityProxyActor.class, conciergeForwarder); } private  ConnectivityProxyActor(final ActorRef conciergeForwarder); static Props props(final ActorRef conciergeForwarder); @Override Receive createReceive(); static final String ACTOR_NAME; }
@Test public void testRetrieveThings() { new TestKit(actorSystem) {{ final Props props = ConnectivityProxyActor.props(getRef()); final ActorRef proxy = actorSystem.actorOf(props); final List<Thing> thingList = IntStream.range(0, 10) .mapToObj(i -> ThingId.of(KNOWN_THING_ID.getNamespace(), KNOWN_THING_ID.getName() + "-" + i)) .map(id -> Thing.newBuilder().setId(id).build()) .collect(Collectors.toList()); final ThingId[] thingIdsArray = thingList.stream().map(Thing::getEntityId).map(Optional::get).toArray(ThingId[]::new); final String correlationId = UUID.randomUUID().toString(); final DittoHeaders headers = DittoHeaders.newBuilder().correlationId(correlationId).contentType("application/json").build(); final RetrieveThings retrieveThings = RetrieveThings.getBuilder(thingIdsArray).dittoHeaders(headers).build(); proxy.tell(retrieveThings, getRef()); expectMsg(retrieveThings); final SourceRef<RetrieveThingResponse> retrieveThingResponseSourceRef = Source.from(retrieveThings.getThingEntityIds()) .map(thingId -> Thing.newBuilder().setId(thingId).build()) .map(thing -> RetrieveThingResponse. of(thing.getEntityId().orElseThrow(), thing, DittoHeaders.empty())) .runWith(StreamRefs.sourceRef(), actorSystem); getLastSender().tell(retrieveThingResponseSourceRef, ActorRef.noSender()); final RetrieveThingsResponse retrieveThingsResponse = expectMsgClass(RetrieveThingsResponse.class); assertThat(retrieveThingsResponse.getThings()).containsExactlyElementsOf(thingList); }}; }
@Test public void testForwardOtherSignal() { new TestKit(actorSystem) {{ final Signal<?> signal = Mockito.mock(Signal.class); Mockito.when(signal.getDittoHeaders()).thenReturn(DittoHeaders.empty()); final Props props = ConnectivityProxyActor.props(getRef()); final ActorRef proxy = actorSystem.actorOf(props); proxy.tell(signal, getRef()); expectMsg(signal); final Signal<?> response = Mockito.mock(Signal.class); Mockito.when(response.getDittoHeaders()).thenReturn(DittoHeaders.empty()); getLastSender().tell(response, ActorRef.noSender()); expectMsg(response); }}; }