PageRenderTime 44ms CodeModel.GetById 27ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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