Search in sources :

Example 61 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.

the class TestAsyncInvoke method check.

/**
 * Wait for response and check
 */
private <T> void check(CompletableFuture<ResponseEntity<T>> responseEntityCompletableFuture, BiConsumer<ResponseEntity<T>, Throwable> checkLogic) {
    CountDownLatch countDownLatch = new CountDownLatch(1);
    Holder<Boolean> responseChecked = new Holder<>();
    responseEntityCompletableFuture.whenComplete((responseEntity, ex) -> {
        checkLogic.accept(responseEntity, ex);
        responseChecked.value = true;
        countDownLatch.countDown();
    });
    try {
        countDownLatch.await(3000, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        fail("error occurs while waiting for response, " + e.getMessage());
    }
    Assert.assertTrue("response check unfinished!", responseChecked.value);
}
Also used : Holder(org.apache.servicecomb.foundation.common.Holder) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 62 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.

the class TestPartToMultipartFile method transferTo.

@Test
public void transferTo() throws IllegalStateException, IOException {
    File dest = new File("/dest");
    Holder<String> destName = new Holder<>();
    new MockUp<Part>(part) {

        @Mock
        void write(String fileName) throws IOException {
            destName.value = fileName;
        }
    };
    multipartFile.transferTo(dest);
    Assert.assertEquals(dest.getPath(), destName.value);
}
Also used : Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) File(java.io.File) Test(org.junit.Test)

Example 63 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.

the class TestDefaultLogPublisher method init_enabled_default.

@Test
public void init_enabled_default() {
    Holder<Boolean> registered = new Holder<>(false);
    new MockUp<EventBus>(eventBus) {

        @Mock
        void register(Object object) {
            registered.value = true;
        }
    };
    publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    Assert.assertFalse(registered.value);
}
Also used : MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 64 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.

the class TestDefaultLogPublisher method init_enabled_false.

@Test
public void init_enabled_false() {
    Holder<Boolean> registered = new Holder<>();
    new MockUp<EventBus>(eventBus) {

        @Mock
        void register(Object object) {
            registered.value = true;
        }
    };
    ArchaiusUtils.setProperty(DefaultLogPublisher.ENABLED, false);
    publisher.init(globalRegistry, eventBus, new MetricsBootstrapConfig());
    Assert.assertNull(registered.value);
}
Also used : MetricsBootstrapConfig(org.apache.servicecomb.foundation.metrics.MetricsBootstrapConfig) Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 65 with Holder

use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.

the class TestAbstractRestInvocation method invokeFilterHaveResponse.

@Test
public void invokeFilterHaveResponse(@Mocked HttpServerFilter filter) {
    Response response = Response.ok("");
    new Expectations() {

        {
            filter.enabled();
            result = true;
            filter.afterReceiveRequest(invocation, requestEx);
            result = response;
        }
    };
    Holder<Response> result = new Holder<>();
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected void doInvoke() {
            result.value = Response.ok("not run to here");
        }

        @Override
        protected void sendResponseQuietly(Response response) {
            result.value = response;
        }
    };
    initRestInvocation();
    restInvocation.httpServerFilters = Arrays.asList(filter);
    restInvocation.invoke();
    Assert.assertSame(response, result.value);
}
Also used : AbstractHttpServletResponse(org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse) Response(org.apache.servicecomb.swagger.invocation.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Expectations(mockit.Expectations) Holder(org.apache.servicecomb.foundation.common.Holder) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Aggregations

Holder (org.apache.servicecomb.foundation.common.Holder)108 Test (org.junit.Test)88 MockUp (mockit.MockUp)36 AtomicLong (java.util.concurrent.atomic.AtomicLong)28 Invocation (org.apache.servicecomb.core.Invocation)24 Expectations (mockit.Expectations)22 Vertx (io.vertx.core.Vertx)20 List (java.util.List)18 Response (org.apache.servicecomb.swagger.invocation.Response)18 Mock (mockit.Mock)16 HttpServerFilterBaseForTest (org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 SCBEngine (org.apache.servicecomb.core.SCBEngine)14 ExpectedException (org.junit.rules.ExpectedException)14 CountDownLatch (java.util.concurrent.CountDownLatch)12 Status (javax.ws.rs.core.Response.Status)12 Deencapsulation (mockit.Deencapsulation)12 Mocked (mockit.Mocked)12 ConfigUtil (org.apache.servicecomb.config.ConfigUtil)12