use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.
the class TestVertxHttpMethod method testDoMethod.
@Test
public void testDoMethod(@Mocked HttpClient httpClient) throws Exception {
Context context = new MockUp<Context>() {
@Mock
public void runOnContext(Handler<Void> action) {
action.handle(null);
}
}.getMockInstance();
HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
Endpoint endpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
Mockito.when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
Mockito.when(request.exceptionHandler(Mockito.any())).then(answer -> null);
this.doMethod(httpClientWithContext, invocation, asyncResp);
Assert.assertTrue(true);
}
use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.
the class TestGrpcTransport method testSend.
@Test
public void testSend() {
boolean status = false;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ipPort);
Mockito.when(ipPort.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ipPort.getPort()).thenReturn(80);
new MockUp<ClientPoolManager<HttpClientWithContext>>() {
@Mock
public HttpClientWithContext findThreadBindClientPool() {
return Mockito.mock(HttpClientWithContext.class);
}
};
try {
transport.send(invocation, asyncResp);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.
the class TestHighwayTransport method commonHighwayMock.
private void commonHighwayMock(Invocation invocation) {
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ep.getPort()).thenReturn(80);
}
use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.
the class AbstractTransport method setListenAddressWithoutSchema.
protected void setListenAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) {
if (addressWithoutSchema != null && pairs != null && !pairs.isEmpty()) {
int idx = addressWithoutSchema.indexOf('?');
if (idx == -1) {
addressWithoutSchema += "?";
} else {
addressWithoutSchema += "&";
}
StringBuilder sb = new StringBuilder();
for (Entry<String, String> entry : pairs.entrySet()) {
sb.append(entry.getKey()).append('=').append(entry.getValue()).append('&');
}
sb.setLength(sb.length() - 1);
addressWithoutSchema += sb.toString();
}
this.endpoint = new Endpoint(this, NetUtils.getRealListenAddress(getName(), addressWithoutSchema));
if (this.endpoint.getEndpoint() != null) {
this.publishEndpoint = new Endpoint(this, RegistryUtils.getPublishAddress(getName(), addressWithoutSchema));
} else {
this.publishEndpoint = null;
}
}
use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.
the class TestRestServerVerticle method testRestServerVerticleWithRouter.
@Test
public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080");
new Expectations() {
{
transport.parseAddress("http://127.0.0.1:8080");
result = endpointObject;
}
};
Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080");
new Expectations() {
{
context.config();
result = jsonObject;
jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
result = endpiont;
}
};
RestServerVerticle server = new RestServerVerticle();
// process stuff done by Expectations
server.init(vertx, context);
server.start(startFuture);
}
Aggregations