PageRenderTime 19ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast-client/src/test/java/com/hazelcast/client/CollectionClientProxyTest.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 92 lines | 63 code | 13 blank | 16 comment | 0 complexity | 65aa0c382f8b3ac2e9ab7ac670c9b553 MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.client;
18
19import com.hazelcast.client.impl.ItemListenerManager;
20import com.hazelcast.client.impl.ListenerManager;
21import com.hazelcast.core.ItemEvent;
22import com.hazelcast.core.ItemListener;
23import com.hazelcast.impl.ClusterOperation;
24import org.hamcrest.BaseMatcher;
25import org.hamcrest.Description;
26import org.junit.Ignore;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29
30import java.util.HashMap;
31
32import static org.mockito.Matchers.argThat;
33import static org.mockito.Mockito.*;
34
35@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
36public class CollectionClientProxyTest {
37    @Test
38    public void testIterator() throws Exception {
39    }
40
41    @Ignore
42    @Test
43    public void testAddItemListenerIncludeValue() throws Exception {
44        Boolean includeValue = true;
45        HazelcastClient client = mock(HazelcastClient.class);
46        ListenerManager listenerManager = mock(ListenerManager.class);
47        ItemListenerManager itemListenerManager = mock(ItemListenerManager.class);
48        when(listenerManager.getItemListenerManager()).thenReturn(itemListenerManager);
49        when(client.getListenerManager()).thenReturn(listenerManager);
50        when(client.getOutRunnable()).thenReturn(new OutRunnable(client, new HashMap(), new PacketWriter()));
51        String name = "def";
52        ProxyHelper proxyHelper = mock(ProxyHelper.class);
53        when(proxyHelper.getHazelcastClient()).thenReturn(client);
54        Packet request = new Packet();
55        request.setName(name);
56        request.setOperation(ClusterOperation.ADD_LISTENER);
57        when(proxyHelper.createCall(request)).thenReturn(new Call(1L, request));
58        when(proxyHelper.createRequestPacket(ClusterOperation.ADD_LISTENER, null, null)).thenReturn(request);
59        CollectionClientProxy proxy = new SetClientProxy(proxyHelper, name);
60        ItemListener listener = new ItemListener() {
61
62            public void itemAdded(ItemEvent itemEvent) {
63            }
64
65            public void itemRemoved(ItemEvent itemEvent) {
66            }
67        };
68        proxy.addItemListener(listener, includeValue);
69        //verify(listenerManager).addListenerCall(argThat(new CallMatcher()));
70        verify(itemListenerManager).registerListener(name, listener, includeValue);
71        verify(proxyHelper).doCall(argThat(new CallMatcher()));
72    }
73
74    class CallMatcher extends BaseMatcher<Call> {
75        public void describeTo(Description description) {
76        }
77
78        public boolean matches(Object o) {
79            return (o instanceof Call);
80        }
81    }
82
83    ;
84
85    @Test
86    public void testRemoveItemListener() throws Exception {
87    }
88
89    @Test
90    public void testSize() throws Exception {
91    }
92}