Search in sources :

Example 1 with DetachedMockFactory

use of spock.mock.DetachedMockFactory in project micronaut-core by micronaut-projects.

the class HttpRequestTest method testForEach2.

public void testForEach2() {
    final DefaultFullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "/test");
    nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML);
    HttpRequest<?> request = new NettyHttpRequest(nettyRequest, new DetachedMockFactory().Mock(ChannelHandlerContext.class), ConversionService.SHARED, new HttpServerConfiguration());
    final HttpHeaders headers = request.getHeaders();
    headers.forEach((name, values) -> {
        assertEquals(HttpHeaders.CONTENT_TYPE, name);
        assertEquals(2, values.size());
        assertTrue(values.contains(MediaType.APPLICATION_JSON));
        assertTrue(values.contains(MediaType.APPLICATION_XML));
    });
    AtomicInteger integer = new AtomicInteger(0);
    headers.forEachValue((s, s2) -> integer.incrementAndGet());
    assertEquals(2, integer.get());
}
Also used : HttpHeaders(io.micronaut.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpServerConfiguration(io.micronaut.http.server.HttpServerConfiguration) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) NettyHttpRequest(io.micronaut.http.server.netty.NettyHttpRequest) DetachedMockFactory(spock.mock.DetachedMockFactory)

Example 2 with DetachedMockFactory

use of spock.mock.DetachedMockFactory in project conductor by Netflix.

the class MockQueueDAOModule method configureQueueDAO.

@Override
public void configureQueueDAO() {
    DetachedMockFactory detachedMockFactory = new DetachedMockFactory();
    JedisCommands jedisMock = new JedisMock();
    ShardSupplier shardSupplier = new ShardSupplier() {

        @Override
        public Set<String> getQueueShards() {
            return new HashSet<>(Collections.singletonList("a"));
        }

        @Override
        public String getCurrentShard() {
            return "a";
        }

        @Override
        public String getShardForHost(Host host) {
            return "a";
        }
    };
    RedisQueues redisQueues = new RedisQueues(jedisMock, jedisMock, "mockedQueues", shardSupplier, 60000, 120000);
    DynoQueueDAO dynoQueueDAO = new DynoQueueDAO(redisQueues);
    bind(QueueDAO.class).toInstance(detachedMockFactory.Spy(dynoQueueDAO));
    install(new WorkflowExecutorModule());
}
Also used : DynoQueueDAO(com.netflix.conductor.dao.dynomite.queue.DynoQueueDAO) QueueDAO(com.netflix.conductor.dao.QueueDAO) JedisCommands(redis.clients.jedis.commands.JedisCommands) DynoQueueDAO(com.netflix.conductor.dao.dynomite.queue.DynoQueueDAO) WorkflowExecutorModule(com.netflix.conductor.core.execution.WorkflowExecutorModule) JedisMock(com.netflix.conductor.jedis.JedisMock) Host(com.netflix.dyno.connectionpool.Host) RedisQueues(com.netflix.dyno.queues.redis.RedisQueues) DetachedMockFactory(spock.mock.DetachedMockFactory) ShardSupplier(com.netflix.dyno.queues.ShardSupplier) HashSet(java.util.HashSet)

Example 3 with DetachedMockFactory

use of spock.mock.DetachedMockFactory in project spock by spockframework.

the class SpockMockFactoryBean method getObject.

@Override
@SuppressWarnings("unchecked")
public T getObject() throws Exception {
    if (instance == null) {
        MockNature nature = MockNature.valueOf(mockNature.toUpperCase(Locale.ROOT));
        instance = new DetachedMockFactory().createMock(name, targetClass, nature, Collections.<String, Object>emptyMap());
    }
    return instance;
}
Also used : MockNature(org.spockframework.mock.MockNature) DetachedMockFactory(spock.mock.DetachedMockFactory)

Example 4 with DetachedMockFactory

use of spock.mock.DetachedMockFactory in project micronaut-core by micronaut-projects.

the class HttpRequestTest method testForEach.

public void testForEach() {
    final DefaultFullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "/test");
    nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    HttpRequest<?> request = new NettyHttpRequest(nettyRequest, new DetachedMockFactory().Mock(ChannelHandlerContext.class), ConversionService.SHARED, new HttpServerConfiguration());
    final HttpHeaders headers = request.getHeaders();
    headers.forEach((name, values) -> {
        assertEquals(HttpHeaders.CONTENT_TYPE, name);
        assertEquals(1, values.size());
        assertEquals(MediaType.APPLICATION_JSON, values.iterator().next());
    });
}
Also used : HttpHeaders(io.micronaut.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpServerConfiguration(io.micronaut.http.server.HttpServerConfiguration) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) NettyHttpRequest(io.micronaut.http.server.netty.NettyHttpRequest) DetachedMockFactory(spock.mock.DetachedMockFactory)

Aggregations

DetachedMockFactory (spock.mock.DetachedMockFactory)4 HttpHeaders (io.micronaut.http.HttpHeaders)2 HttpServerConfiguration (io.micronaut.http.server.HttpServerConfiguration)2 NettyHttpRequest (io.micronaut.http.server.netty.NettyHttpRequest)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 WorkflowExecutorModule (com.netflix.conductor.core.execution.WorkflowExecutorModule)1 QueueDAO (com.netflix.conductor.dao.QueueDAO)1 DynoQueueDAO (com.netflix.conductor.dao.dynomite.queue.DynoQueueDAO)1 JedisMock (com.netflix.conductor.jedis.JedisMock)1 Host (com.netflix.dyno.connectionpool.Host)1 ShardSupplier (com.netflix.dyno.queues.ShardSupplier)1 RedisQueues (com.netflix.dyno.queues.redis.RedisQueues)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MockNature (org.spockframework.mock.MockNature)1 JedisCommands (redis.clients.jedis.commands.JedisCommands)1