/hazelcast-spring/src/test/java/com/hazelcast/spring/TestBeansApplicationContext.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 70 lines · 43 code · 12 blank · 15 comment · 0 complexity · 8b9f8b694d2ba0214a2790be8d8c7d65 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.spring;
  17. import com.hazelcast.client.HazelcastClient;
  18. import com.hazelcast.core.Hazelcast;
  19. import com.hazelcast.core.HazelcastInstance;
  20. import org.junit.AfterClass;
  21. import org.junit.Assert;
  22. import org.junit.BeforeClass;
  23. import org.junit.Test;
  24. import org.junit.runner.RunWith;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.context.ApplicationContext;
  27. import org.springframework.test.context.ContextConfiguration;
  28. @RunWith(CustomSpringJUnit4ClassRunner.class)
  29. @ContextConfiguration(locations = {"beans-applicationContext-hazelcast.xml"})
  30. public class TestBeansApplicationContext {
  31. @BeforeClass
  32. @AfterClass
  33. public static void start() {
  34. HazelcastClient.shutdownAll();
  35. Hazelcast.shutdownAll();
  36. }
  37. @Autowired
  38. private ApplicationContext context;
  39. @Test
  40. public void testLazy() {
  41. Assert.assertTrue(Hazelcast.getAllHazelcastInstances().isEmpty());
  42. Assert.assertTrue(HazelcastClient.getAllHazelcastClients().isEmpty());
  43. context.getBean("map2");
  44. Assert.assertEquals(1, Hazelcast.getAllHazelcastInstances().size());
  45. Assert.assertEquals(1, HazelcastClient.getAllHazelcastClients().size());
  46. HazelcastInstance hazelcast = Hazelcast.getAllHazelcastInstances().iterator().next();
  47. Assert.assertEquals(2, hazelcast.getInstances().size());
  48. }
  49. @Test
  50. public void testScope() {
  51. context.getBean("client");
  52. context.getBean("client");
  53. Assert.assertEquals(3, HazelcastClient.getAllHazelcastClients().size());
  54. HazelcastInstance instance = (HazelcastInstance) context.getBean("instance");
  55. Assert.assertEquals(1, Hazelcast.getAllHazelcastInstances().size());
  56. Assert.assertEquals(instance, Hazelcast.getAllHazelcastInstances().iterator().next());
  57. }
  58. }