Search in sources :

Example 21 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestLoadbalanceHandler method testLoadbalanceHandlerHandleWithLoadBalancerHandler.

@Test
public void testLoadbalanceHandlerHandleWithLoadBalancerHandler() throws Exception {
    boolean status = true;
    new MockUp<LoadbalanceHandler>() {

        @Mock
        private LoadBalancer createLoadBalancer(String appId, String microserviceName, String microserviceVersionRule, String transportName) {
            return lb;
        }
    };
    LoadbalanceHandler lh = new LoadbalanceHandler();
    Invocation invocation = Mockito.mock(Invocation.class);
    Mockito.when(invocation.getConfigTransportName()).thenReturn("baadshah");
    Mockito.when(invocation.getMicroserviceVersionRule()).thenReturn("VERSION_RULE_LATEST");
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(invocation.getMicroserviceName()).thenReturn("test");
    new MockUp<Configuration>() {

        @Mock
        public boolean isRetryEnabled(String microservice) {
            return true;
        }
    };
    SyncResponseExecutor orginExecutor = new SyncResponseExecutor();
    Mockito.when(invocation.getResponseExecutor()).thenReturn(orginExecutor);
    List<ExecutionListener<Invocation, Response>> listeners = new ArrayList<>(0);
    @SuppressWarnings("unchecked") ExecutionListener<Invocation, Response> listener = Mockito.mock(ExecutionListener.class);
    ExecutionListener<Invocation, Response> e = null;
    listeners.add(e);
    listeners.add(listener);
    try {
        lh.handle(invocation, asyncResp);
    } catch (Exception ex) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) SyncResponseExecutor(io.servicecomb.core.provider.consumer.SyncResponseExecutor) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) ExecutionListener(com.netflix.loadbalancer.reactive.ExecutionListener) AsyncResponse(io.servicecomb.core.AsyncResponse) Response(io.servicecomb.core.Response) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 22 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestTcp method testTcpClient.

@Test
public void testTcpClient() throws Exception {
    NetClient oNetClient = new NetClient() {

        @Override
        public boolean isMetricsEnabled() {
            // TODO Auto-generated method stub
            return true;
        }

        @Override
        public NetClient connect(int port, String host, Handler<AsyncResult<NetSocket>> connectHandler) {
            return Mockito.mock(NetClient.class);
        }

        @Override
        public void close() {
        // TODO Auto-generated method stub
        }
    };
    TcpClient oTcpClient = new TcpClient(Mockito.mock(Context.class), oNetClient, "highway://127.2.0.1:8080", new TcpClientConfig());
    oTcpClient.checkTimeout();
    oTcpClient.send(new TcpOutputStream(), 123, Mockito.mock(TcpResonseCallback.class));
    oTcpClient.send(new TcpOutputStream(), 123, Mockito.mock(TcpResonseCallback.class));
    Assert.assertNotEquals(null, oTcpClient.getContext());
    new MockUp<TcpClientPool>() {

        @Mock
        protected void startCheckTimeout(TcpClientConfig clientConfig, Context context) {
        }
    };
    TcpClientConfig config = new TcpClientConfig();
    TcpClientPool oClientPool = new TcpClientPool(config, Vertx.vertx().getOrCreateContext(), oNetClient);
    oClientPool.send("highway://152.2.2.3:8080", new TcpOutputStream(), Mockito.mock(TcpResonseCallback.class));
    oClientPool.send("highway://152.2.2.3:8080", new TcpOutputStream(), Mockito.mock(TcpResonseCallback.class));
    Assert.assertNotNull(oClientPool);
    TcpRequest oTcpRequest = new TcpRequest(1234, Mockito.mock(TcpResonseCallback.class));
    oTcpRequest.isTimeout();
    oTcpRequest.onReply(Buffer.buffer(), Buffer.buffer(("test").getBytes()));
    oTcpRequest.onSendError(new Throwable("test Errorsss"));
    Assert.assertNotNull(oTcpRequest);
    TcpClientVerticle oTcpClientVerticle = new TcpClientVerticle();
    oTcpClientVerticle.init(Vertx.vertx(), Vertx.vertx().getOrCreateContext());
    oTcpClientVerticle.createClientPool();
    oTcpClientVerticle.createClientPool();
    Assert.assertNotNull(oTcpClientVerticle.getVertx());
    NetSocket socket = Mockito.mock(NetSocket.class);
    Throwable e = Mockito.mock(Throwable.class);
    Buffer hBuffer = Mockito.mock(Buffer.class);
    Buffer bBuffer = Mockito.mock(Buffer.class);
    Deencapsulation.invoke(oTcpClient, "connect");
    Deencapsulation.invoke(oTcpClient, "onConnectSuccess", socket);
    Mockito.when(socket.localAddress()).thenReturn(new SocketAddressImpl(0, "127.0.0.1"));
    Deencapsulation.setField(oTcpClient, "netSocket", socket);
    Deencapsulation.invoke(oTcpClient, "onDisconnected", e);
    Deencapsulation.invoke(oTcpClient, "tryLogin");
    Deencapsulation.invoke(oTcpClient, "onLoginSuccess");
    Deencapsulation.invoke(oTcpClient, "onConnectFailed", e);
    long l = 10;
    Deencapsulation.invoke(oTcpClient, "onReply", l, hBuffer, bBuffer);
    oTcpClient.checkTimeout();
    Assert.assertNotNull(oTcpClient);
}
Also used : NetSocket(io.vertx.core.net.NetSocket) Context(io.vertx.core.Context) Buffer(io.vertx.core.buffer.Buffer) TcpClientVerticle(io.servicecomb.foundation.vertx.client.tcp.TcpClientVerticle) TcpClientConfig(io.servicecomb.foundation.vertx.client.tcp.TcpClientConfig) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) TcpClientPool(io.servicecomb.foundation.vertx.client.tcp.TcpClientPool) TcpResonseCallback(io.servicecomb.foundation.vertx.client.tcp.TcpResonseCallback) NetClient(io.vertx.core.net.NetClient) TcpRequest(io.servicecomb.foundation.vertx.client.tcp.TcpRequest) TcpClient(io.servicecomb.foundation.vertx.client.tcp.TcpClient) SocketAddressImpl(io.vertx.core.net.impl.SocketAddressImpl) TcpOutputStream(io.servicecomb.foundation.vertx.tcp.TcpOutputStream) Test(org.junit.Test)

