Merge "BUG-1690: catch wildcard InstanceIdentifiers"
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / ActorSystemFactoryTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.remote.rpc;
10
11
12 import akka.actor.ActorSystem;
13 import com.typesafe.config.ConfigFactory;
14 import junit.framework.Assert;
15 import org.junit.After;
16 import org.junit.Test;
17 import org.opendaylight.controller.remote.rpc.utils.AkkaConfigurationReader;
18 import org.osgi.framework.Bundle;
19 import org.osgi.framework.BundleContext;
20
21 import static org.junit.Assert.fail;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24
25 public class ActorSystemFactoryTest {
26   ActorSystem system = null;
27
28   @Test
29   public void testActorSystemCreation(){
30     BundleContext context = mock(BundleContext.class);
31     when(context.getBundle()).thenReturn(mock(Bundle.class));
32
33     AkkaConfigurationReader reader = mock(AkkaConfigurationReader.class);
34     when(reader.read()).thenReturn(ConfigFactory.load());
35
36     ActorSystemFactory.createInstance(context, reader);
37     system = ActorSystemFactory.getInstance();
38     Assert.assertNotNull(system);
39     // Check illegal state exception
40
41     try {
42       ActorSystemFactory.createInstance(context, reader);
43       fail("Illegal State exception should be thrown, while creating actor system second time");
44     } catch (IllegalStateException e) {
45     }
46   }
47
48   @After
49   public void cleanup() throws InterruptedException {
50     if(system != null) {
51       system.shutdown();
52     }
53   }
54 }