Skip to content

Commit

Permalink
add doCommand in missed files
Browse files Browse the repository at this point in the history
  • Loading branch information
gloriacai01 committed Aug 30, 2024
1 parent fecfca9 commit 4ea7699
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.viam.sdk.core.component.servo;
import com.google.protobuf.Struct;
import com.viam.common.v1.Common;
import com.viam.component.servo.v1.ServoServiceGrpc;
import com.viam.sdk.core.resource.ResourceRPCService;
Expand Down Expand Up @@ -62,6 +63,14 @@ public void getGeometries(com.viam.common.v1.Common.GetGeometriesRequest request
List<Common.Geometry> geometries = servo.getGeometries(Optional.ofNullable(request.getExtra()));
responseObserver.onNext(Common.GetGeometriesResponse.newBuilder().addAllGeometries(geometries).build());
responseObserver.onCompleted();
}
@Override
public void doCommand(Common.DoCommandRequest request,
StreamObserver<Common.DoCommandResponse> responseObserver) {

Servo servo = getResource(Servo.named(request.getName()));
Struct result = servo.doCommand(request.getCommand().getFieldsMap());
responseObserver.onNext(Common.DoCommandResponse.newBuilder().setResult(result).build());
responseObserver.onCompleted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,14 @@ class ServoRPCClientTest {
assertEquals(80, pos)
}

@Test
fun doCommand() {
val command = mapOf("foo" to Value.newBuilder().setStringValue("bar").build())
doReturn(Struct.newBuilder().putAllFields(command).build()).`when`(servo).doCommand(anyMap())
val response = client.doCommand(command)
verify(servo).doCommand(command)
assertEquals(command, response.fieldsMap)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,15 @@ class ServoRPCServiceTest {
verify(servo).getGeometries(Optional.of(Struct.getDefaultInstance()))
}

@Test
fun doCommand(){
val command =
Struct.newBuilder().putAllFields(mapOf("foo" to Value.newBuilder().setStringValue("bar").build())).build()
doReturn(command).`when`(servo).doCommand(anyMap())
val request = Common.DoCommandRequest.newBuilder().setName(servo.name.name).setCommand(command).build()
val response = client.doCommand(request)
verify(servo).doCommand(command.fieldsMap)
assertEquals(command, response.result)
}

}

0 comments on commit 4ea7699

Please sign in to comment.