2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  22 package jtest.org.onap.ccsdk.sli.adaptors.ra;
 
  24 import org.junit.Assert;
 
  25 import org.junit.FixMethodOrder;
 
  26 import org.junit.Test;
 
  27 import org.junit.runner.RunWith;
 
  28 import org.junit.runners.MethodSorters;
 
  29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
 
  32 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
 
  33 import org.slf4j.Logger;
 
  34 import org.slf4j.LoggerFactory;
 
  35 import org.springframework.beans.factory.annotation.Autowired;
 
  36 import org.springframework.test.context.ContextConfiguration;
 
  37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
  39 @RunWith(SpringJUnit4ClassRunner.class)
 
  40 @ContextConfiguration(locations = { "classpath:test-context.xml" })
 
  41 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 
  42 public class TestIsAvailable {
 
  44     private static final Logger log = LoggerFactory.getLogger(TestIsAvailable.class);
 
  46     @Autowired(required = true)
 
  47     private ResourceAllocator resourceAllocator;
 
  49     @Autowired(required = true)
 
  50     private DataSetup dataSetup;
 
  53     public void test001() throws Exception {
 
  55         log.info("============== isAvailable " + t + " ================================");
 
  56         log.info("=== Test successful response - all resources available");
 
  58         String service1 = "isAvailable" + t + "/service1";
 
  61         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
  62         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
  64         SvcLogicContext ctx = new SvcLogicContext();
 
  65         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
  66         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
  67         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
 
  68         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
  70         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
  72         log.info("Result: " + st);
 
  74         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
  75         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
  79     public void test002() throws Exception {
 
  81         log.info("============== isAvailable " + t + " ================================");
 
  82         log.info("=== Test capacity not found - request very big number that is above the limits");
 
  84         String service1 = "isAvailable" + t + "/service1";
 
  87         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
  88         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
  90         SvcLogicContext ctx = new SvcLogicContext();
 
  91         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
  92         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
  93         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps");
 
  94         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
  96         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
  98         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
  99         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 101         log.info("Result: " + st);
 
 102         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 103         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 105         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 106         Assert.assertTrue(maxAvailableSpeed.equals("960000"));
 
 107         Assert.assertTrue(speedUnit.equals("kbps"));
 
 108         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 112     public void test003() throws Exception {
 
 114         log.info("============== isAvailable " + t + " ================================");
 
 115         log.info("=== Test capacity not found - PROV check for VPE");
 
 117         String service1 = "isAvailable" + t + "/service1";
 
 120         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "---", "juniper-vpe-image");
 
 121         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
 123         SvcLogicContext ctx = new SvcLogicContext();
 
 124         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
 125         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 126         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
 
 127         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 129         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 131         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
 132         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 134         log.info("Result: " + st);
 
 135         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 136         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 138         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 139         Assert.assertTrue(maxAvailableSpeed.equals("0"));
 
 140         Assert.assertTrue(speedUnit.equals("kbps"));
 
 141         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 145     public void test004() throws Exception {
 
 147         log.info("============== isAvailable " + t + " ================================");
 
 148         log.info("=== Test capacity not found - PROV check for VPLSPE");
 
 150         String service1 = "isAvailable" + t + "/service1";
 
 153         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
 154         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "---", null);
 
 156         SvcLogicContext ctx = new SvcLogicContext();
 
 157         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
 158         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 159         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
 
 160         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 162         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 164         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
 165         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 167         log.info("Result: " + st);
 
 168         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 169         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 171         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 172         Assert.assertTrue(maxAvailableSpeed.equals("0"));
 
 173         Assert.assertTrue(speedUnit.equals("kbps"));
 
 174         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 178     public void test005() throws Exception {
 
 180         log.info("============== isAvailable " + t + " ================================");
 
 181         log.info("=== Test capacity not found - VPE not found in DB");
 
 183         String service1 = "isAvailable" + t + "/service1";
 
 186         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
 188         SvcLogicContext ctx = new SvcLogicContext();
 
 189         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
 190         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 191         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
 
 192         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 194         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 196         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
 197         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 199         log.info("Result: " + st);
 
 200         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 201         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 203         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 204         Assert.assertTrue(maxAvailableSpeed.equals("0"));
 
 205         Assert.assertTrue(speedUnit.equals("kbps"));
 
 206         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 210     public void test006() throws Exception {
 
 212         log.info("============== isAvailable " + t + " ================================");
 
 213         log.info("=== Test capacity not found - VPLSPE not found in DB");
 
 215         String service1 = "isAvailable" + t + "/service1";
 
 218         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
 220         SvcLogicContext ctx = new SvcLogicContext();
 
 221         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
 222         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 223         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
 
 224         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 226         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 228         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
 229         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 231         log.info("Result: " + st);
 
 232         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 233         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 235         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 236         Assert.assertTrue(maxAvailableSpeed.equals("0"));
 
 237         Assert.assertTrue(speedUnit.equals("kbps"));
 
 238         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 242     public void test007() throws Exception {
 
 244         log.info("============== isAvailable " + t + " ================================");
 
 245         log.info("=== Test capacity not found - test max available speed calculation");
 
 247         String service1 = "isAvailable" + t + "/service1";
 
 248         String existingService1 = "isAvailable" + t + "/existing-service1";
 
 249         String existingService2 = "isAvailable" + t + "/existing-service2";
 
 252         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
 253         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv127", "ae0", "PROV", "juniper-vpe-image");
 
 254         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
 255         dataSetup.setupService(existingService1, "Active", 2, 200000, "mtanjrsv126", "mtsnj303vr1",
 
 256                 "MTSNJA4LCP1/Server1");
 
 257         dataSetup.setupService(existingService2, "Active", 3, 100000, "mtanjrsv127", "mtsnj303vr1",
 
 258                 "MTSNJA4LCP1/Server1");
 
 259         dataSetup.setupService(existingService2, "Pending", 4, 500000, "mtanjrsv127", "mtsnj303vr1",
 
 260                 "MTSNJA4LCP1/Server1");
 
 262         SvcLogicContext ctx = new SvcLogicContext();
 
 263         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
 264         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 265         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps");
 
 266         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 268         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 270         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
 271         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 273         log.info("Result: " + st);
 
 274         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 275         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 277         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 278         Assert.assertTrue(maxAvailableSpeed.equals("260000"));
 
 279         Assert.assertTrue(speedUnit.equals("kbps"));
 
 280         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 284     public void test008() throws Exception {
 
 286         log.info("============== isAvailable " + t + " ================================");
 
 287         log.info("=== Test capacity not found - test server limit depending on number of connections");
 
 289         String service1 = "isAvailable" + t + "/service1";
 
 292         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
 293         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv127", "ae0", "PROV", "juniper-vpe-image");
 
 294         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
 295         for (int i = 1; i <= 13; i++)
 
 296             dataSetup.setupService("isAvailable" + t + "/existing-service" + i, "Active", 2, 20000, "mtanjrsv126",
 
 297                     "mtsnj303vr1", "MTSNJA4LCP1/Server1");
 
 299         SvcLogicContext ctx = new SvcLogicContext();
 
 300         ctx.setAttribute("tmp.resource-allocator.service-instance-id", service1);
 
 301         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 302         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps");
 
 303         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 305         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 307         String maxAvailableSpeed = ctx.getAttribute("tmp.resource-allocator-output.max-available-speed");
 
 308         String speedUnit = ctx.getAttribute("tmp.resource-allocator-output.speed-unit");
 
 310         log.info("Result: " + st);
 
 311         log.info("  tmp.resource-allocator-output.max-available-speed: " + maxAvailableSpeed);
 
 312         log.info("  tmp.resource-allocator-output.speed-unit: " + speedUnit);
 
 314         Assert.assertTrue(st == QueryStatus.NOT_FOUND);
 
 315         Assert.assertTrue(maxAvailableSpeed.equals("340000"));
 
 316         Assert.assertTrue(speedUnit.equals("kbps"));
 
 317         Assert.assertTrue(dataSetup.serviceNotInDb(service1, null, null));
 
 321     public void test009() throws Exception {
 
 323         log.info("============== isAvailable " + t + " ================================");
 
 324         log.info("=== Test successful response - no service instance id in input - all resources available");
 
 327         dataSetup.setupVpePort("MTSNJA4LCP1", "mtanjrsv126", "ae0", "PROV", "juniper-vpe-image");
 
 328         dataSetup.setupVplspePort("MTSNJA4LCP1", "mtsnj303vr1", "xe-0/0/2", "PROV", null);
 
 330         SvcLogicContext ctx = new SvcLogicContext();
 
 331         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 332         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Mbps");
 
 333         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 335         QueryStatus st = resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 337         log.info("Result: " + st);
 
 338         log.info("  tmp.resource-allocator-output.max-available-speed: " +
 
 339                 ctx.getAttribute("tmp.resource-allocator-output.max-available-speed"));
 
 340         log.info("  tmp.resource-allocator-output.speed-unit: " +
 
 341                 ctx.getAttribute("tmp.resource-allocator-output.speed-unit"));
 
 343         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
 347     public void test010() throws Exception {
 
 349         log.info("============== isAvailable " + t + " ================================");
 
 350         log.info("=== Test input validations - no aic-site-id in input");
 
 352         SvcLogicContext ctx = new SvcLogicContext();
 
 353         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 354         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps");
 
 357             resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 358         } catch (SvcLogicException e) {
 
 359             Assert.assertTrue(e.getMessage().equals(
 
 360                     "tmp.resource-allocator.aic-site-id is required in ResourceAllocator"));
 
 363         Assert.fail("SvcLogicException expected");
 
 367     public void test011() throws Exception {
 
 369         log.info("============== isAvailable " + t + " ================================");
 
 370         log.info("=== Test input validations - speed not a number in input");
 
 372         SvcLogicContext ctx = new SvcLogicContext();
 
 373         ctx.setAttribute("tmp.resource-allocator.speed", "nnnnn");
 
 374         ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps");
 
 375         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 378             resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 379         } catch (SvcLogicException e) {
 
 380             Assert.assertTrue(e.getMessage().equals("Invalid tmp.resource-allocator.speed. Must be a number."));
 
 383         Assert.fail("SvcLogicException expected");
 
 387     public void test012() throws Exception {
 
 389         log.info("============== isAvailable " + t + " ================================");
 
 390         log.info("=== Test input validations - speed-unit missing in input");
 
 392         SvcLogicContext ctx = new SvcLogicContext();
 
 393         ctx.setAttribute("tmp.resource-allocator.speed", "300");
 
 394         ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1");
 
 397             resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx);
 
 398         } catch (SvcLogicException e) {
 
 399             Assert.assertTrue(e.getMessage().equals(
 
 400                     "tmp.resource-allocator.speed-unit is required in ResourceAllocator"));
 
 403         Assert.fail("SvcLogicException expected");