summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-02-14 15:30:07 +0100
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-02-14 15:30:07 +0100
commit9ebb9c1aa320e49c581ba1a66202cc2f2bda0c5a (patch)
tree658398df111f90c19fe158c7c9abe040a850d49d /src/test/java
parent454936e900890e77adc9a1450e5bcb01d0c90823 (diff)
Rework the SDC cache
Rework the SDC cache that was broken and add unit tests to validate it Issue-ID: CLAMP-85 Change-Id: I43503702733d8f8f0ddbf391f94fb4e5416be98f Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java37
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java48
-rw-r--r--src/test/java/org/onap/clamp/clds/model/CldsDBServiceCacheTest.java67
3 files changed, 147 insertions, 5 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
index c684d4455..1e9a9ed5e 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
@@ -25,30 +25,35 @@ package org.onap.clamp.clds.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
+import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.NotFoundException;
+import org.apache.commons.codec.DecoderException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.AbstractItCase;
+import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.CLDSMonitoringDetails;
+import org.onap.clamp.clds.model.CldsDBServiceCache;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.CldsServiceData;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -57,7 +62,6 @@ import org.springframework.test.context.junit4.SpringRunner;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
-@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class CldsDaoItCase extends AbstractItCase {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class);
@@ -66,6 +70,8 @@ public class CldsDaoItCase extends AbstractItCase {
private String bpmnText;
private String imageText;
private String bpmnPropText;
+ @Autowired
+ private SdcCatalogServices sdcCatalogServices;
/**
* Setup the variable before the tests execution.
@@ -161,4 +167,31 @@ public class CldsDaoItCase extends AbstractItCase {
assertNotNull(clName.getCloseloopName());
});
}
+
+ @Test
+ public void testCldsServiceCache() throws GeneralSecurityException, DecoderException, IOException {
+ CldsServiceData cldsServiceData = sdcCatalogServices
+ .getCldsServiceDataWithAlarmConditions("4cc5b45a-1f63-4194-8100-cd8e14248c92");
+ // Test not in cache so should be null
+ CldsServiceData cldsServiceDataCache = cldsDao.getCldsServiceCache("4cc5b45a-1f63-4194-8100-cd8e14248c92");
+ assertNull(cldsServiceDataCache);
+ cldsDao.setCldsServiceCache(new CldsDBServiceCache(cldsServiceData));
+ cldsServiceDataCache = cldsDao.getCldsServiceCache("4cc5b45a-1f63-4194-8100-cd8e14248c92");
+ assertNotNull(cldsServiceDataCache);
+ assertEquals("56441b4b-0467-41dc-9a0e-e68613838219", cldsServiceDataCache.getServiceUUID());
+ assertEquals("4cc5b45a-1f63-4194-8100-cd8e14248c92", cldsServiceDataCache.getServiceInvariantUUID());
+ assertEquals(2, cldsServiceDataCache.getCldsVfs().size());
+ assertNotNull(cldsServiceDataCache.getAgeOfRecord());
+ assertEquals(4, cldsServiceDataCache.getCldsVfs().get(0).getCldsVfcs().size());
+ assertEquals("07e266fc-49ab-4cd7-8378-ca4676f1b9ec",
+ cldsServiceDataCache.getCldsVfs().get(0).getVfInvariantResourceUUID());
+ assertEquals(0, cldsServiceDataCache.getCldsVfs().get(0).getCldsKPIList().size());
+ // Second update
+ cldsServiceData.setCldsVfs(null);
+ cldsDao.setCldsServiceCache(new CldsDBServiceCache(cldsServiceData));
+ cldsServiceDataCache = cldsDao.getCldsServiceCache("4cc5b45a-1f63-4194-8100-cd8e14248c92");
+ assertNotNull(cldsServiceDataCache);
+ assertNull(cldsServiceDataCache.getCldsVfs());
+ cldsDao.clearServiceCache();
+ }
}
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
index 9dac2dc14..932434de7 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,17 +26,21 @@ package org.onap.clamp.clds.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
import java.io.IOException;
import java.io.InputStream;
+import java.security.GeneralSecurityException;
import java.security.Principal;
import java.util.Properties;
import javax.ws.rs.core.SecurityContext;
+import org.apache.commons.codec.DecoderException;
+import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,13 +50,14 @@ import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.CldsHealthCheck;
import org.onap.clamp.clds.model.CldsInfo;
import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.CldsServiceData;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.service.CldsService;
import org.onap.clamp.clds.util.ResourceFileUtil;
+import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
@@ -60,7 +65,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class CldsServiceItCase extends AbstractItCase {
@Autowired
@@ -170,4 +174,42 @@ public class CldsServiceItCase extends AbstractItCase {
// Verify whether it has been added properly or not
assertNotNull(cldsDao.getModel(randomNameModel));
}
+
+ @Test
+ public void testGetSdcServices() throws GeneralSecurityException, DecoderException, JSONException, IOException {
+ String result = cldsService.getSdcServices();
+ JSONAssert.assertEquals(
+ ResourceFileUtil.getResourceAsString("example/sdc/expected-result/all-sdc-services.json"), result,
+ true);
+ }
+
+ @Test
+ public void testGetSdcPropertiesByServiceUUIDForRefresh()
+ throws GeneralSecurityException, DecoderException, JSONException, IOException {
+ SecurityContext securityContext = Mockito.mock(SecurityContext.class);
+ Principal principal = Mockito.mock(Principal.class);
+ Mockito.when(principal.getName()).thenReturn("admin");
+ Mockito.when(securityContext.getUserPrincipal()).thenReturn(principal);
+ Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-filter-vf|dev|*")).thenReturn(true);
+ cldsService.setSecurityContext(securityContext);
+ // Test basic functionalities
+ String result = cldsService.getSdcPropertiesByServiceUUIDForRefresh("4cc5b45a-1f63-4194-8100-cd8e14248c92",
+ false);
+ JSONAssert.assertEquals(
+ ResourceFileUtil.getResourceAsString("example/sdc/expected-result/sdc-properties-4cc5b45a.json"),
+ result, true);
+ // Now test the Cache effect
+ CldsServiceData cldsServiceDataCache = cldsDao.getCldsServiceCache("c95b0e7c-c1f0-4287-9928-7964c5377a46");
+ // Should not be there, so should be null
+ assertNull(cldsServiceDataCache);
+ cldsService.getSdcPropertiesByServiceUUIDForRefresh("c95b0e7c-c1f0-4287-9928-7964c5377a46", true);
+ // Should be there now, so should NOT be null
+ cldsServiceDataCache = cldsDao.getCldsServiceCache("c95b0e7c-c1f0-4287-9928-7964c5377a46");
+ assertNotNull(cldsServiceDataCache);
+ cldsDao.clearServiceCache();
+ }
}
diff --git a/src/test/java/org/onap/clamp/clds/model/CldsDBServiceCacheTest.java b/src/test/java/org/onap/clamp/clds/model/CldsDBServiceCacheTest.java
new file mode 100644
index 000000000..ad1689157
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/model/CldsDBServiceCacheTest.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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
+ *
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class CldsDBServiceCacheTest {
+
+ @Test
+ public void testConstructor() throws IOException, ClassNotFoundException {
+ CldsServiceData cldsServiceData = new CldsServiceData();
+ cldsServiceData.setServiceUUID("testUUID");
+ cldsServiceData.setAgeOfRecord(Long.valueOf(100));
+ cldsServiceData.setServiceInvariantUUID("testInvariantUUID");
+ List<CldsVfData> cldsVfs = new ArrayList<>();
+ CldsVfData cldsVfData = new CldsVfData();
+ cldsVfData.setVfName("vf");
+ List<CldsVfKPIData> cldsKPIList = new ArrayList<>();
+ CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();
+ cldsVfKPIData.setFieldPath("fieldPath");
+ cldsVfKPIData.setFieldPathValue("fieldValue");
+ cldsKPIList.add(cldsVfKPIData);
+ cldsVfData.setCldsKPIList(cldsKPIList);
+ cldsVfs.add(cldsVfData);
+ cldsServiceData.setCldsVfs(cldsVfs);
+ CldsDBServiceCache cldsDBServiceCache = new CldsDBServiceCache(cldsServiceData);
+ ObjectInputStream reader = new ObjectInputStream(cldsDBServiceCache.getCldsDataInstream());
+ CldsServiceData cldsServiceDataResult = (CldsServiceData) reader.readObject();
+ assertNotNull(cldsServiceDataResult);
+ assertNotNull(cldsServiceDataResult.getCldsVfs());
+ assertEquals(cldsServiceDataResult.getCldsVfs().size(), 1);
+ assertNotNull(cldsServiceDataResult.getCldsVfs().get(0).getCldsKPIList());
+ assertEquals(cldsServiceDataResult.getCldsVfs().get(0).getCldsKPIList().size(), 1);
+ assertEquals(cldsServiceDataResult.getServiceInvariantUUID(), "testInvariantUUID");
+ assertEquals(cldsServiceDataResult.getServiceUUID(), "testUUID");
+ assertEquals(cldsServiceDataResult.getAgeOfRecord(), Long.valueOf(100L));
+ }
+}