diff options
Diffstat (limited to 'graph-inventory/aai-client/src')
25 files changed, 256 insertions, 566 deletions
diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java index 998aea9065..ee06fa4be8 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectPlurals.java @@ -22,63 +22,12 @@ package org.onap.aaiclient.client.aai; import java.io.Serializable; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectPlurals; -import org.onap.so.constants.Defaults; import com.google.common.base.CaseFormat; public class AAIObjectPlurals implements AAIObjectBase, GraphInventoryObjectPlurals, Serializable { private static final long serialVersionUID = 5312713297525740746L; - public static final AAIObjectPlurals CUSTOMER = - new AAIObjectPlurals(AAIObjectType.CUSTOMER, AAINamespaceConstants.BUSINESS, "/customers"); - public static final AAIObjectPlurals GENERIC_VNF = - new AAIObjectPlurals(AAIObjectType.GENERIC_VNF, AAINamespaceConstants.NETWORK, "/generic-vnfs"); - public static final AAIObjectPlurals PORT_GROUP = - new AAIObjectPlurals(AAIObjectType.PORT_GROUP, AAIObjectType.VCE.uriTemplate(), "/port-groups"); - public static final AAIObjectPlurals PSERVER = - new AAIObjectPlurals(AAIObjectType.PSERVER, AAINamespaceConstants.CLOUD_INFRASTRUCTURE, "/pservers"); - public static final AAIObjectPlurals P_INTERFACE = - new AAIObjectPlurals(AAIObjectType.P_INTERFACE, AAIObjectType.PSERVER.uriTemplate(), "/p-interfaces"); - public static final AAIObjectPlurals L3_NETWORK = - new AAIObjectPlurals(AAIObjectType.L3_NETWORK, AAINamespaceConstants.NETWORK, "/l3-networks"); - public static final AAIObjectPlurals NETWORK_POLICY = - new AAIObjectPlurals(AAIObjectType.NETWORK_POLICY, AAINamespaceConstants.NETWORK, "/network-policies"); - public static final AAIObjectPlurals VPN_BINDING = - new AAIObjectPlurals(AAIObjectType.VPN_BINDING, AAINamespaceConstants.NETWORK, "/vpn-bindings"); - public static final AAIObjectPlurals SERVICE_SUBSCRIPTION = new AAIObjectPlurals(AAIObjectType.SERVICE_SUBSCRIPTION, - AAIObjectType.CUSTOMER.uriTemplate(), "/service-subscriptions"); - public static final AAIObjectPlurals SERVICE_INSTANCE = new AAIObjectPlurals(AAIObjectType.SERVICE_INSTANCE, - AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), "/service-instances"); - public static final AAIObjectPlurals OWNING_ENTITY = - new AAIObjectPlurals(AAIObjectType.OWNING_ENTITY, AAINamespaceConstants.BUSINESS, "/owning-entities"); - public static final AAIObjectPlurals VOLUME_GROUP = new AAIObjectPlurals(AAIObjectType.VOLUME_GROUP, - AAIObjectType.CLOUD_REGION.uriTemplate(), "/volume-groups"); - public static final AAIObjectPlurals AVAILIBILITY_ZONE = new AAIObjectPlurals(AAIObjectType.AVAILIBILITY_ZONE, - AAIObjectType.CLOUD_REGION.uriTemplate(), "/availability-zones"); - public static final AAIObjectPlurals VF_MODULE = - new AAIObjectPlurals(AAIObjectType.VF_MODULE, AAIObjectType.GENERIC_VNF.uriTemplate(), "/vf-modules"); - public static final AAIObjectPlurals CONFIGURATION = - new AAIObjectPlurals(AAIObjectType.CONFIGURATION, AAINamespaceConstants.NETWORK, "/configurations"); - public static final AAIObjectPlurals DEFAULT_TENANT = - new AAIObjectPlurals(AAIObjectType.DEFAULT_TENANT, AAINamespaceConstants.CLOUD_INFRASTRUCTURE - + "/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER + "/AAIAIC25", "/tenants"); - public static final AAIObjectPlurals NETWORK_TECHNOLOGY = new AAIObjectPlurals(AAIObjectType.NETWORK_TECHNOLOGY, - AAINamespaceConstants.CLOUD_INFRASTRUCTURE, "/network-technologies"); - public static final AAIObjectPlurals LOGICAL_LINK = - new AAIObjectPlurals(AAIObjectType.LOGICAL_LINK, AAINamespaceConstants.NETWORK, "/logical-links"); - public static final AAIObjectPlurals L_INTERFACE = - new AAIObjectPlurals(AAIObjectType.L_INTERFACE, AAIObjectType.VSERVER.uriTemplate(), "/l-interfaces"); - public static final AAIObjectPlurals SUB_L_INTERFACE = - new AAIObjectPlurals(AAIObjectType.L_INTERFACE, AAIObjectType.L_INTERFACE.uriTemplate(), "/l-interfaces"); - public static final AAIObjectPlurals INSTANCE_GROUP = - new AAIObjectPlurals(AAIObjectType.INSTANCE_GROUP, AAINamespaceConstants.NETWORK, "/instance-groups"); - public static final AAIObjectPlurals PNF = - new AAIObjectPlurals(AAIObjectType.PNF, AAINamespaceConstants.NETWORK, "/pnfs"); - public static final AAIObjectPlurals PROJECT = - new AAIObjectPlurals(AAIObjectType.PROJECT, AAINamespaceConstants.BUSINESS, "/projects"); - public static final AAIObjectPlurals VSERVER = - new AAIObjectPlurals(AAIObjectType.VSERVER, AAIObjectType.TENANT.uriTemplate(), "/vservers"); - private final String uriTemplate; private final String partialUri; private final String name; diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java index dae5c62dd3..55a487d675 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java @@ -27,175 +27,30 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import org.onap.aai.annotations.Metadata; -import org.onap.aai.domain.yang.AggregateRoute; -import org.onap.aai.domain.yang.AllottedResource; -import org.onap.aai.domain.yang.AvailabilityZone; -import org.onap.aai.domain.yang.CloudRegion; -import org.onap.aai.domain.yang.Collection; -import org.onap.aai.domain.yang.CommunicationServiceProfile; -import org.onap.aai.domain.yang.Complex; -import org.onap.aai.domain.yang.Configuration; -import org.onap.aai.domain.yang.Connector; -import org.onap.aai.domain.yang.Customer; -import org.onap.aai.domain.yang.Device; -import org.onap.aai.domain.yang.EsrVnfm; -import org.onap.aai.domain.yang.ExtAaiNetwork; -import org.onap.aai.domain.yang.Flavor; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.Image; -import org.onap.aai.domain.yang.InstanceGroup; -import org.onap.aai.domain.yang.L3Network; -import org.onap.aai.domain.yang.LInterface; -import org.onap.aai.domain.yang.LagInterface; -import org.onap.aai.domain.yang.LineOfBusiness; -import org.onap.aai.domain.yang.LogicalLink; -import org.onap.aai.domain.yang.ModelVer; -import org.onap.aai.domain.yang.NetworkPolicy; -import org.onap.aai.domain.yang.NetworkTechnology; -import org.onap.aai.domain.yang.OperationalEnvironment; -import org.onap.aai.domain.yang.OwningEntity; -import org.onap.aai.domain.yang.PInterface; -import org.onap.aai.domain.yang.PhysicalLink; -import org.onap.aai.domain.yang.Platform; -import org.onap.aai.domain.yang.Pnf; -import org.onap.aai.domain.yang.PortGroup; -import org.onap.aai.domain.yang.Project; -import org.onap.aai.domain.yang.Pserver; -import org.onap.aai.domain.yang.RouteTableReference; -import org.onap.aai.domain.yang.Service; -import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aai.domain.yang.ServiceProfile; -import org.onap.aai.domain.yang.ServiceSubscription; -import org.onap.aai.domain.yang.SliceProfile; -import org.onap.aai.domain.yang.SpPartner; -import org.onap.aai.domain.yang.SriovPf; -import org.onap.aai.domain.yang.SriovVf; -import org.onap.aai.domain.yang.Subnet; -import org.onap.aai.domain.yang.Tenant; -import org.onap.aai.domain.yang.TunnelXconnect; -import org.onap.aai.domain.yang.Vce; -import org.onap.aai.domain.yang.VfModule; -import org.onap.aai.domain.yang.VlanRange; -import org.onap.aai.domain.yang.VlanTag; -import org.onap.aai.domain.yang.Vnfc; -import org.onap.aai.domain.yang.VolumeGroup; -import org.onap.aai.domain.yang.VpnBinding; -import org.onap.aai.domain.yang.Vserver; -import org.onap.aai.domain.yang.Zone; import org.onap.aaiclient.client.aai.entities.uri.AAIFluentTypeReverseLookup; +import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectName; import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType; -import org.onap.so.constants.Defaults; import org.reflections.Reflections; import org.reflections.scanners.SubTypesScanner; import org.reflections.util.ClasspathHelper; import org.reflections.util.ConfigurationBuilder; import com.google.common.base.CaseFormat; -public class AAIObjectType implements AAIObjectBase, GraphInventoryObjectType, Serializable { +/** + * Types are accessed through AAIFluentTypeBuilder and should no longer be added as static members + * + */ +public class AAIObjectType implements AAIObjectBase, AAIObjectName, GraphInventoryObjectType, Serializable { private static final long serialVersionUID = -2877184776691514600L; private static Map<String, AAIObjectType> map = new HashMap<>(); - public static final AAIObjectType DEFAULT_CLOUD_REGION = new AAIObjectType( - AAINamespaceConstants.CLOUD_INFRASTRUCTURE, - "/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER + "/{cloud-region-id}", "default-cloud-region"); - public static final AAIObjectType CUSTOMER = new AAIObjectType(AAINamespaceConstants.BUSINESS, Customer.class); public static final AAIObjectType GENERIC_QUERY = new AAIObjectType("/search", "/generic-query", "generic-query"); public static final AAIObjectType BULK_PROCESS = new AAIObjectType("/bulkprocess", "", "bulkprocess"); public static final AAIObjectType SINGLE_TRANSACTION = new AAIObjectType("/bulk/single-transaction", "", "single-transaction"); - public static final AAIObjectType GENERIC_VNF = new AAIObjectType(AAINamespaceConstants.NETWORK, GenericVnf.class); - public static final AAIObjectType GENERIC_VNFS = - new AAIObjectType(AAINamespaceConstants.NETWORK, "/generic-vnfs", "generic-vnfs"); - public static final AAIObjectType VF_MODULE = - new AAIObjectType(AAIObjectType.GENERIC_VNF.uriTemplate(), VfModule.class); - public static final AAIObjectType L3_NETWORK = new AAIObjectType(AAINamespaceConstants.NETWORK, L3Network.class); - public static final AAIObjectType NETWORK_POLICY = - new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkPolicy.class); public static final AAIObjectType NODES_QUERY = new AAIObjectType("/search", "/nodes-query", "nodes-query"); public static final AAIObjectType CUSTOM_QUERY = new AAIObjectType("/query", "", "query"); - public static final AAIObjectType ROUTE_TABLE_REFERENCE = - new AAIObjectType(AAINamespaceConstants.NETWORK, RouteTableReference.class); - public static final AAIObjectType DEFAULT_TENANT = - new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE + "/cloud-regions/cloud-region/" - + Defaults.CLOUD_OWNER + "/AAIAIC25", "/tenants/tenant/{tenant-id}", "default-tenant"); - public static final AAIObjectType VCE = new AAIObjectType(AAINamespaceConstants.NETWORK, Vce.class); - public static final AAIObjectType PORT_GROUP = new AAIObjectType(AAIObjectType.VCE.uriTemplate(), PortGroup.class); - public static final AAIObjectType VPN_BINDING = new AAIObjectType(AAINamespaceConstants.NETWORK, VpnBinding.class); - public static final AAIObjectType CONFIGURATION = - new AAIObjectType(AAINamespaceConstants.NETWORK, Configuration.class); - public static final AAIObjectType PSERVER = - new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Pserver.class); - public static final AAIObjectType SERVICE_SUBSCRIPTION = - new AAIObjectType(AAIObjectType.CUSTOMER.uriTemplate(), ServiceSubscription.class); - - public static final AAIObjectType SERVICE_INSTANCE_METADATA = new AAIObjectType( - AAIObjectType.SERVICE_INSTANCE + "/metadata", org.onap.aai.domain.yang.v13.Metadata.class); - - public static final AAIObjectType SERVICE = new AAIObjectType( - AAINamespaceConstants.SERVICE_DESIGN_AND_CREATION + "/services/service/{service-id}", Service.class); - public static final AAIObjectType SERVICE_INSTANCE = - new AAIObjectType(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), ServiceInstance.class); - public static final AAIObjectType PROJECT = new AAIObjectType(AAINamespaceConstants.BUSINESS, Project.class); - public static final AAIObjectType LINE_OF_BUSINESS = - new AAIObjectType(AAINamespaceConstants.BUSINESS, LineOfBusiness.class); - public static final AAIObjectType PLATFORM = new AAIObjectType(AAINamespaceConstants.BUSINESS, Platform.class); - public static final AAIObjectType OWNING_ENTITY = - new AAIObjectType(AAINamespaceConstants.BUSINESS, OwningEntity.class); - public static final AAIObjectType ALLOTTED_RESOURCE = - new AAIObjectType(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), AllottedResource.class); - public static final AAIObjectType ALLOTTED_RESOURCE_ALL = - new AAIObjectType(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), "/allotted-resources", "allottedResources"); - public static final AAIObjectType PNF = new AAIObjectType(AAINamespaceConstants.NETWORK, Pnf.class); - public static final AAIObjectType OPERATIONAL_ENVIRONMENT = - new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, OperationalEnvironment.class); - public static final AAIObjectType CLOUD_REGION = - new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, CloudRegion.class); - public static final AAIObjectType TENANT = - new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Tenant.class); - public static final AAIObjectType VOLUME_GROUP = - new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), VolumeGroup.class); - public static final AAIObjectType VSERVER = new AAIObjectType(AAIObjectType.TENANT.uriTemplate(), Vserver.class); - public static final AAIObjectType MODEL_VER = new AAIObjectType( - AAINamespaceConstants.SERVICE_DESIGN_AND_CREATION + "/models/model/{model-invariant-id}", ModelVer.class); - public static final AAIObjectType TUNNEL_XCONNECT = - new AAIObjectType(AAIObjectType.ALLOTTED_RESOURCE.uriTemplate(), TunnelXconnect.class); - public static final AAIObjectType P_INTERFACE = - new AAIObjectType(AAIObjectType.PSERVER.uriTemplate(), PInterface.class); - public static final AAIObjectType SRIOV_PF = - new AAIObjectType(AAIObjectType.P_INTERFACE.uriTemplate(), SriovPf.class); - public static final AAIObjectType LOGICAL_LINK = - new AAIObjectType(AAINamespaceConstants.NETWORK, LogicalLink.class); - public static final AAIObjectType PHYSICAL_LINK = - new AAIObjectType(AAINamespaceConstants.NETWORK, PhysicalLink.class); - public static final AAIObjectType INSTANCE_GROUP = - new AAIObjectType(AAINamespaceConstants.NETWORK, InstanceGroup.class); - public static final AAIObjectType COLLECTION = new AAIObjectType(AAINamespaceConstants.NETWORK, Collection.class); - public static final AAIObjectType VNFC = new AAIObjectType(AAINamespaceConstants.NETWORK, Vnfc.class); - public static final AAIObjectType VLAN_TAG = new AAIObjectType(AAINamespaceConstants.NETWORK, VlanTag.class); - public static final AAIObjectType COMPLEX = - new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Complex.class); - public static final AAIObjectType CONNECTOR = new AAIObjectType(AAINamespaceConstants.BUSINESS, Connector.class); - public static final AAIObjectType NETWORK_TECHNOLOGY = - new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, NetworkTechnology.class); - public static final AAIObjectType SUBNET = new AAIObjectType(AAIObjectType.L3_NETWORK.uriTemplate(), Subnet.class); - public static final AAIObjectType SP_PARTNER = new AAIObjectType(AAINamespaceConstants.BUSINESS, SpPartner.class); - public static final AAIObjectType DEVICE = new AAIObjectType(AAINamespaceConstants.NETWORK, Device.class); - public static final AAIObjectType EXT_AAI_NETWORK = - new AAIObjectType(AAINamespaceConstants.NETWORK, ExtAaiNetwork.class); - public static final AAIObjectType AGGREGATE_ROUTE = - new AAIObjectType(AAINamespaceConstants.NETWORK, AggregateRoute.class); - public static final AAIObjectType L_INTERFACE = - new AAIObjectType(AAIObjectType.VSERVER.uriTemplate(), LInterface.class); - public static final AAIObjectType SRIOV_VF = - new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(), SriovVf.class); - public static final AAIObjectType SUB_L_INTERFACE = new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(), - "/l-interfaces/l-interface/{sub-interface-name}", "sub-l-interface"); - public static final AAIObjectType IMAGE = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Image.class); - public static final AAIObjectType FLAVOR = - new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Flavor.class); - - public static final AAIObjectType VLAN_RANGE = new AAIObjectType(CLOUD_REGION.uriTemplate(), VlanRange.class); public static final AAIObjectType UNKNOWN = new AAIObjectType("", "", "unknown") { private static final long serialVersionUID = 9208984071038447607L; @@ -206,42 +61,9 @@ public class AAIObjectType implements AAIObjectBase, GraphInventoryObjectType, S } }; public static final AAIObjectType DSL = new AAIObjectType("/dsl", "", "dsl"); - public static final AAIObjectType VNFM = new AAIObjectType( - AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list/esr-vnfm/{vnfm-id}", EsrVnfm.class); - public static final AAIObjectType VNFM_LIST = - new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM, "/esr-vnfm-list", "vnfm-list"); - public static final AAIObjectType VNFM_ESR_SYSTEM_INFO_LIST = - new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list", - "/esr-vnfm/{vnfm-id}/esr-system-info-list", "vnfm-esr-system-info-list"); - public static final AAIObjectType CLOUD_ESR_SYSTEM_INFO_LIST = new AAIObjectType( - AAIObjectType.CLOUD_REGION.uriTemplate(), "/esr-system-info-list", "cloud-esr-system-info-list"); - public static final AAIObjectType ZONE = new AAIObjectType(AAINamespaceConstants.NETWORK, Zone.class); - public static final AAIObjectType AVAILIBILITY_ZONE = - new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), AvailabilityZone.class); - public static final AAIObjectType THIRDPARTY_SDNC_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM, - "/esr-thirdparty-sdnc-list", "thirdparty-sdnc-list"); - public static final AAIObjectType THIRDPARTY_SDNC_SYSTEM_INFO_LIST = - new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-thirdparty-sdnc-list", - "/esr-thirdparty-sdnc/{sdnc-id}/esr-system-info-list", "thirdparty-sdnc-system-info-list"); - public static final AAIObjectType COMMUNICATION_SERVICE_PROFILE = - new AAIObjectType(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), CommunicationServiceProfile.class); - public static final AAIObjectType SERVICE_PROFILE = - new AAIObjectType(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), ServiceProfile.class); - public static final AAIObjectType SERVICE_PROFILE_ALL = - new AAIObjectType(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), "/service-profiles", "serviceProfiles"); - public static final AAIObjectType SLICE_PROFILE = - new AAIObjectType(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), SliceProfile.class); - public static final AAIObjectType SLICE_PROFILE_ALL = - new AAIObjectType(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), "/slice-profiles", "sliceProfiles"); - public static final AAIObjectType COMMUNICATION_PROFILE_ALL = new AAIObjectType( - AAIObjectType.SERVICE_INSTANCE.uriTemplate(), "/communication-service-profiles", "communicationProfiles"); - public static final AAIObjectType QUERY_ALLOTTED_RESOURCE = - new AAIObjectType(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), "?depth=2", "service-Instance"); - - public static final AAIObjectType LAG_INTERFACE = - new AAIObjectType(AAIObjectType.PSERVER.uriTemplate(), LagInterface.class); - - + public static final AAIObjectType SUB_L_INTERFACE = new AAIObjectType( + "/cloud-infrastructure/cloud-regions/cloud-region/{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}/l-interfaces/l-interface/{interface-name}", + "/l-interfaces/l-interface/{sub-interface-name}", "sub-l-interface"); private final String uriTemplate; private final String parentUri; @@ -346,8 +168,8 @@ public class AAIObjectType implements AAIObjectBase, GraphInventoryObjectType, S @Override public boolean equals(Object o) { - if (o instanceof AAIObjectBase) { - return this.typeName().equals(((AAIObjectBase) o).typeName()); + if (o instanceof GraphInventoryObjectName) { + return this.typeName().equals(((GraphInventoryObjectName) o).typeName()); } return false; diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java index 0aff965ac0..c31d393b36 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java @@ -20,8 +20,6 @@ package org.onap.aaiclient.client.aai; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -36,9 +34,12 @@ import org.onap.aaiclient.client.aai.entities.CustomQuery; import org.onap.aaiclient.client.aai.entities.Results; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.graphinventory.Format; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; public class AAIRestClientImpl implements AAIRestClientI { @@ -48,7 +49,7 @@ public class AAIRestClientImpl implements AAIRestClientI { @Override public List<Pserver> getPhysicalServerByVnfId(String vnfId) throws IOException { List<AAIResourceUri> startNodes = new ArrayList<>(); - startNodes.add(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); + startNodes.add(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))); String jsonInput = new AAIQueryClient().query(Format.RESOURCE, new CustomQuery(startNodes, PSERVER_VNF_QUERY)); return this.getListOfPservers(jsonInput); @@ -70,20 +71,21 @@ public class AAIRestClientImpl implements AAIRestClientI { public void updateMaintenceFlagVnfId(String vnfId, boolean inMaint) { GenericVnf genericVnf = new GenericVnf(); genericVnf.setInMaint(inMaint); - new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId), genericVnf); + new AAIResourcesClient() + .update(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId)), genericVnf); } @Override public GenericVnf getVnfByName(String vnfId) { - return new AAIResourcesClient() - .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)).orElse(null); + return new AAIResourcesClient().get(GenericVnf.class, + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))).orElse(null); } @Override public Optional<Pnf> getPnfByName(String pnfId) { - Response response = - new AAIResourcesClient().getFullResponse(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId)); + Response response = new AAIResourcesClient() + .getFullResponse(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().pnf(pnfId))); if (response.getStatus() != 200) { return Optional.empty(); } else { @@ -93,20 +95,22 @@ public class AAIRestClientImpl implements AAIRestClientI { @Override public void createPnf(String pnfId, Pnf pnf) { - new AAIResourcesClient().createIfNotExists(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId), - Optional.of(pnf)); + new AAIResourcesClient().createIfNotExists( + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().pnf(pnfId)), Optional.of(pnf)); } @Override public void updatePnf(String pnfId, Pnf pnf) { - new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId), pnf); + new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().pnf(pnfId)), + pnf); } @Override public Optional<ServiceInstance> getServiceInstanceById(String globalSubscriberId, String serviceType, String serviceInstanceId) { - Response response = new AAIResourcesClient().getFullResponse(AAIUriFactory - .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)); + Response response = new AAIResourcesClient().getFullResponse( + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId) + .serviceSubscription(serviceType).serviceInstance(serviceInstanceId))); return Optional.ofNullable(response.readEntity(ServiceInstance.class)); } @@ -114,8 +118,9 @@ public class AAIRestClientImpl implements AAIRestClientI { public void updateServiceInstance(String globalSubscriberId, String serviceType, String serviceInstanceId, ServiceInstance serviceInstance) { try { - new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, - globalSubscriberId, serviceType, serviceInstanceId), serviceInstance); + new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId)), + serviceInstance); } catch (Throwable ex) { log.error("Exception happened while updating ServiceInstance, Exception: {}", ex.getLocalizedMessage()); throw new RuntimeException(ex); diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentTypeReverseLookup.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentTypeReverseLookup.java index bd9f4c713f..95cb1fe7c2 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentTypeReverseLookup.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIFluentTypeReverseLookup.java @@ -1,5 +1,6 @@ package org.onap.aaiclient.client.aai.entities.uri; +import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -20,7 +21,7 @@ public class AAIFluentTypeReverseLookup { (Class<? extends GraphInventoryFluentType.Info>) Class .forName("org.onap.aaiclient.client.generated.fluentbuilders." + className + "$Info"); - GraphInventoryFluentType.Info type = clazz.newInstance(); + GraphInventoryFluentType.Info type = clazz.getConstructor().newInstance(); Optional<String> parentTemplate = findParentPath(type, uri); if (parentTemplate.isPresent()) { @@ -29,7 +30,8 @@ public class AAIFluentTypeReverseLookup { // fallback to enum lookup return AAIObjectType.fromTypeName(name); } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { } return AAIObjectType.UNKNOWN; } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactory.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactory.java index 6bb2cbd471..be49535f3e 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactory.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactory.java @@ -21,29 +21,43 @@ package org.onap.aaiclient.client.aai.entities.uri; import java.net.URI; +import org.onap.aaiclient.client.aai.AAIObjectName; import org.onap.aaiclient.client.aai.AAIObjectPlurals; import org.onap.aaiclient.client.aai.AAIObjectType; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; public class AAIUriFactory { + + public static final AAIFluentTypeReverseLookup reverseLookup = new AAIFluentTypeReverseLookup(); + /** * values are filled into the URI template specified in {@link AAIObjectType} in order <br> - * There are two special lookups performed on certain types when a single value is specified: <br> - * Service Instance and AllottedResources <br> - * These can be retrieved without all their required keys but an HTTP call is required to do so - * + * * @param type * @param values * @return */ public static AAIResourceUri createResourceUri(AAIObjectType type, Object... values) { - if (AAIObjectType.SERVICE_INSTANCE.equals(type)) { - return new ServiceInstanceUri(values); - } else if (AAIObjectType.ALLOTTED_RESOURCE.equals(type)) { - return new AllottedResourceLookupUri(values); + return new AAISimpleUri(type, values); + } + + /** + * These can be retrieved without all their required keys but an HTTP call is required to do so + * + * @param type + * @param values + * @return + */ + public static AAIResourceUri createResourceUri(AAISingleFragment fragment) { + + if (Types.SERVICE_INSTANCE.typeName().equals(fragment.get().build().typeName())) { + return new ServiceInstanceUri(fragment); + } else if (Types.ALLOTTED_RESOURCE.typeName().equals(fragment.get().build().typeName())) { + return new AllottedResourceLookupUri(fragment); } else { - return new AAISimpleUri(type, values); + return null; } } @@ -51,13 +65,16 @@ public class AAIUriFactory { return new AAISimpleUri(uri.build(), uri.values()); } - public static NodesSingleUri createNodesUri(AAIObjectType type, Object... values) { + protected static NodesSingleUri createNodesUri(AAIObjectType type, Object... values) { return new NodesSingleUri(type, values); + } + public static NodesSingleUri createNodesUri(AAISingleFragment fragment) { + return new NodesSingleUri(fragment.get().build(), fragment.get().values()); } - public static NodesPluralUri createNodesUri(AAIObjectPlurals type) { - return new NodesPluralUri(type); + public static NodesPluralUri createNodesUri(AAIPluralFragment fragment) { + return new NodesPluralUri(fragment.get().build()); } @@ -68,7 +85,8 @@ public class AAIUriFactory { * @param uri * @return */ - public static AAISimpleUri createResourceFromExistingURI(AAIObjectType type, URI uri) { + public static AAISimpleUri createResourceFromExistingURI(AAIObjectName name, URI uri) { + AAIObjectType type = reverseLookup.fromName(name.typeName(), uri.toString()); return new AAISimpleUri(type, uri); } @@ -81,20 +99,19 @@ public class AAIUriFactory { * @param childValues * @return */ - public static AAISimpleUri createResourceFromParentURI(AAIResourceUri parentUri, AAIObjectType childType, - Object... childValues) { + public static AAISimpleUri createResourceFromParentURI(AAIResourceUri parentUri, AAISingleFragment fragment) { - return new AAISimpleUri(parentUri, childType, childValues); + return new AAISimpleUri(parentUri, fragment.get().build(), fragment.get().values()); } - public static AAISimplePluralUri createResourceFromParentURI(AAIResourceUri parentUri, AAIObjectPlurals childType) { + public static AAISimplePluralUri createResourceFromParentURI(AAIResourceUri parentUri, AAIPluralFragment fragment) { - return new AAISimplePluralUri(parentUri, childType); + return new AAISimplePluralUri(parentUri, fragment.get().build()); } public static AAISimplePluralUri createResourceUri(AAIFluentPluralType uri) { - return new AAISimplePluralUri(uri.build()); + return new AAISimplePluralUri(uri.build(), uri.values()); } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUri.java index 7f51835580..099f717238 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUri.java @@ -25,22 +25,25 @@ import java.util.Optional; import javax.ws.rs.core.UriBuilder; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; public class AllottedResourceLookupUri extends HttpLookupUri { private static final long serialVersionUID = -9212594383876793188L; - protected AllottedResourceLookupUri(Object... values) { - super(AAIObjectType.ALLOTTED_RESOURCE, values); + protected AllottedResourceLookupUri(AAIObjectType type, UriBuilder builder, Optional<String> cachedValue, + Object... values) { + super(type, builder, cachedValue, values); } - protected AllottedResourceLookupUri(UriBuilder builder, Optional<String> cachedValue, Object... values) { - super(AAIObjectType.ALLOTTED_RESOURCE, builder, cachedValue, values); + protected AllottedResourceLookupUri(AAISingleFragment fragment) { + super(AAIFluentTypeBuilder.business().customer("").serviceSubscription("").serviceInstance("") + .allottedResource("").build(), fragment.get().values()); } @Override public AllottedResourceLookupUri clone() { - return new AllottedResourceLookupUri(this.internalURI.clone(), this.getCachedValue(), values); + return new AllottedResourceLookupUri(this.aaiType, this.internalURI.clone(), this.getCachedValue(), values); } public AAIResourcesClient getResourcesClient() { diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/HttpLookupUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/HttpLookupUri.java index c39eb50dc2..42f52565cd 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/HttpLookupUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/HttpLookupUri.java @@ -45,7 +45,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public abstract class HttpLookupUri extends AAISimpleUri implements HttpAwareUri { private transient Optional<String> cachedValue = Optional.empty(); - private final AAIObjectType aaiType; + protected final AAIObjectType aaiType; protected HttpLookupUri(AAIObjectType type, Object... values) { super(type, values); diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUri.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUri.java index 96eaac5815..366a011b14 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUri.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUri.java @@ -25,22 +25,25 @@ import java.util.Optional; import javax.ws.rs.core.UriBuilder; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; public class ServiceInstanceUri extends HttpLookupUri { private static final long serialVersionUID = 2248914170527514548L; - protected ServiceInstanceUri(Object... values) { - super(AAIObjectType.SERVICE_INSTANCE, values); + protected ServiceInstanceUri(AAIObjectType type, UriBuilder builder, Optional<String> cachedValue, + Object... values) { + super(type, builder, cachedValue, values); } - protected ServiceInstanceUri(UriBuilder builder, Optional<String> cachedValue, Object... values) { - super(AAIObjectType.SERVICE_INSTANCE, builder, cachedValue, values); + protected ServiceInstanceUri(AAISingleFragment fragment) { + super(AAIFluentTypeBuilder.business().customer("").serviceSubscription("").serviceInstance("").build(), + fragment.get().values()); } @Override public ServiceInstanceUri clone() { - return new ServiceInstanceUri(this.internalURI.clone(), this.getCachedValue(), values); + return new ServiceInstanceUri(this.aaiType, this.internalURI.clone(), this.getCachedValue(), values); } public AAIResourcesClient getResourcesClient() { diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java index 000521bdf6..12051fb07d 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIObjectTypeTest.java @@ -22,16 +22,15 @@ package org.onap.aaiclient.client.aai; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; public class AAIObjectTypeTest { @Test public void fromTypeNameTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException { - AAIObjectType type = AAIObjectType.fromTypeName("allotted-resource"); - assertEquals("allotted-resource", type.typeName()); + AAIObjectType type = AAIObjectType.fromTypeName("generic-query"); + assertEquals("generic-query", type.typeName()); } @@ -43,58 +42,14 @@ public class AAIObjectTypeTest { } @Test - public void verifyDefaultCase() { - assertEquals("default removed for tenant", "tenant", AAIObjectType.DEFAULT_TENANT.typeName()); - assertEquals("default removed for cloud-region", "cloud-region", AAIObjectType.DEFAULT_CLOUD_REGION.typeName()); - } - - @Test - public void verifyRegularCase() { - assertEquals("default removed for tenant", "allotted-resource", AAIObjectType.ALLOTTED_RESOURCE.typeName()); - } - - @Test - public void instanceGroupObjectTypeTest() { - final String id = "test1"; - AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, id); - assertEquals("/network/instance-groups/instance-group/test1", aaiUri.build().toString()); - } - - @Test - public void collectionObjectTypeTest() { - final String id = "test1"; - AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id); - assertEquals("/network/collections/collection/test1", aaiUri.build().toString()); - } - - @Test - public void genericVnfTest() { - AAIObjectType type = AAIObjectType.GENERIC_VNF; - assertEquals("/network/generic-vnfs/generic-vnf/{vnf-id}", type.uriTemplate()); - assertEquals("/generic-vnfs/generic-vnf/{vnf-id}", type.partialUri()); - } - - @Test - public void pInterfaceTest() { - AAIObjectType type = AAIObjectType.P_INTERFACE; - assertEquals("/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}", - type.uriTemplate()); - assertEquals("/p-interfaces/p-interface/{interface-name}", type.partialUri()); - } - - @Test - public void networkPolicyObjectTypeTest() { - final String id = "test1"; - AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id); - assertEquals("/network/network-policies/network-policy/test1", aaiUri.build().toString()); - } - - @Test public void equalityTest() { AAIObjectType genericVnf = AAIFluentTypeBuilder.network().genericVnf("test").build(); + AAIObjectType genericVnf2 = AAIFluentTypeBuilder.network().genericVnf("test2").build(); + + assertEquals(genericVnf2, genericVnf); - assertEquals(AAIObjectType.GENERIC_VNF, genericVnf); + assertEquals(genericVnf, Types.GENERIC_VNF); } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIQueryClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIQueryClientTest.java index 15fe03e93f..29d862478c 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIQueryClientTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIQueryClientTest.java @@ -43,17 +43,18 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Complex; -import org.onap.so.client.RestClient; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.CustomQuery; import org.onap.aaiclient.client.aai.entities.Results; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.Format; import org.onap.aaiclient.client.graphinventory.GraphInventoryClient; import org.onap.aaiclient.client.graphinventory.GraphInventorySubgraphType; import org.onap.aaiclient.client.graphinventory.entities.Pathed; import org.onap.aaiclient.client.graphinventory.entities.ResourceAndUrl; +import org.onap.so.client.RestClient; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -112,7 +113,7 @@ public class AAIQueryClientTest { doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL), any(CustomQuery.class)); List<Complex> result = aaiQueryClient.querySingleResource( - new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))), + new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(Types.COMPLEX.getFragment("test")))), Complex.class); assertEquals(2, result.size()); assertEquals("complex-id-15100-jc689q2", result.get(1).getPhysicalLocationId()); @@ -123,11 +124,10 @@ public class AAIQueryClientTest { doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL), any(CustomQuery.class)); List<ResourceAndUrl<AAIResultWrapper>> result = aaiQueryClient.getResourceAndUrl( - new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test")))); + new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(Types.COMPLEX.getFragment("test"))))); assertEquals(2, result.size()); - assertEquals(1, - result.get(1).getWrapper().getRelationships().get().getRelatedUris(AAIObjectType.PSERVER).size()); + assertEquals(1, result.get(1).getWrapper().getRelationships().get().getRelatedUris(Types.PSERVER).size()); } @Test @@ -138,7 +138,7 @@ public class AAIQueryClientTest { List<Pathed> results = aaiQueryClient.queryPathed( - new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test")))); + new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(Types.COMPLEX.getFragment("test"))))); assertEquals(2, results.size()); assertEquals("service-instance", results.get(1).getResourceType()); diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java index ca361f46d8..36ba1f3e76 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientTest.java @@ -55,6 +55,7 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.defaultproperties.DefaultAAIPropertiesImpl; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryMultipleItemsException; import org.onap.so.client.RestClient; import com.github.tomakehurst.wiremock.admin.NotFoundException; @@ -86,7 +87,7 @@ public class AAIResourcesClientTest { @Test public void verifyNotExists() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404))); AAIResourcesClient client = aaiClient; @@ -96,7 +97,7 @@ public class AAIResourcesClientTest { @Test public void verifyDelete() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("aai/resources/mockObject.json").withStatus(200))); @@ -108,7 +109,7 @@ public class AAIResourcesClientTest { @Test public void verifyBasicAuth() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test3")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) .withHeader("Authorization", equalTo("Basic dGVzdDp0ZXN0")) .willReturn(aResponse().withHeader("Content-Type", "application/json") @@ -119,8 +120,8 @@ public class AAIResourcesClientTest { @Test public void verifyConnect() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); - AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2")); + AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test3")); wireMockRule.stubFor( put(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship")) .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(200))); @@ -133,8 +134,8 @@ public class AAIResourcesClientTest { @Test public void verifyDisconnect() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); - AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2")); + AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test3")); wireMockRule.stubFor( delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship")) @@ -148,7 +149,7 @@ public class AAIResourcesClientTest { @Test public void verifyPatch() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test2")); wireMockRule.stubFor(post(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) .willReturn(aResponse().withStatus(200))); @@ -160,7 +161,7 @@ public class AAIResourcesClientTest { @Test public void verifyNotExistsGet() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404))); AAIResourcesClient client = aaiClient; @@ -170,7 +171,7 @@ public class AAIResourcesClientTest { @Test public void verifyNotExistsGetException() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())) .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404))); AAIResourcesClient client = aaiClient; @@ -181,7 +182,7 @@ public class AAIResourcesClientTest { @Test public void verifyFailedCallException() { - AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test")); wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBodyFile("aai/error-message.json").withStatus(400))); AAIResourcesClient client = aaiClient; @@ -195,7 +196,7 @@ public class AAIResourcesClientTest { @Test public void buildRelationshipTest() { AAIResourcesClient client = aaiClient; - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test")); Relationship relationship = new Relationship(); relationship.setRelatedLink(uri.build().toString()); Relationship actual = client.buildRelationship(uri); @@ -213,7 +214,7 @@ public class AAIResourcesClientTest { vnf.setVnfId("my-vnf-id"); GenericVnfs vnfs = new GenericVnfs(); vnfs.getGenericVnf().add(vnf); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); RestClient restClientMock = mock(RestClient.class); doReturn(restClientMock).when(client).createClient(uri); when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs)); @@ -232,7 +233,7 @@ public class AAIResourcesClientTest { GenericVnfs vnfs = new GenericVnfs(); vnfs.getGenericVnf().add(vnf); vnfs.getGenericVnf().add(vnf2); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); RestClient restClientMock = mock(RestClient.class); doReturn(restClientMock).when(client).createClient(uri); when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs)); @@ -250,7 +251,7 @@ public class AAIResourcesClientTest { GenericVnfs vnfs = new GenericVnfs(); vnfs.getGenericVnf().add(vnf); vnfs.getGenericVnf().add(vnf2); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); RestClient restClientMock = mock(RestClient.class); doReturn(restClientMock).when(client).createClient(uri); when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs)); @@ -266,7 +267,7 @@ public class AAIResourcesClientTest { vnf.setVnfId("my-vnf-id"); GenericVnfs vnfs = new GenericVnfs(); vnfs.getGenericVnf().add(vnf); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); RestClient restClientMock = mock(RestClient.class); doReturn(restClientMock).when(client).createClient(uri); when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.empty()); @@ -282,7 +283,7 @@ public class AAIResourcesClientTest { vnf.setVnfId("my-vnf-id"); GenericVnfs vnfs = new GenericVnfs(); vnfs.getGenericVnf().add(vnf); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); RestClient restClientMock = mock(RestClient.class); doReturn(restClientMock).when(client).createClient(uri); when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.empty()); @@ -295,7 +296,7 @@ public class AAIResourcesClientTest { @Test public void testGetFirstWrongPluralClass() { GenericVnf vnf = new GenericVnf(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); RestClient restClientMock = mock(RestClient.class); doReturn(restClientMock).when(client).createClient(uri); when(restClientMock.get(GenericVnf.class)).thenReturn(Optional.of(vnf)); diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java index 9e0825bbb5..23c06a6817 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java @@ -45,6 +45,7 @@ import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri; import org.onap.aaiclient.client.defaultproperties.DefaultAAIPropertiesImpl; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import com.github.tomakehurst.wiremock.junit.WireMockRule; @RunWith(MockitoJUnitRunner.class) @@ -70,7 +71,7 @@ public class AAIResourcesClientWithServiceInstanceUriTest { wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*")).willReturn( aResponse().withStatus(404).withHeader("Content-Type", "application/json").withHeader("Mock", "true"))); - uri = spy((ServiceInstanceUri) AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id")); + uri = spy((ServiceInstanceUri) AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("id"))); doReturn(aaiClient).when(uri).getResourcesClient(); } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAISingleTransactionClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAISingleTransactionClientTest.java index 0820397fd6..7035999a69 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAISingleTransactionClientTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAISingleTransactionClientTest.java @@ -49,6 +49,7 @@ import org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactio import org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.graphinventory.GraphInventoryPatchConverter; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; @@ -60,9 +61,12 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class AAISingleTransactionClientTest { private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/singletransaction/"; - AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "pserver-hostname"); - AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex"); - AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex2"); + AAIResourceUri uriA = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver("pserver-hostname")); + AAIResourceUri uriB = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().complex("my-complex")); + AAIResourceUri uriC = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().complex("my-complex2")); ObjectMapper mapper; diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAITransactionalClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAITransactionalClientTest.java index bf2417141f..cda119ef13 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAITransactionalClientTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAITransactionalClientTest.java @@ -45,6 +45,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.Relationship; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.graphinventory.GraphInventoryPatchConverter; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; @@ -56,13 +57,13 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class AAITransactionalClientTest { private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/bulkprocess/"; - AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test2"); - AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); - AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4"); - AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5"); - AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6"); - AAIResourceUri uriG = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test7"); + AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")); + AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver("test2")); + AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test3")); + AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver("test4")); + AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test5")); + AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver("test6")); + AAIResourceUri uriG = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test7")); ObjectMapper mapper; diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIURITest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIURITest.java index f2bd188ab3..7fad6f512f 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIURITest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/AAIURITest.java @@ -25,6 +25,7 @@ import javax.ws.rs.core.UriBuilder; import org.junit.Test; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; public class AAIURITest { @@ -33,8 +34,9 @@ public class AAIURITest { @Test public void verifyTemplateReplacement() { final String id = "test1"; - AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id); - String manualReplace = AAIObjectType.CONFIGURATION.toString().replaceAll("\\{configuration-id\\}", id); + AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().configuration(id)); + String manualReplace = + AAIFluentTypeBuilder.network().configuration(id).uriTemplate().replaceAll("\\{configuration-id\\}", id); assertEquals("uri template replaced", aaiUri.build(), UriBuilder.fromPath(manualReplace).build()); } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java index b0b0c6aca9..4b5085edf2 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/DSLQueryBuilderTest.java @@ -23,6 +23,7 @@ package org.onap.aaiclient.client.aai; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.entities.DSLNodeKey; import org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder; import org.onap.aaiclient.client.graphinventory.entities.DSLStartNode; @@ -36,12 +37,11 @@ public class DSLQueryBuilderTest { @Test public void whereTest() { - DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(AAIObjectType.CLOUD_REGION, + DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(Types.CLOUD_REGION, __.key("cloud-owner", "att-nc"), __.key("cloud-region-id", "test"))); - builder.to(__.node(AAIObjectType.VLAN_TAG)) - .where(__.node(AAIObjectType.OWNING_ENTITY, __.key("owning-entity-name", "name"))) - .to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", "108")).output()); + builder.to(__.node(Types.VLAN_TAG)).where(__.node(Types.OWNING_ENTITY, __.key("owning-entity-name", "name"))) + .to(__.node(Types.VLAN_TAG, __.key("vlan-id-outer", "108")).output()); assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > " + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > " + "vlan-tag*('vlan-id-outer', '108')", @@ -50,12 +50,11 @@ public class DSLQueryBuilderTest { @Test public void unionTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); - builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()), - __.node(AAIObjectType.VSERVER) - .to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()))); + builder.union(__.node(Types.PSERVER).output().to(__.node(Types.COMPLEX).output()), + __.node(Types.VSERVER).to(__.node(Types.PSERVER).output().to(__.node(Types.COMPLEX).output()))); assertEquals( "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]", @@ -64,11 +63,11 @@ public class DSLQueryBuilderTest { @Test public void whereUnionTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); - builder.where(__.union(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")), - __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1"))))); + builder.where(__.union(__.node(Types.PSERVER, __.key("hostname", "hostname1")), + __.node(Types.VSERVER).to(__.node(Types.PSERVER, __.key("hostname", "hostname1"))))); assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), " + "vserver > pserver('hostname', 'hostname1') ])", builder.build().get()); @@ -76,38 +75,38 @@ public class DSLQueryBuilderTest { @Test public void notNullTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder.traversal( - new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "", "null").not()).output()); + DSLQueryBuilder<Output, Output> builder = TraversalBuilder + .traversal(new DSLStartNode(Types.CLOUD_REGION, __.key("cloud-owner", "", "null").not()).output()); assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build().get()); } @Test public void shortCutToTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.PSERVER, __.key("hostname", "my-hostname")).output()); - builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id")); + builder.to(Types.P_INTERFACE).to(Types.SRIOV_PF, __.key("pf-pci-id", "my-id")); assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')", builder.build().get()); } @Test public void limitTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.PSERVER, __.key("hostname", "my-hostname")).output()); - builder.to(AAIObjectType.P_INTERFACE).limit(2).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id")); + builder.to(Types.P_INTERFACE).limit(2).to(Types.SRIOV_PF, __.key("pf-pci-id", "my-id")); assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id') LIMIT 2", builder.build().get()); } @Test public void equalsTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output()); + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.PSERVER, __.key("hostname", "my-hostname")).output()); - builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id")); + builder.to(Types.P_INTERFACE).to(Types.SRIOV_PF, __.key("pf-pci-id", "my-id")); assertTrue( builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')")); assertTrue(builder.equals(builder)); @@ -115,32 +114,30 @@ public class DSLQueryBuilderTest { @Test public void mixedTypeTest() { - DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(AAIObjectType.CLOUD_REGION, - __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id"))); - builder.to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output()); + DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment( + new DSLStartNode(Types.CLOUD_REGION, __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id"))); + builder.to(__.node(Types.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output()); assertTrue(builder.equals( "cloud-region('cloud-owner', 'owner')('cloud-region-id', 'id') > vlan-tag*('vlan-id-outer', 167)('my-boolean', true)")); } @Test public void outputOnNodeLambdasTest() { - DSLQueryBuilder<Start, Start> builder = TraversalBuilder - .fragment(new DSLStartNode(AAIObjectType.L_INTERFACE, new DSLNodeKey("interface-id", "myId"))); + DSLQueryBuilder<Start, Start> builder = + TraversalBuilder.fragment(new DSLStartNode(Types.L_INTERFACE, new DSLNodeKey("interface-id", "myId"))); - builder.to(AAIObjectType.VSERVER, __.key("vserver-name", "myName")).output().to(AAIObjectType.P_INTERFACE) - .output(); + builder.to(Types.VSERVER, __.key("vserver-name", "myName")).output().to(Types.P_INTERFACE).output(); assertEquals("l-interface('interface-id', 'myId') > vserver*('vserver-name', 'myName') > p-interface*", builder.build().get()); } @Test public void skipOutputOnUnionTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.GENERIC_VNF, __.key("vnf-id", "vnfId")).output()); - builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()), - __.node(AAIObjectType.VSERVER) - .to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()))) + builder.union(__.node(Types.PSERVER).output().to(__.node(Types.COMPLEX).output()), + __.node(Types.VSERVER).to(__.node(Types.PSERVER).output().to(__.node(Types.COMPLEX).output()))) .output(); assertEquals( @@ -150,10 +147,10 @@ public class DSLQueryBuilderTest { @Test public void selectOutputFilterTest() { - DSLQueryBuilder<Output, Output> builder = TraversalBuilder - .traversal(new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "CloudOwner")) + DSLQueryBuilder<Output, Output> builder = + TraversalBuilder.traversal(new DSLStartNode(Types.CLOUD_REGION, __.key("cloud-owner", "CloudOwner")) .output("cloud-region-id", "a", "b")); - builder.to(__.node(AAIObjectType.PSERVER)).output("x", "y", "z"); + builder.to(__.node(Types.PSERVER)).output("x", "y", "z"); assertEquals("cloud-region{'cloud-region-id', 'a', 'b'}('cloud-owner', 'CloudOwner') > pserver{'x', 'y', 'z'}", builder.build().toString()); @@ -161,7 +158,7 @@ public class DSLQueryBuilderTest { @Test public void selectOutputFilterOnNodeTest() { - DSLStartNode node = new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "CloudOwner")); + DSLStartNode node = new DSLStartNode(Types.CLOUD_REGION, __.key("cloud-owner", "CloudOwner")); DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(node).output("cloud-region-id"); assertEquals("cloud-region{'cloud-region-id'}('cloud-owner', 'CloudOwner')", builder.build().toString()); diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java index 9e106fab85..75dbd4aea2 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/RelationshipsTest.java @@ -30,9 +30,10 @@ import java.util.List; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; public class RelationshipsTest { @@ -45,12 +46,16 @@ public class RelationshipsTest { AAIResultWrapper wrapper = new AAIResultWrapper(content); Relationships relationships = wrapper.getRelationships().get(); - List<AAIResourceUri> test = relationships.getRelatedUris(AAIObjectType.VCE); + List<AAIResourceUri> test = relationships.getRelatedUris(Types.VCE); List<AAIResourceUri> uris = Arrays.asList( - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a9fec18e-1ea3-40e4-a6c0-a89b3de07053"), - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "8ae1e5f8-61f1-4c71-913a-b40cc4593cb9"), - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a2935fa9-b743-49f4-9813-a127f13c4e93"), - AAIUriFactory.createResourceUri(AAIObjectType.VCE, "c7fe7698-8063-4e26-8bd3-ca3edde0b0d4")); + AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.network().vce("a9fec18e-1ea3-40e4-a6c0-a89b3de07053")), + AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.network().vce("8ae1e5f8-61f1-4c71-913a-b40cc4593cb9")), + AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.network().vce("a2935fa9-b743-49f4-9813-a127f13c4e93")), + AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.network().vce("c7fe7698-8063-4e26-8bd3-ca3edde0b0d4"))); assertTrue(uris.containsAll(test) && test.containsAll(uris)); @@ -67,14 +72,14 @@ public class RelationshipsTest { ArgumentCaptor<AAIResourceUri> argument = ArgumentCaptor.forClass(AAIResourceUri.class); doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture()); - spy.getByType(AAIObjectType.VCE, uri -> uri.nodesOnly(true)); + spy.getByType(Types.VCE, uri -> uri.nodesOnly(true)); assertTrue(argument.getAllValues().stream().allMatch(item -> item.build().toString().contains("nodes-only"))); argument = ArgumentCaptor.forClass(AAIResourceUri.class); doReturn(new AAIResultWrapper("{}")).when(spy).get(argument.capture()); - spy.getByType(AAIObjectType.VCE); + spy.getByType(Types.VCE); assertTrue(argument.getAllValues().stream().allMatch(item -> !item.build().toString().contains("?"))); diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java index 3823392b01..e8c84c02ff 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java @@ -22,7 +22,8 @@ package org.onap.aaiclient.client.aai.entities.uri; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.onap.aaiclient.client.aai.AAIObjectType; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; public class AAISimpleUriFromParentUriTest { @@ -30,10 +31,10 @@ public class AAISimpleUriFromParentUriTest { @Test public void appendChildren() { - AAIResourceUri parentUri = - AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "key1", "key2", "key3"); + AAIResourceUri parentUri = AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.business().customer("key1").serviceSubscription("key2").serviceInstance("key3")); - AAIResourceUri uri = new AAISimpleUri(parentUri, AAIObjectType.ALLOTTED_RESOURCE, "key4"); + AAIResourceUri uri = new AAISimpleUri(parentUri, Types.ALLOTTED_RESOURCE.getFragment("").get().build(), "key4"); assertEquals("path appended", "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4", diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromUriTest.java index 9030789cfd..3c8b2e8743 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriFromUriTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import javax.ws.rs.core.UriBuilder; import org.junit.Test; import org.onap.aaiclient.client.aai.AAIObjectType; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; public class AAISimpleUriFromUriTest { @@ -66,10 +67,11 @@ public class AAISimpleUriFromUriTest { @Test public void beforeBuildEquality() { - AAIResourceUri uri = new AAISimpleUri(AAIObjectType.VCE, + AAIResourceUri uri = new AAISimpleUri(AAIFluentTypeBuilder.network().vce("").build(), UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build()); - AAIResourceUri uri2 = new AAISimpleUri(AAIObjectType.VCE, "a9f ec18e-1ea3-40e4-a6c0-a89b3de07053"); + AAIResourceUri uri2 = new AAISimpleUri(AAIFluentTypeBuilder.network().vce("").build(), + "a9f ec18e-1ea3-40e4-a6c0-a89b3de07053"); assertEquals("are equal", uri2, uri); } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java index 92e74163a7..6382be4a92 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAISimpleUriTest.java @@ -29,8 +29,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Map; import org.junit.Test; -import org.onap.aaiclient.client.aai.AAIObjectPlurals; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.entities.uri.Depth; @@ -41,14 +39,14 @@ public class AAISimpleUriTest { @Test public void relatedToTestPlural() { - AAIPluralResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")) + .relatedTo(Types.PSERVERS.getFragment()); String uriOutput = uri.build().toString(); String expected = "/network/generic-vnfs/generic-vnf/test1/related-to/pservers"; assertEquals(expected, uriOutput); - uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") + uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")) .relatedTo(Types.PSERVERS.getFragment()); uriOutput = uri.build().toString(); assertEquals(expected, uriOutput); @@ -56,14 +54,14 @@ public class AAISimpleUriTest { @Test public void relatedToTestSingular() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") - .relatedTo(AAIObjectType.PSERVER, "test2"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")) + .relatedTo(Types.PSERVER.getFragment("test2")); String uriOutput = uri.build().toString(); String expected = "/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2"; assertEquals(expected, uriOutput); - uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") + uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")) .relatedTo(Types.PSERVER.getFragment("test2")); uriOutput = uri.build().toString(); @@ -74,7 +72,7 @@ public class AAISimpleUriTest { @Test public void cloneTestSingular() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")); AAIResourceUri cloned = uri.clone(); assertEquals("/network/generic-vnfs/generic-vnf/test1", cloned.build().toString()); @@ -85,31 +83,31 @@ public class AAISimpleUriTest { @Test public void cloneTestPlural() { - AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); + AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()); AAISimplePluralUri cloned = uri.clone(); assertEquals("/network/generic-vnfs", cloned.build().toString()); } @Test public void cloneTestWithRelatedTo() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") - .relatedTo(AAIObjectType.PSERVER, "test2"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")) + .relatedTo(Types.PSERVER.getFragment("test2")); String uriOutput = uri.clone().build().toString(); assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2", uriOutput); } @Test public void cloneTestPluralWithRelatedTo() { - AAIPluralResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")) + .relatedTo(Types.PSERVERS.getFragment()); String uriOutput = uri.clone().build().toString(); assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput); } @Test public void getKeysTest() { - AAIResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure() + .cloudRegion("cloud1", "cloud2").tenant("tenant1").vserver("vserver1")); Map<String, String> keys = uri.getURIKeys(); System.out.println(keys); System.out.println(uri.build()); @@ -118,8 +116,8 @@ public class AAISimpleUriTest { @Test public void getEncodedKeyTest() { - AAIResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("test1") + .serviceSubscription("my value").serviceInstance("test3")); Map<String, String> keys = uri.getURIKeys(); assertEquals("my value", keys.get("service-type")); @@ -127,7 +125,7 @@ public class AAISimpleUriTest { @Test public void serializeTest() throws IOException, ClassNotFoundException { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test1")); uri.depth(Depth.ONE); uri.limit(1); diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactoryTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactoryTest.java index ec40b1b477..87517369c3 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactoryTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AAIUriFactoryTest.java @@ -22,15 +22,16 @@ package org.onap.aaiclient.client.aai.entities.uri; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.onap.aaiclient.client.aai.AAIObjectPlurals; -import org.onap.aaiclient.client.aai.AAIObjectType; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; public class AAIUriFactoryTest { @Test public void testCreateResourceUri() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + AAIResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("VIP(VelocitytoIP)")); String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; assertEquals(expected, uri.build().toString()); @@ -39,7 +40,7 @@ public class AAIUriFactoryTest { @Test public void testCreateNodesUri() { - AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + AAIResourceUri uri = AAIUriFactory.createNodesUri(Types.GENERIC_VNF.getFragment("VIP(VelocitytoIP)")); String expected = "/nodes/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; assertEquals(expected, uri.build().toString()); @@ -48,8 +49,9 @@ public class AAIUriFactoryTest { @Test public void testCreateResourceFromExistingURI() { - AAIResourceUri uri = new AAISimpleUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); - AAIResourceUri uri2 = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.GENERIC_VNF, uri.build()); + AAIResourceUri uri = + new AAISimpleUri(AAIFluentTypeBuilder.network().genericVnf("").build(), "VIP(VelocitytoIP)"); + AAIResourceUri uri2 = AAIUriFactory.createResourceFromExistingURI(Types.GENERIC_VNF, uri.build()); String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; assertEquals(expected, uri2.build().toString()); @@ -58,11 +60,20 @@ public class AAIUriFactoryTest { @Test public void testCreateResourceURIForPluralsWithValues() { - AAIPluralResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType"); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer("customerId").serviceSubscription("serviceType").serviceInstances()); String expected = "/business/customers/customer/customerId/service-subscriptions/service-subscription/serviceType/service-instances"; assertEquals(expected, uri.build().toString()); } + + @Test + public void testCreateResourceURIForPluralsWithNoValues() { + + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customers()); + + String expected = "/business/customers"; + assertEquals(expected, uri.build().toString()); + } } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUriTest.java index e6add8cbc1..eb59173c9f 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/AllottedResourceLookupUriTest.java @@ -29,6 +29,7 @@ import java.net.URI; import java.net.URISyntaxException; import javax.ws.rs.core.UriBuilder; import org.junit.Test; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPayloadException; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException; @@ -38,7 +39,7 @@ public class AllottedResourceLookupUriTest { public void oneKey() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - AllottedResourceLookupUri instance = new AllottedResourceLookupUri("key1"); + AllottedResourceLookupUri instance = new AllottedResourceLookupUri(Types.ALLOTTED_RESOURCE.getFragment("key1")); AllottedResourceLookupUri spy = spy(instance); doReturn( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4") diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java deleted file mode 100644 index 2cbf5bb090..0000000000 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2019 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========================================================= - */ - -package org.onap.aaiclient.client.aai.entities.uri; - -import static org.hamcrest.CoreMatchers.equalTo; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.aaiclient.client.aai.AAIObjectPlurals; -import org.onap.aaiclient.client.aai.AAIObjectType; -import org.onap.aaiclient.client.graphinventory.exceptions.IncorrectNumberOfUriKeys; - -public class IncorrectNumberOfUriKeysTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void verifyIncorrectNumberOfKeysSingle() { - - thrown.expect(IncorrectNumberOfUriKeys.class); - thrown.expectMessage(equalTo("Expected 3 variables: [cloud-owner, cloud-region-id, volume-group-id]")); - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, "volume-group-id"); - - } - - @Test - public void verifyIncorrectNumberOfKeysPlural() { - - thrown.expect(IncorrectNumberOfUriKeys.class); - AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, "my-cloud-owner"); - - } - - @Test - public void verifyIncorrectNumberOfKeysFromParent() { - - thrown.expect(IncorrectNumberOfUriKeys.class); - AAIResourceUri parentUri = - AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "my-cloud-owner", "my-cloud-region-id"); - AAIResourceUri uri = AAIUriFactory.createResourceFromParentURI(parentUri, AAIObjectType.VOLUME_GROUP); - } - - @Test - public void verifyIncorrectNumberOfKeysHttpAware() { - - thrown.expect(IncorrectNumberOfUriKeys.class); - AAIResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "customer-id", "subscription-id"); - } -} diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUriTest.java index 514a349095..6a1b459e6f 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUriTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/aai/entities/uri/ServiceInstanceUriTest.java @@ -56,10 +56,10 @@ import org.mockito.InjectMocks; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aaiclient.client.aai.AAIClient; -import org.onap.aaiclient.client.aai.AAIObjectPlurals; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.defaultproperties.DefaultAAIPropertiesImpl; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryPayloadException; import org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriComputationException; @@ -93,7 +93,7 @@ public class ServiceInstanceUriTest { final String content = new String( Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json"))); - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3")); final Optional<String> result = instance.extractRelatedLink(content); final String expected = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; @@ -105,7 +105,7 @@ public class ServiceInstanceUriTest { public void oneKey() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); doReturn( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3") @@ -123,7 +123,7 @@ public class ServiceInstanceUriTest { public void oneKeyQueryParams() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); doReturn( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3") @@ -141,7 +141,7 @@ public class ServiceInstanceUriTest { public void oneKeyEncoded() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); doReturn( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space") @@ -159,7 +159,7 @@ public class ServiceInstanceUriTest { public void oneKeyGetKeys() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); doReturn( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space") @@ -171,7 +171,7 @@ public class ServiceInstanceUriTest { @Test public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; @@ -184,23 +184,11 @@ public class ServiceInstanceUriTest { } @Test - public void threeKey() throws IOException { - - ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3"); - final URI result = instance.build(); - final URI expected = UriBuilder.fromPath( - "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3") - .build(); - assertEquals("result is equal", expected, result); - - } - - @Test public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json"))); - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3")); ServiceInstanceUri spy = spy(instance); AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class); AAIResultWrapper wrapper = mock(AAIResultWrapper.class); @@ -214,17 +202,8 @@ public class ServiceInstanceUriTest { } @Test - public void cloneTest() { - ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3"); - final URI result = instance.build(); - final URI result2 = instance.clone().queryParam("something", "new").build(); - assertEquals("uris are not equal", false, result.toString().equals(result2.toString())); - - } - - @Test public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3")); ServiceInstanceUri spy = spy(instance); AAIResourcesClient client = aaiClient; doReturn(client).when(spy).getResourcesClient(); @@ -238,7 +217,7 @@ public class ServiceInstanceUriTest { @Test public void serializeTest() throws IOException, ClassNotFoundException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key3"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3")); final String content = new String( Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json"))); @@ -274,13 +253,14 @@ public class ServiceInstanceUriTest { @Test public void relatedToTest() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); doReturn( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3") .when(spy).getObjectById(any(Object.class)); - final URI result = spy.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", "my-vnf-name").build(); + final URI result = + spy.relatedTo(Types.GENERIC_VNFS.getFragment()).queryParam("vnf-name", "my-vnf-name").build(); final URI expected = UriBuilder.fromUri( "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/related-to/generic-vnfs?vnf-name=my-vnf-name") .build(); @@ -290,11 +270,11 @@ public class ServiceInstanceUriTest { @Test public void relatedToEqualityTestBeforeBuildTest() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException { - ServiceInstanceUri instance = new ServiceInstanceUri("key1"); + ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key1")); ServiceInstanceUri spy = spy(instance); final AAIPluralResourceUri result = - spy.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", "my-vnf-name"); + spy.relatedTo(Types.GENERIC_VNFS.getFragment()).queryParam("vnf-name", "my-vnf-name"); assertEquals("result is equal", result, result); } diff --git a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java index 270aca072c..7b3e80fa46 100644 --- a/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java +++ b/graph-inventory/aai-client/src/test/java/org/onap/aaiclient/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java @@ -23,9 +23,7 @@ package org.onap.aaiclient.client.graphinventory.entities.uri.parsers; import static org.junit.Assert.assertEquals; import java.util.Map; import org.junit.Test; -import org.onap.aaiclient.client.aai.AAIObjectType; -import org.onap.aaiclient.client.graphinventory.entities.uri.parsers.UriParser; -import org.onap.aaiclient.client.graphinventory.entities.uri.parsers.UriParserSpringImpl; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; public class UriParserSpringImplTest { @@ -33,7 +31,8 @@ public class UriParserSpringImplTest { @Test public void reverseTemplate() { - final UriParser parser = new UriParserSpringImpl(AAIObjectType.SERVICE_INSTANCE.toString()); + final UriParser parser = new UriParserSpringImpl( + AAIFluentTypeBuilder.business().customer("").serviceSubscription("").serviceInstance("").uriTemplate()); final String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; |