Example 23 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestVertxTLSBuilder method testbuildHttpServerOptionsRequest.

@Test
public void testbuildHttpServerOptionsRequest() {
    SSLOption option = SSLOption.buildFromYaml("rest.provider");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpServerOptions serverOptions = new HttpServerOptions();
    new MockUp<SSLOption>() {

        @Mock
        public boolean isAuthPeer() {
            return false;
        }
    };
    VertxTLSBuilder.buildNetServerOptions(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.getClientAuth(), ClientAuth.REQUEST);
}
Also used : HttpServerOptions(io.vertx.core.http.HttpServerOptions) MockUp(mockit.MockUp) SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom) Test(org.junit.Test)

Example 24 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestParamSerializer method testSerialize.

@Test
public void testSerialize() {
    boolean status = true;
    Assert.assertNotNull(paramSerializer);
    String[] stringArray = new String[1];
    stringArray[0] = "abc";
    ProtobufGenerator obj = null;
    try {
        obj = new ProtobufGenerator(Mockito.mock(IOContext.class), 2, Mockito.mock(ObjectCodec.class), Mockito.mock(OutputStream.class));
    } catch (IOException exce) {
    }
    Assert.assertNotNull(obj);
    new MockUp<ProtobufGenerator>() {

        @Mock
        public void writeStartObject() throws IOException {
        }

        ProtobufSchema protobufSchema = new ProtobufSchema(null, null);

        @Mock
        public ProtobufSchema getSchema() {
            return protobufSchema;
        }
    };
    ProtobufMessage protobufMessage = new ProtobufMessage(null, null);
    new MockUp<ProtobufSchema>() {

        @Mock
        public ProtobufMessage getRootType() {
            return protobufMessage;
        }
    };
    List<ProtobufField> listProtobufField = new ArrayList<ProtobufField>();
    listProtobufField.add(Mockito.mock(ProtobufField.class));
    new MockUp<ProtobufMessage>() {

        @Mock
        public Iterable<ProtobufField> fields() {
            return listProtobufField;
        }
    };
    new MockUp<JsonGenerator>() {

        @Mock
        public void writeObjectField(String fieldName, Object pojo) throws IOException {
        }
    };
    new MockUp<ProtobufGenerator>() {

        @Mock
        public void writeEndObject() throws IOException {
        }
    };
    try {
        paramSerializer.serialize(stringArray, obj, Mockito.mock(SerializerProvider.class));
    } catch (JsonProcessingException e) {
        status = false;
    } catch (IOException e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : ArrayList(java.util.ArrayList) ProtobufSchema(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema) MockUp(mockit.MockUp) IOException(java.io.IOException) ProtobufMessage(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufMessage) ProtobufGenerator(com.fasterxml.jackson.dataformat.protobuf.ProtobufGenerator) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ProtobufField(com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufField) Test(org.junit.Test)

Example 25 with MockUp

use of mockit.MockUp in project java-chassis by ServiceComb.

the class TestIpPortManager method testCreateServiceRegistryCacheWithInstanceCache.

@Test
public void testCreateServiceRegistryCacheWithInstanceCache() {
    boolean validAssert = true;
    List<MicroserviceInstance> list = new ArrayList<MicroserviceInstance>();
    MicroserviceInstance e1 = new MicroserviceInstance();
    list.add(e1);
    new MockUp<RegistryUtils>() {

        @Mock
        public List<MicroserviceInstance> findServiceInstance(String appId, String serviceName, String versionRule) {
            return list;
        }
    };
    Microservice microservice = new Microservice();
    new MockUp<RegistryUtils>() {

        @Mock
        private Microservice createMicroserviceFromDefinition() {
            return microservice;
        }
    };
    try {
        Deencapsulation.setField(manager, "instanceCache", Mockito.mock(InstanceCache.class));
        manager.createServiceRegistryCache();
        Assert.assertNotNull(manager.get());
        Assert.assertNull(manager.next());
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertTrue(validAssert);
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) ArrayList(java.util.ArrayList) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) InstanceCache(io.servicecomb.serviceregistry.cache.InstanceCache) MockUp(mockit.MockUp) Test(org.junit.Test)

Aggregations

MockUp (mockit.MockUp)208 Test (org.junit.Test)189 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)80 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)78 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)77 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)28 ArrayList (java.util.ArrayList)23 Encoding (org.apache.carbondata.core.metadata.encoder.Encoding)20 IOException (java.io.IOException)18 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)10 Configuration (org.apache.hadoop.conf.Configuration)10 FileStatus (org.apache.hadoop.fs.FileStatus)10 Path (org.apache.hadoop.fs.Path)10 Invocation (io.servicecomb.core.Invocation)9 OperationMeta (io.servicecomb.core.definition.OperationMeta)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 Timestamp (java.sql.Timestamp)8 DateFormat (java.text.DateFormat)8 ParseException (java.text.ParseException)8 SimpleDateFormat (java.text.SimpleDateFormat)8