aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceException.java1
-rw-r--r--controlloop/common/msb/src/test/java/org/onap/policy/msb/client/MSBServiceManagerTest.java225
2 files changed, 113 insertions, 113 deletions
diff --git a/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceException.java b/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceException.java
index f5bbdb5f2..2342e1695 100644
--- a/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceException.java
+++ b/controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MSBServiceException.java
@@ -15,6 +15,7 @@
package org.onap.policy.msb.client;
public class MSBServiceException extends Exception {
+ private static final long serialVersionUID = 5227416822833497317L;
public MSBServiceException() {
super();
diff --git a/controlloop/common/msb/src/test/java/org/onap/policy/msb/client/MSBServiceManagerTest.java b/controlloop/common/msb/src/test/java/org/onap/policy/msb/client/MSBServiceManagerTest.java
index 771bb4921..4edb168f0 100644
--- a/controlloop/common/msb/src/test/java/org/onap/policy/msb/client/MSBServiceManagerTest.java
+++ b/controlloop/common/msb/src/test/java/org/onap/policy/msb/client/MSBServiceManagerTest.java
@@ -38,119 +38,118 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
public class MSBServiceManagerTest {
- @Mock
- private MSBServiceClient msbClient;
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
+ @Mock
+ private MSBServiceClient msbClient;
- private MSBServiceManager msbManager;
-
- public MSBServiceManagerTest(){}
-
- @BeforeClass
- public static void setUpClass(){}
-
- @AfterClass
- public static void tearDownClass(){}
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- msbManager = new MSBServiceManager(msbClient);
- }
-
- @After
- public void tearDown() {
- }
-
- @Test
- public void testByActor () throws RouteException,UnknownHostException {
- MicroServiceFullInfo serviceInfo = this.build(InetAddress.getLocalHost().getHostAddress(),"8843");
- when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenReturn(serviceInfo);
- Node node = msbManager.getNode("AAI");
- assertNotNull(node);
- serviceInfo = this.build(InetAddress.getLocalHost().getHostAddress(),"8840");
- when(msbClient.queryMicroServiceInfo("so","v2")).thenReturn(serviceInfo);
- node = msbManager.getNode("SO");
- assertNotNull(node);
-
- serviceInfo = this.build(InetAddress.getLocalHost().getHostAddress(),"8082");
- when(msbClient.queryMicroServiceInfo("nfvo-nslcm","v1")).thenReturn(serviceInfo);
- node = msbManager.getNode("VFC");
- assertNotNull(node);
-
- }
-
- @Test
- public void testByActor_when_actorNotExist_returnNull () throws RouteException,UnknownHostException {
- MicroServiceFullInfo serviceInfo = this.build(InetAddress.getLocalHost().getHostAddress(),"8843");
- when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenReturn(serviceInfo);
- Node node = msbManager.getNode("DDD");
- assertNull(node);
- }
-
- @Test
- public void testByServiceNameAndVersion () throws RouteException,UnknownHostException {
- MicroServiceFullInfo serviceInfo = this.build(InetAddress.getLocalHost().getHostAddress(),"8843");
- when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenReturn(serviceInfo);
- Node node = msbManager.getNode("aai-search","v11");
- assertNotNull(node);
- }
-
- @Test
- public void testByServiceNameAndVersion_when_serice_notRegistedToMSB () throws RouteException,UnknownHostException {
- MicroServiceFullInfo serviceInfo = this.build(InetAddress.getLocalHost().getHostAddress(),"8843");
- when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenThrow(new RouteException());
- Node node = msbManager.getNode("aai-search","v11");
- assertNotNull(node);
- assertTrue(node.getName() == "aai-search");
- assertTrue(node.getIp() == null);
- assertTrue(node.getPort() == null);
- }
-
- @Test
- public void testReadMsbPolicyProperites_noPropertyFileSpecifed_throwsException() throws MSBServiceException, IOException {
- expectedException.expect(MSBServiceException.class);
- expectedException.expectMessage("No msb.policy.properties specified.");
- System.clearProperty("msb.policy.properties");
- msbManager = new MSBServiceManager();
- }
-
- @Test
- public void testReadMsbPolicyProperites_propertyFileDoesNotExist_throwsException() throws MSBServiceException, IOException {
- expectedException.expect(MSBServiceException.class);
- expectedException.expectMessage("No msb.policy.properties specified.");
- System.setProperty("msb.policy.properties", "nonExistingPropertyFile.txt");
- msbManager = new MSBServiceManager();
- System.clearProperty("msb.policy.properties");
- }
-
- @Test
- public void testReadMsbPolicyProperites_propertyFileExists() throws MSBServiceException, IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
- System.setProperty("msb.policy.properties", "src/test/resources/msbPropertyFile.properties");
- msbManager = new MSBServiceManager();
- System.clearProperty("msb.policy.properties");
-
- Field factoryField = msbManager.getClass().getDeclaredField("factory");
- factoryField.setAccessible(true);
- MSBServiceFactory msbServiceFactory = (MSBServiceFactory) factoryField.get(msbManager);
-
- Field msbClientField = msbServiceFactory.getClass().getDeclaredField("msbClient");
- msbClientField.setAccessible(true);
- MSBServiceClient msbClient = (MSBServiceClient) msbClientField.get(msbServiceFactory);
- assertEquals("127.0.0.1:20", msbClient.getMsbSvrAddress());
- }
-
- public static MicroServiceFullInfo build(String ip,String port){
- MicroServiceFullInfo serviceInfo = new MicroServiceFullInfo();
- Set<NodeInfo> nodes = new HashSet<NodeInfo>();
- NodeInfo node= new NodeInfo();
- node.setPort(port);
- node.setIp(ip);
- nodes.add(node);
- serviceInfo.setNodes(nodes);
- return serviceInfo;
- }
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+ private MSBServiceManager msbManager;
+
+ public MSBServiceManagerTest(){}
+
+ @BeforeClass
+ public static void setUpClass(){}
+
+ @AfterClass
+ public static void tearDownClass(){}
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ msbManager = new MSBServiceManager(msbClient);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testByActor () throws RouteException,UnknownHostException {
+ MicroServiceFullInfo serviceInfo = MSBServiceManagerTest.build(InetAddress.getLocalHost().getHostAddress(),"8843");
+ when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenReturn(serviceInfo);
+ Node node = msbManager.getNode("AAI");
+ assertNotNull(node);
+ serviceInfo = MSBServiceManagerTest.build(InetAddress.getLocalHost().getHostAddress(),"8840");
+ when(msbClient.queryMicroServiceInfo("so","v2")).thenReturn(serviceInfo);
+ node = msbManager.getNode("SO");
+ assertNotNull(node);
+
+ serviceInfo = MSBServiceManagerTest.build(InetAddress.getLocalHost().getHostAddress(),"8082");
+ when(msbClient.queryMicroServiceInfo("nfvo-nslcm","v1")).thenReturn(serviceInfo);
+ node = msbManager.getNode("VFC");
+ assertNotNull(node);
+
+ }
+
+ @Test
+ public void testByActor_when_actorNotExist_returnNull () throws RouteException,UnknownHostException {
+ MicroServiceFullInfo serviceInfo = MSBServiceManagerTest.build(InetAddress.getLocalHost().getHostAddress(),"8843");
+ when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenReturn(serviceInfo);
+ Node node = msbManager.getNode("DDD");
+ assertNull(node);
+ }
+
+ @Test
+ public void testByServiceNameAndVersion () throws RouteException,UnknownHostException {
+ MicroServiceFullInfo serviceInfo = MSBServiceManagerTest.build(InetAddress.getLocalHost().getHostAddress(),"8843");
+ when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenReturn(serviceInfo);
+ Node node = msbManager.getNode("aai-search","v11");
+ assertNotNull(node);
+ }
+
+ @Test
+ public void testByServiceNameAndVersion_when_serice_notRegistedToMSB () throws RouteException,UnknownHostException {
+ MSBServiceManagerTest.build(InetAddress.getLocalHost().getHostAddress(),"8843");
+ when(msbClient.queryMicroServiceInfo("aai-search","v11")).thenThrow(new RouteException());
+ Node node = msbManager.getNode("aai-search","v11");
+ assertNotNull(node);
+ assertTrue(node.getName() == "aai-search");
+ assertTrue(node.getIp() == null);
+ assertTrue(node.getPort() == null);
+ }
+
+ @Test
+ public void testReadMsbPolicyProperites_noPropertyFileSpecifed_throwsException() throws MSBServiceException, IOException {
+ expectedException.expect(MSBServiceException.class);
+ expectedException.expectMessage("No msb.policy.properties specified.");
+ System.clearProperty("msb.policy.properties");
+ msbManager = new MSBServiceManager();
+ }
+
+ @Test
+ public void testReadMsbPolicyProperites_propertyFileDoesNotExist_throwsException() throws MSBServiceException, IOException {
+ expectedException.expect(MSBServiceException.class);
+ expectedException.expectMessage("No msb.policy.properties specified.");
+ System.setProperty("msb.policy.properties", "nonExistingPropertyFile.txt");
+ msbManager = new MSBServiceManager();
+ System.clearProperty("msb.policy.properties");
+ }
+
+ @Test
+ public void testReadMsbPolicyProperites_propertyFileExists() throws MSBServiceException, IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ System.setProperty("msb.policy.properties", "src/test/resources/msbPropertyFile.properties");
+ msbManager = new MSBServiceManager();
+ System.clearProperty("msb.policy.properties");
+
+ Field factoryField = msbManager.getClass().getDeclaredField("factory");
+ factoryField.setAccessible(true);
+ MSBServiceFactory msbServiceFactory = (MSBServiceFactory) factoryField.get(msbManager);
+
+ Field msbClientField = msbServiceFactory.getClass().getDeclaredField("msbClient");
+ msbClientField.setAccessible(true);
+ MSBServiceClient msbClient = (MSBServiceClient) msbClientField.get(msbServiceFactory);
+ assertEquals("127.0.0.1:20", msbClient.getMsbSvrAddress());
+ }
+
+ public static MicroServiceFullInfo build(String ip,String port){
+ MicroServiceFullInfo serviceInfo = new MicroServiceFullInfo();
+ Set<NodeInfo> nodes = new HashSet<NodeInfo>();
+ NodeInfo node= new NodeInfo();
+ node.setPort(port);
+ node.setIp(ip);
+ nodes.add(node);
+ serviceInfo.setNodes(nodes);
+ return serviceInfo;
+ }
}