X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-backend%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2FAppStatsManagerTest.java;fp=dashboard%2Fwebapp-backend%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2FAppStatsManagerTest.java;h=5aaace21c42b17b9835b247e4a2239e7c93f7045;hb=42ce1232fc25aa7affa6f8109f5e7d18ca2526b4;hp=0000000000000000000000000000000000000000;hpb=9a688995681b92344824c990bb1d838d3cc7cfaa;p=portal%2Fric-dashboard.git diff --git a/dashboard/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppStatsManagerTest.java b/dashboard/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppStatsManagerTest.java new file mode 100644 index 00000000..5aaace21 --- /dev/null +++ b/dashboard/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/AppStatsManagerTest.java @@ -0,0 +1,91 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2019 AT&T Intellectual Property + * %% + * 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=================================== + */ +package org.oransc.ric.portal.dashboard; + +import java.lang.invoke.MethodHandles; +import java.util.List; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration; +import org.oransc.ric.portal.dashboard.exception.StatsManagerException; +import org.oransc.ric.portal.dashboard.model.AppStats; +import org.oransc.ric.portal.dashboard.model.StatsDetailsTransport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("test") +public class AppStatsManagerTest { + + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + @Test + public void testStatsMgr() throws Exception { + new AppStatsManager("file.json"); + try { + new AppStatsManager(null); + throw new Exception("Unexpected success"); + } catch (IllegalArgumentException ex) { + logger.info("caught expected exception: {}", ex.toString()); + } + AppStatsManager mgr = new AppStatsManager(true); + AppStats as1 = mgr.createStats(RICInstanceMockConfiguration.INSTANCE_KEY_1, + new StatsDetailsTransport(-1, "app1 name", "http://app1")); + logger.info("Created stats {}", as1); + AppStats as2 = mgr.createStats(RICInstanceMockConfiguration.INSTANCE_KEY_1, + new StatsDetailsTransport(-1, "app2 name", "http://app2")); + logger.info("Created stats {}", as2); + List all = mgr.getStats(); + Assert.assertFalse(all.isEmpty()); + List byInstance = mgr.getStatsByInstance(RICInstanceMockConfiguration.INSTANCE_KEY_1); + Assert.assertFalse(byInstance.isEmpty()); + mgr = new AppStatsManager(false); + AppStats as3 = mgr.createStats(RICInstanceMockConfiguration.INSTANCE_KEY_1, + new StatsDetailsTransport(-1, "app3 name", "http://app3")); + Assert.assertNotEquals(as2.getStatsDetails().getAppId(), as3.getStatsDetails().getAppId()); + try { + mgr.createStats(as3.getInstanceKey(), as3.getStatsDetails()); + throw new Exception("Unexpected success"); + } catch (StatsManagerException ex) { + logger.info("caught expected exception: {}", ex.toString()); + } + AppStats as = mgr.getStatsById(as1.getInstanceKey(), as1.getStatsDetails().getAppId()); + Assert.assertEquals(as1, as); + AppStats notFound = mgr.getStatsById("bogus", 12345); + Assert.assertNull(notFound); + as1.getStatsDetails().setMetricUrl("http://other"); + mgr.updateStats(as1.getInstanceKey(), as1.getStatsDetails()); + mgr.deleteStats(as1.getInstanceKey(), as1.getStatsDetails().getAppId()); + try { + mgr.updateStats("bogus", as1.getStatsDetails()); + throw new Exception("Unexpected success"); + } catch (StatsManagerException ex) { + logger.info("caught expected exception: {}", ex.toString()); + } + try { + mgr.deleteStats("bogus", 999); + throw new Exception("Unexpected success"); + } catch (StatsManagerException ex) { + logger.info("caught expected exception: {}", ex.toString()); + } + } + +}