aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-02-09 15:08:42 +0000
committerGerrit Code Review <gerrit@onap.org>2018-02-09 15:08:42 +0000
commit03c44b6534d3e45ac5fac11be71bf120da752aa4 (patch)
tree5307fd05e3a5c9a67e15b19962bfe4291d991b2b /controlloop/common
parentd536517dd5d45abeb037eb3900759771d97b2418 (diff)
parent23fca0124dc61ff67cae2e11171f0dcfc8995b1e (diff)
Merge "Remove Technical Debt from MSB code"
Diffstat (limited to 'controlloop/common')
-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;
+ }
}