aboutsummaryrefslogtreecommitdiffstats
path: root/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java')
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java168
1 files changed, 90 insertions, 78 deletions
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java
index aa5db78..6e7200d 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/service/MicroServiceFullServiceTest.java
@@ -1,21 +1,33 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.service;
-import com.fiftyonred.mock_jedis.MockJedisPool;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -23,31 +35,27 @@ import org.junit.runner.RunWith;
import org.onap.msb.apiroute.api.MicroServiceFullInfo;
import org.onap.msb.apiroute.api.Node;
import org.onap.msb.apiroute.wrapper.dao.RedisAccessWrapper;
-import org.onap.msb.apiroute.wrapper.service.MicroServiceFullService;
import org.onap.msb.apiroute.wrapper.util.JedisUtil;
import org.onap.msb.apiroute.wrapper.util.MicroServiceUtil;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.JedisPoolConfig;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.*;
+import com.fiftyonred.mock_jedis.MockJedisPool;
-import static org.junit.Assert.*;
-import static org.powermock.api.mockito.PowerMockito.when;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({JedisUtil.class,RedisAccessWrapper.class})
-@PowerMockIgnore( {"javax.management.*"})
+@PrepareForTest({JedisUtil.class, RedisAccessWrapper.class})
+@PowerMockIgnore({"javax.management.*"})
public class MicroServiceFullServiceTest {
private static MicroServiceFullService microServiceFullService = null;
private static Comparator<MicroServiceFullInfo> serviceComparator = null;
+
@BeforeClass
- public static void setUp() throws Exception{
+ public static void setUp() throws Exception {
microServiceFullService = MicroServiceFullService.getInstance();
serviceComparator = new Comparator<MicroServiceFullInfo>() {
@Override
@@ -60,11 +68,12 @@ public class MicroServiceFullServiceTest {
}
};
}
+
@Before
public void setUpBeforeTest() throws Exception {
final JedisPool mockJedisPool = new MockJedisPool(new JedisPoolConfig(), "localhost");
PowerMockito.mockStatic(JedisUtil.class);
- JedisUtil jedisUtil=PowerMockito.mock(JedisUtil.class);
+ JedisUtil jedisUtil = PowerMockito.mock(JedisUtil.class);
when(jedisUtil.borrowJedisInstance()).thenReturn(mockJedisPool.getResource());
PowerMockito.replace(PowerMockito.method(RedisAccessWrapper.class, "filterKeys")).with(new InvocationHandler() {
@@ -76,15 +85,16 @@ public class MicroServiceFullServiceTest {
}
@Test
- public void testExistsMicroServiceInstance_notExist(){
+ public void testExistsMicroServiceInstance_notExist() {
try {
assertFalse(microServiceFullService.existsMicroServiceInstance("notExist", "v1"));
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
+
@Test
- public void testExistsMicroServiceInstance_Exist(){
+ public void testExistsMicroServiceInstance_Exist() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -94,20 +104,20 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
try {
assertFalse(microServiceFullService.existsMicroServiceInstance("testService", "v1"));
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
assertTrue(microServiceFullService.existsMicroServiceInstance("testService", "v1"));
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testSaveMicroServiceInfo2Redis(){
+ public void testSaveMicroServiceInfo2Redis() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -117,7 +127,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
try {
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
@@ -125,12 +135,12 @@ public class MicroServiceFullServiceTest {
assertEquals(microServiceFullInfo, actual);
} catch (Exception e) {
e.printStackTrace();
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testDeleteMicroService(){
+ public void testDeleteMicroService() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -140,21 +150,21 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
try {
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
assertTrue(microServiceFullService.existsMicroServiceInstance("testService", "v1"));
- microServiceFullService.deleteMicroService("testService","v1");
+ microServiceFullService.deleteMicroService("testService", "v1");
assertFalse(microServiceFullService.existsMicroServiceInstance("testService", "v1"));
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testUpdateMicroServiceStatus(){
+ public void testUpdateMicroServiceStatus() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -164,20 +174,20 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
try {
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
- assertEquals("1", microServiceFullService.getMicroServiceInstance("testService","v1").getStatus());
+ assertEquals("1", microServiceFullService.getMicroServiceInstance("testService", "v1").getStatus());
microServiceFullService.updateMicroServiceStatus("testService", "v1", "0");
assertEquals("0", microServiceFullService.getMicroServiceInstance("testService", "v1").getStatus());
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testGetAllMicroServiceKey(){
+ public void testGetAllMicroServiceKey() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -187,7 +197,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
MicroServiceFullInfo microServiceFullInfo2 = new MicroServiceFullInfo();
@@ -199,7 +209,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo2.setProtocol("http");
microServiceFullInfo2.setEnable_ssl(false);
Set<Node> nodeSet2 = new HashSet<>();
- nodeSet2.add(new Node("10.74.148.88","8081"));
+ nodeSet2.add(new Node("10.74.148.88", "8081"));
microServiceFullInfo2.setNodes(nodeSet2);
MicroServiceFullInfo microServiceFullInfo3 = new MicroServiceFullInfo();
@@ -211,7 +221,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo3.setProtocol("http");
microServiceFullInfo3.setEnable_ssl(false);
Set<Node> nodeSet3 = new HashSet<>();
- nodeSet3.add(new Node("10.74.148.89","8080"));
+ nodeSet3.add(new Node("10.74.148.89", "8080"));
microServiceFullInfo3.setNodes(nodeSet3);
try {
@@ -220,19 +230,19 @@ public class MicroServiceFullServiceTest {
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo3);
Set<String> result = microServiceFullService.getAllMicroServiceKey();
- final Set<String> expected =new HashSet<String>();
+ final Set<String> expected = new HashSet<String>();
expected.add("testService");
expected.add("testService2");
assertEquals(expected, result);
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testGetAllVersionsOfTheService(){
+ public void testGetAllVersionsOfTheService() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -242,7 +252,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
MicroServiceFullInfo microServiceFullInfo2 = new MicroServiceFullInfo();
@@ -254,7 +264,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo2.setProtocol("http");
microServiceFullInfo2.setEnable_ssl(false);
Set<Node> nodeSet2 = new HashSet<>();
- nodeSet2.add(new Node("10.74.148.88","8081"));
+ nodeSet2.add(new Node("10.74.148.88", "8081"));
microServiceFullInfo2.setNodes(nodeSet2);
MicroServiceFullInfo microServiceFullInfo3 = new MicroServiceFullInfo();
@@ -266,7 +276,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo3.setProtocol("http");
microServiceFullInfo3.setEnable_ssl(false);
Set<Node> nodeSet3 = new HashSet<>();
- nodeSet3.add(new Node("10.74.148.89","8080"));
+ nodeSet3.add(new Node("10.74.148.89", "8080"));
microServiceFullInfo3.setNodes(nodeSet3);
try {
@@ -281,17 +291,17 @@ public class MicroServiceFullServiceTest {
expected.add(microServiceFullInfo);
expected.add(microServiceFullInfo3);
- Collections.sort(expected,serviceComparator);
- Collections.sort(result,serviceComparator);
+ Collections.sort(expected, serviceComparator);
+ Collections.sort(result, serviceComparator);
assertEquals(expected, result);
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testGetAllMicroServicesInstances(){
+ public void testGetAllMicroServicesInstances() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -301,7 +311,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
MicroServiceFullInfo microServiceFullInfo2 = new MicroServiceFullInfo();
@@ -313,7 +323,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo2.setProtocol("http");
microServiceFullInfo2.setEnable_ssl(true);
Set<Node> nodeSet2 = new HashSet<>();
- nodeSet2.add(new Node("10.74.148.89","8080"));
+ nodeSet2.add(new Node("10.74.148.89", "8080"));
microServiceFullInfo2.setNodes(nodeSet2);
try {
@@ -325,17 +335,17 @@ public class MicroServiceFullServiceTest {
expected.add(microServiceFullInfo2);
List<MicroServiceFullInfo> result = microServiceFullService.getAllMicroServiceInstances();
Collections.sort(expected, serviceComparator);
- Collections.sort(result,serviceComparator );
+ Collections.sort(result, serviceComparator);
assertEquals(expected, result);
} catch (Exception e) {
e.printStackTrace();
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void testDeleteMultiMicroService(){
+ public void testDeleteMultiMicroService() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("v1");
@@ -345,7 +355,7 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
@@ -358,34 +368,36 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo3.setProtocol("http");
microServiceFullInfo3.setEnable_ssl(false);
Set<Node> nodeSet3 = new HashSet<>();
- nodeSet3.add(new Node("10.74.148.89","8080"));
+ nodeSet3.add(new Node("10.74.148.89", "8080"));
microServiceFullInfo3.setNodes(nodeSet3);
try {
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo3);
- //two versions of testservice exist
- assertEquals(2,microServiceFullService.getAllVersionsOfTheService("testService").size());
- //delete all versions of testservice
- long size = microServiceFullService.deleteMultiMicroService(MicroServiceUtil.getPrefixedKey("testService","*"));
- //after delete,no version exist
- assertEquals(0,microServiceFullService.getAllVersionsOfTheService("testService").size());
+ // two versions of testservice exist
+ assertEquals(2, microServiceFullService.getAllVersionsOfTheService("testService").size());
+ // delete all versions of testservice
+ long size = microServiceFullService
+ .deleteMultiMicroService(MicroServiceUtil.getPrefixedKey("testService", "*"));
+ // after delete,no version exist
+ assertEquals(0, microServiceFullService.getAllVersionsOfTheService("testService").size());
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
@Test
- public void tesGetMicroServiceInstance_notExist(){
+ public void tesGetMicroServiceInstance_notExist() {
try {
- assertNull(microServiceFullService.getMicroServiceInstance("notExist","v1"));
+ assertNull(microServiceFullService.getMicroServiceInstance("notExist", "v1"));
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}
+
@Test
- public void tesExistsGetUpdateDeleteMicroServiceStatus_versionNull(){
+ public void tesExistsGetUpdateDeleteMicroServiceStatus_versionNull() {
MicroServiceFullInfo microServiceFullInfo = new MicroServiceFullInfo();
microServiceFullInfo.setServiceName("testService");
microServiceFullInfo.setVersion("");
@@ -395,29 +407,29 @@ public class MicroServiceFullServiceTest {
microServiceFullInfo.setProtocol("http");
microServiceFullInfo.setEnable_ssl(false);
Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88","8080"));
+ nodeSet.add(new Node("10.74.148.88", "8080"));
microServiceFullInfo.setNodes(nodeSet);
try {
- //test null
+ // test null
assertFalse(microServiceFullService.existsMicroServiceInstance("testService", "null"));
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
- assertEquals("1", microServiceFullService.getMicroServiceInstance("testService","null").getStatus());
+ assertEquals("1", microServiceFullService.getMicroServiceInstance("testService", "null").getStatus());
microServiceFullService.updateMicroServiceStatus("testService", "null", "0");
assertEquals("0", microServiceFullService.getMicroServiceInstance("testService", "null").getStatus());
- microServiceFullService.deleteMicroService("testService","null");
+ microServiceFullService.deleteMicroService("testService", "null");
assertFalse(microServiceFullService.existsMicroServiceInstance("testService", "null"));
- //test String "null"
+ // test String "null"
assertFalse(microServiceFullService.existsMicroServiceInstance("testService", null));
microServiceFullService.saveMicroServiceInfo2Redis(microServiceFullInfo);
- assertEquals("1", microServiceFullService.getMicroServiceInstance("testService",null).getStatus());
+ assertEquals("1", microServiceFullService.getMicroServiceInstance("testService", null).getStatus());
microServiceFullService.updateMicroServiceStatus("testService", null, "0");
assertEquals("0", microServiceFullService.getMicroServiceInstance("testService", null).getStatus());
- microServiceFullService.deleteMicroService("testService",null);
+ microServiceFullService.deleteMicroService("testService", null);
assertFalse(microServiceFullService.existsMicroServiceInstance("testService", null));
} catch (Exception e) {
- assert false:"throw exception means error occured!"+e.getMessage();
+ assert false : "throw exception means error occured!" + e.getMessage();
}
}