2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * Copyright (C) 2017 Amdocs
 
   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=========================================================
 
  20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  23 package org.openecomp.appc.dg.aai.impl;
 
  26 import java.util.HashMap;
 
  29 import org.openecomp.sdnc.sli.SvcLogicContext;
 
  30 import org.openecomp.sdnc.sli.SvcLogicException;
 
  31 import org.openecomp.sdnc.sli.SvcLogicResource;
 
  32 import org.openecomp.sdnc.sli.aai.AAIClient;
 
  33 import org.openecomp.sdnc.sli.aai.AAIServiceException;
 
  34 import org.openecomp.sdnc.sli.aai.data.*;
 
  35 import org.openecomp.sdnc.sli.aai.data.notify.NotifyEvent;
 
  36 import org.openecomp.sdnc.sli.aai.data.v1507.VServer;
 
  37 import org.openecomp.sdnc.sli.aai.update.Update;
 
  40 public class AAIClientMock implements AAIClient {
 
  42     Map<String, String> mockAAI = new HashMap<>();
 
  44     public void setMockAAI(Map<String, String> mockAAI) {
 
  45         this.mockAAI = mockAAI;
 
  49     public AAIResponse requestSdnZoneQuery(String s, String s1, String s2) throws AAIServiceException {
 
  54     public boolean postNetworkVceData(String s, Vce vce) throws AAIServiceException {
 
  59     public Vce requestNetworkVceData(String s) throws AAIServiceException {
 
  64     public boolean deleteNetworkVceData(String s, String s1) throws AAIServiceException {
 
  69     public ServiceInstance requestServiceInterfaceData(String s) throws AAIServiceException {
 
  74     public ServiceInstance requestServiceInterfaceData(String s, String s1, String s2) throws AAIServiceException {
 
  79     public boolean postServiceInterfaceData(String s, String s1, String s2, ServiceInstance serviceInstance) throws AAIServiceException {
 
  84     public SearchResults requestServiceInstanceURL(String s) throws AAIServiceException {
 
  89     public Vpe requestNetworkVpeData(String s) throws AAIServiceException {
 
  94     public boolean postNetworkVpeData(String s, Vpe vpe) throws AAIServiceException {
 
  99     public boolean deleteNetworkVpeData(String s, String s1) throws AAIServiceException {
 
 104     public Vserver requestVServerData(String s, String s1, String s2, String s3) throws AAIServiceException {
 
 109     public boolean postVServerData(String s, String s1, String s2, String s3, Vserver vserver) throws AAIServiceException {
 
 114     public boolean deleteVServerData(String s, String s1, String s2, String s3, String s4) throws AAIServiceException {
 
 119     public URL requestVserverURLNodeQuery(String s) throws AAIServiceException {
 
 124     public String getTenantIdFromVserverUrl(URL url) {
 
 129     public String getCloudOwnerFromVserverUrl(URL url) {
 
 134     public String getCloudRegionFromVserverUrl(URL url) {
 
 139     public String getVServerIdFromVserverUrl(URL url, String s) {
 
 144     public Vserver requestVServerDataByURL(URL url) throws AAIServiceException {
 
 149     public VplsPe requestNetworkVplsPeData(String s) throws AAIServiceException {
 
 154     public boolean postNetworkVplsPeData(String s, VplsPe vplsPe) throws AAIServiceException {
 
 159     public boolean deleteNetworkVplsPeData(String s, String s1) throws AAIServiceException {
 
 164     public Complex requestNetworkComplexData(String s) throws AAIServiceException {
 
 169     public boolean postNetworkComplexData(String s, Complex complex) throws AAIServiceException {
 
 174     public boolean deleteNetworkComplexData(String s, String s1) throws AAIServiceException {
 
 179     public CtagPool requestCtagPoolData(String s, String s1, String s2) throws AAIServiceException {
 
 184     public VServer dataChangeRequestVServerData(URL url) throws AAIServiceException {
 
 189     public CtagPool dataChangeRequestCtagPoolData(URL url) throws AAIServiceException {
 
 194     public VplsPe dataChangeRequestVplsPeData(URL url) throws AAIServiceException {
 
 199     public Vpe dataChangeRequestVpeData(URL url) throws AAIServiceException {
 
 204     public DvsSwitch dataChangeRequestDvsSwitchData(URL url) throws AAIServiceException {
 
 209     public PServer dataChangeRequestPServerData(URL url) throws AAIServiceException {
 
 214     public OamNetwork dataChangeRequestOAMNetworkData(URL url) throws AAIServiceException {
 
 219     public AvailabilityZone dataChangeRequestAvailabilityZoneData(URL url) throws AAIServiceException {
 
 224     public Complex dataChangeRequestComplexData(URL url) throws AAIServiceException {
 
 229     public boolean dataChangeDeleteVServerData(URL url) throws AAIServiceException {
 
 234     public boolean dataChangeDeleteCtagPoolData(URL url) throws AAIServiceException {
 
 239     public boolean dataChangeDeleteVplsPeData(URL url) throws AAIServiceException {
 
 244     public boolean dataChangeDeleteVpeData(URL url) throws AAIServiceException {
 
 249     public boolean dataChangeDeleteDvsSwitchData(URL url) throws AAIServiceException {
 
 254     public boolean dataChangeDeleteOAMNetworkData(URL url) throws AAIServiceException {
 
 259     public boolean dataChangeDeleteAvailabilityZoneData(URL url) throws AAIServiceException {
 
 264     public boolean dataChangeDeleteComplexData(URL url) throws AAIServiceException {
 
 269     public GenericVnf requestGenericVnfData(String s) throws AAIServiceException {
 
 274     public boolean postGenericVnfData(String s, GenericVnf genericVnf) throws AAIServiceException {
 
 279     public boolean deleteGenericVnfData(String s, String s1) throws AAIServiceException {
 
 284     public DvsSwitch requestDvsSwitchData(String s) throws AAIServiceException {
 
 289     public boolean postDvsSwitchData(String s, DvsSwitch dvsSwitch) throws AAIServiceException {
 
 294     public boolean deleteDvsSwitchData(String s, String s1) throws AAIServiceException {
 
 299     public PInterface requestPInterfaceData(String s, String s1) throws AAIServiceException {
 
 304     public boolean postPInterfaceData(String s, String s1, PInterface pInterface) throws AAIServiceException {
 
 309     public boolean deletePInterfaceData(String s, String s1, String s2) throws AAIServiceException {
 
 314     public PhysicalLink requestPhysicalLinkData(String s) throws AAIServiceException {
 
 319     public boolean postPhysicalLinkData(String s, PhysicalLink physicalLink) throws AAIServiceException {
 
 324     public boolean deletePhysicalLinkData(String s, String s1) throws AAIServiceException {
 
 329     public PServer requestPServerData(String s) throws AAIServiceException {
 
 334     public boolean postPServerData(String s, PServer pServer) throws AAIServiceException {
 
 339     public boolean deletePServerData(String s, String s1) throws AAIServiceException {
 
 344     public L3Network requestL3NetworkData(String s) throws AAIServiceException {
 
 349     public L3Network requestL3NetworkQueryByName(String s) throws AAIServiceException {
 
 354     public boolean postL3NetworkData(String s, L3Network l3Network) throws AAIServiceException {
 
 359     public boolean deleteL3NetworkData(String s, String s1) throws AAIServiceException {
 
 364     public VpnBinding requestVpnBindingData(String s) throws AAIServiceException {
 
 369     public boolean deleteVpnBindingData(String s, String s1) throws AAIServiceException {
 
 374     public VnfImage requestVnfImageData(String s) throws AAIServiceException {
 
 379     public VnfImage requestVnfImageDataByVendorModel(String s, String s1) throws AAIServiceException {
 
 384     public VnfImage requestVnfImageDataByVendorModelVersion(String s, String s1, String s2) throws AAIServiceException {
 
 389     public boolean sendNotify(NotifyEvent notifyEvent, String s, String s1) throws AAIServiceException {
 
 394     public SitePairSet requestSitePairSetData(String s) throws AAIServiceException {
 
 399     public boolean postSitePairSetData(String s, SitePairSet sitePairSet) throws AAIServiceException {
 
 404     public boolean deleteSitePairSetData(String s, String s1) throws AAIServiceException {
 
 409     public Service requestServiceData(String s) throws AAIServiceException {
 
 414     public boolean postServiceData(String s, Service service) throws AAIServiceException {
 
 419     public boolean deleteServiceData(String s, String s1) throws AAIServiceException {
 
 424     public QueryResponse requestNodeQuery(String s, String s1, String s2) throws AAIServiceException {
 
 429     public String requestDataByURL(URL url) throws AAIServiceException {
 
 434     public GenericVnf requestGenericVnfeNodeQuery(String s) throws AAIServiceException {
 
 439     public Tenant requestTenantData(String s, String s1, String s2) throws AAIServiceException {
 
 444     public Tenant requestTenantDataByName(String s, String s1, String s2) throws AAIServiceException {
 
 449     public boolean postTenantData(String s, String s1, String s2, Tenant tenant) throws AAIServiceException {
 
 454     public boolean updateAnAIEntry(Update update) throws AAIServiceException {
 
 459     public QueryStatus backup(Map<String, String> map, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 464     public QueryStatus restore(Map<String, String> map, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 469     public QueryStatus isAvailable(String s, String s1, String s2, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 474     public QueryStatus exists(String s, String s1, String s2, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 479     public QueryStatus query(String s, boolean b, String s1, String key, String prefix, String s4, SvcLogicContext ctx) throws SvcLogicException {
 
 480         if (s.equals("generic-vnf") && key.equals("vnf-id = 'test_VNF'") && ctx != null) {
 
 481             for (Map.Entry<String, String> entry : mockAAI.entrySet()) {
 
 482                 ctx.setAttribute(prefix + "." + entry.getKey(), entry.getValue());
 
 484             return QueryStatus.SUCCESS;
 
 487         } else if (key.equals("vnf-id = 'test_VNF1'")){
 
 488             return QueryStatus.NOT_FOUND;
 
 490         else if (key.equals("vnf-id = 'test_VNF3'")){
 
 491             throw new SvcLogicException();
 
 494             return QueryStatus.FAILURE;
 
 501     public QueryStatus reserve(String s, String s1, String s2, String s3, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 506     public QueryStatus save(String s, boolean b, boolean b1, String s1, Map<String, String> map, String s2, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 511     public QueryStatus release(String s, String s1, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 516     public QueryStatus delete(String s, String s1, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 521     public QueryStatus notify(String s, String s1, SvcLogicContext svcLogicContext) throws SvcLogicException {
 
 526     public QueryStatus update(String s, String key, Map<String, String> data, String prefix, SvcLogicContext ctx) throws SvcLogicException {
 
 527         if (s.equals("generic-vnf") && key.equals("vnf-id = 'test_VNF'") && ctx != null) {
 
 528             for (Map.Entry<String, String> entry : data.entrySet()) {
 
 529                 mockAAI.put(entry.getKey(), entry.getValue());
 
 531             return QueryStatus.SUCCESS;
 
 534         } else if (key.equals("vnf-id = 'test_VNF1'")){
 
 535             return QueryStatus.NOT_FOUND;
 
 537         else if (key.equals("vnf-id = 'test_VNF3'")){
 
 538             throw new SvcLogicException();
 
 541             return QueryStatus.FAILURE;