/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. package com.hazelcast.client;
  17. import com.hazelcast.client.impl.ItemListenerManager;
  18. import com.hazelcast.client.impl.ListenerManager;
  19. import com.hazelcast.core.ItemEvent;
  20. import com.hazelcast.core.ItemListener;
  21. import com.hazelcast.impl.ClusterOperation;
  22. import org.hamcrest.BaseMatcher;
  23. import org.hamcrest.Description;
  24. import org.junit.Ignore;
  25. import org.junit.Test;
  26. import org.junit.runner.RunWith;
  27. import java.util.HashMap;
  28. import static org.mockito.Matchers.argThat;
  29. import static org.mockito.Mockito.*;
  30. @RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
  31. public class CollectionClientProxyTest {
  32. @Test
  33. public void testIterator() throws Exception {
  34. }
  35. @Ignore
  36. @Test
  37. public void testAddItemListenerIncludeValue() throws Exception {
  38. Boolean includeValue = true;
  39. HazelcastClient client = mock(HazelcastClient.class);
  40. ListenerManager listenerManager = mock(ListenerManager.class);
  41. ItemListenerManager itemListenerManager = mock(ItemListenerManager.class);
  42. when(listenerManager.getItemListenerManager()).thenReturn(itemListenerManager);
  43. when(client.getListenerManager()).thenReturn(listenerManager);
  44. when(client.getOutRunnable()).thenReturn(new OutRunnable(client, new HashMap(), new PacketWriter()));
  45. String name = "def";
  46. ProxyHelper proxyHelper = mock(ProxyHelper.class);
  47. when(proxyHelper.getHazelcastClient()).thenReturn(client);
  48. Packet request = new Packet();
  49. request.setName(name);
  50. request.setOperation(ClusterOperation.ADD_LISTENER);
  51. when(proxyHelper.createCall(request)).thenReturn(new Call(1L, request));
  52. when(proxyHelper.createRequestPacket(ClusterOperation.ADD_LISTENER, null, null)).thenReturn(request);
  53. CollectionClientProxy proxy = new SetClientProxy(proxyHelper, name);
  54. ItemListener listener = new ItemListener() {
  55. public void itemAdded(ItemEvent itemEvent) {
  56. }
  57. public void itemRemoved(ItemEvent itemEvent) {
  58. }
  59. };
  60. proxy.addItemListener(listener, includeValue);
  61. //verify(listenerManager).addListenerCall(argThat(new CallMatcher()));
  62. verify(itemListenerManager).registerListener(name, listener, includeValue);
  63. verify(proxyHelper).doCall(argThat(new CallMatcher()));
  64. }
  65. class CallMatcher extends BaseMatcher<Call> {
  66. public void describeTo(Description description) {
  67. }
  68. public boolean matches(Object o) {
  69. return (o instanceof Call);
  70. }
  71. }
  72. ;
  73. @Test
  74. public void testRemoveItemListener() throws Exception {
  75. }
  76. @Test
  77. public void testSize() throws Exception {
  78. }
  79. }