diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2025-01-21 14:27:53 +0100 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2025-01-21 19:01:36 +0100 |
commit | a72a615025afe0e93ee14e5b144538df65176e2c (patch) | |
tree | 93da1b085ec21d51b5a2daba10f4dc3056f78855 | |
parent | d0ea368346b68a85696f4a0dac8b1e02c446b64d (diff) |
Dependency inject Retrofit client to simplify api declaration15.0.1
- centrally declare AAI rest client [0]
- add integration test to assert http request to AAI
- do not ignore test failure
[0] this has the advantage, that
- headers are defined for all requests via interceptor
- this is the correct setup to add tracing to the app with a later change
- credentials for AAI can be centrally configured (it is now configurable in the latest AAI version)
Issue-ID: USECASEUI-857
Change-Id: I5ef0e859e3bc2ab4b42fe6ed27632c211b90ac62
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | server/pom.xml | 25 | ||||
-rw-r--r-- | server/src/main/java/org/onap/usecaseui/server/config/AAIClientConfig.java | 74 | ||||
-rw-r--r-- | server/src/main/java/org/onap/usecaseui/server/config/intent/IntentScheduleTask.java (renamed from server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java) | 2 | ||||
-rw-r--r-- | server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java | 358 | ||||
-rw-r--r-- | server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java | 88 | ||||
-rw-r--r-- | server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceIntegrationTest.java | 83 | ||||
-rw-r--r-- | server/src/test/resources/__files/customersResponse.json | 10 |
8 files changed, 257 insertions, 385 deletions
@@ -33,3 +33,5 @@ build/ ### VS Code ###
.vscode/
/bin/
+toPath
+server/logs
diff --git a/server/pom.xml b/server/pom.xml index 65622ff9..bf60ab8d 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -64,6 +64,16 @@ </dependency> <dependency> <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.wiremock.integrations</groupId> + <artifactId>wiremock-spring-boot</artifactId> + <version>3.0.3</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> <exclusion> @@ -203,13 +213,12 @@ </exclusion> </exclusions> </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - <version>4.13.2</version> - </dependency> + <!-- TODO: Migrate tests to junit 5 and remove this dependency --> + <dependency> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>com.sun.activation</groupId> <artifactId>jakarta.activation</artifactId> @@ -350,7 +359,7 @@ <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> - <testFailureIgnore>true</testFailureIgnore> + <testFailureIgnore>false</testFailureIgnore> <includes> <include>**/*Spec*</include> <include>**/Test*.java</include> diff --git a/server/src/main/java/org/onap/usecaseui/server/config/AAIClientConfig.java b/server/src/main/java/org/onap/usecaseui/server/config/AAIClientConfig.java new file mode 100644 index 00000000..f27a72e5 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/config/AAIClientConfig.java @@ -0,0 +1,74 @@ +/** + * Copyright 2025 Deutsche Telekom. + * + * 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. + */ + +package org.onap.usecaseui.server.config; + +import java.io.IOException; + +import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; + +import okhttp3.Credentials; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +@Configuration +public class AAIClientConfig { + + @Value("${client.aai.baseUrl}") + String baseUrl; + @Value("${client.aai.username}") + String username; + @Value("${client.aai.password}") + String password; + + @Bean + OkHttpClient okHttpClient() { + return new OkHttpClient().newBuilder().addInterceptor(new Interceptor() { + @Override + public okhttp3.Response intercept(Chain chain) throws IOException { + Request originalRequest = chain.request(); + Request.Builder builder = originalRequest.newBuilder() + .header("Authorization", Credentials.basic(username, password)) + .header(HttpHeaders.ACCEPT, "application/json") + .header("X-TransactionId", "7777") + .header("X-FromAppId", "uui"); + Request newRequest = builder.build(); + return chain.proceed(newRequest); + } + }).build(); + } + + @Bean + Retrofit retrofit(OkHttpClient okHttpClient) { + return new Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(JacksonConverterFactory.create()) + .client(okHttpClient) + .build(); + } + + @Bean + AAIService aaiService(Retrofit retrofit) { + return retrofit.create(AAIService.class); + } +} diff --git a/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java b/server/src/main/java/org/onap/usecaseui/server/config/intent/IntentScheduleTask.java index e727d1cc..79089cbf 100644 --- a/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java +++ b/server/src/main/java/org/onap/usecaseui/server/config/intent/IntentScheduleTask.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.usecaseui.server.conf.intent; +package org.onap.usecaseui.server.config.intent; import org.onap.usecaseui.server.service.intent.IntentInstanceService; import org.springframework.context.annotation.Configuration; diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java index d6c53ef4..f9f55405 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/aai/AAIService.java @@ -33,453 +33,159 @@ import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.DELETE; import retrofit2.http.GET; -import retrofit2.http.Headers; import retrofit2.http.PUT; import retrofit2.http.Path; import retrofit2.http.Query; public interface AAIService { - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + // @GET("/api/aai-business/v11/customers") @GET("/api/aai-business/v13/customers") Call<AAICustomerRsp> listCustomer(); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-externalSystem/v16/esr-nfvo-list") Call<AAIOrchestratorRsp> listOrchestrator(); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-externalSystem/v16/esr-nfvo-list/esr-nfvo/{nfvo-id}?depth=all") Call<AAISingleOrchestratorRsp> getOrchestrator(@Path("nfvo-id") String nfvoId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @PUT("/api/aai-business/v13/customers/customer/{global-customer-id}") Call<ResponseBody> createOrUpdateCustomer(@Path("global-customer-id") String customerId,@Body RequestBody body); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @DELETE("/api/aai-business/v13//customers/customer/{global-customer-id}") Call<ResponseBody> deleteCustomer(@Path("global-customer-id") String customerId,@Query("resource-version") String resourceVersion); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-business/v13//customers/customer/{global-customer-id}") Call<AAICustomer> getCustomerById(@Path("global-customer-id") String customerId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + // @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances") @GET("/api/aai-business/v16/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances") Call<ResponseBody> listServiceInstances(@Path("global-customer-id") String customerId, @Path("service-type") String serviceType); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) // @GET("/cloud-infrastructure/cloud-regions") @GET("/api/aai-cloudInfrastructure/v11/cloud-regions") Call<VimInfoRsp> listVimInfo(); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) // @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions") @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions") Call<ServiceSubscriptionRsp> listServiceSubscriptions(@Path("global-customer-id") String customerId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + //@GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions") @PUT("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}") Call<ResponseBody> createOrUpdateServiceType(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType,@Body RequestBody body); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + //@GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions") @DELETE("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}") Call<ResponseBody> deleteServiceType(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType,@Query("resource-version") String resourceVersion); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + //@GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions") @GET("/api/aai-business/v11/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}") Call<AAIServiceSubscription> getServiceTypeById(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-externalSystem/v11/esr-thirdparty-sdnc-list") Call<SDNCControllerRsp> listSdncControllers(); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-business/v11/customers/customer/{customerId}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{serviceId}") Call<ResponseBody> getAAIServiceInstance(@Path("customerId") String customerId,@Path("service-type") String seviceType,@Path("serviceId") String serviceId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-network/v14/network-resources") Call<ResponseBody> listNetWorkResources(); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-network/v14/pnfs/pnf/{pnfName}/p-interfaces") Call<PinterfaceRsp> getPinterfaceByPnfName(@Path("pnfName") String pnfName); - - @Headers({ - "X-TransactionId: 9999", - "X-FromAppId: MSO", - "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", - "Accept: application/json" - }) + @GET("/aai/v24/network/logical-links") Call<ResponseBody> getLogicalLinks(); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-network/v14/logical-links/logical-link/{link-name}") Call<ResponseBody> getSpecificLogicalLink(@Path("link-name") String linkName); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @PUT("/api/aai-network/v14/network-resources/network-resource/{networkId}") Call<ResponseBody> createTopoNetwork(@Body RequestBody body,@Path("networkId") String networkId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @PUT("/api/aai-network/v14/ext-aai-networks/ext-aai-network/{aai-id}") Call<ResponseBody> createHostUrl(@Body RequestBody body,@Path("aai-id") String aaiId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-network/v14/ext-aai-networks/ext-aai-network/{aai-id}") Call<ResponseBody> getExtAaiId(@Path("aai-id") String aaiId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-network/v14/ext-aai-networks/ext-aai-network/{aai-id}/esr-system-info") Call<ResponseBody> getHostUrl(@Path("aai-id") String aaiId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @PUT("/api/aai-network/v14/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{tp-id}") Call<ResponseBody> createTerminationPoint(@Body RequestBody body,@Path("pnfName") String pnfName,@Path("tp-id") String tpId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @PUT("/api/aai-network/v14/pnfs/pnf/{pnfname}") Call<ResponseBody> createPnf(@Body RequestBody body,@Path("pnfname") String pnfname); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @PUT("/api/aai-network/v14/logical-links/logical-link/{linkName}") Call<ResponseBody> createLink(@Body RequestBody body,@Path("linkName") String linkName); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @DELETE("/api/aai-network/v14/logical-links/logical-link/{linkName}") Call<ResponseBody> deleteLink(@Path("linkName") String linkName,@Query("resource-version") String resourceVersion); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-business/v14/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances") Call<ResponseBody> getServiceInstances(@Path("global-customer-id") String customerId,@Path("service-type") String serviceType); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-business/v14/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances") Call<ResponseBody> serviceInstaneInfo(@Path("global-customer-id") String globalCustomerId,@Path("service-type") String serviceType,@Query("service-instance-id") String serviceInstanceId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-business/v14/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/allotted-resources") Call<ResponseBody> getAllottedResources(@Path("global-customer-id") String globalCustomerId,@Path("service-type") String serviceType,@Path("service-instance-id") String serviceInstanceId); - - @Headers({ - "X-TransactionId: 9999", - "X-FromAppId: MSO", - "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", - "Accept: application/json" - }) + @GET("/aai/v24/network/pnfs") Call<ResponseBody> getPnfInfo(@Query("pnfName") String pnfName); - - @Headers({ - "X-TransactionId: 9999", - "X-FromAppId: MSO", - "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", - "Accept: application/json" - }) + @GET("/aai/v24/network/connectivities") Call<ResponseBody> getConnectivityInfo(@Query("connectivity-id") String connectivityId); - @Headers({ - "X-TransactionId: 9999", - "X-FromAppId: MSO", - "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", - "Accept: application/json" - }) @GET("/aai/v24/network/vpn-bindings") Call<ResponseBody> getVpnBindingInfo(@Query("vpn-id") String vpnId); - @Headers({ - "X-TransactionId: 9999", - "X-FromAppId: MSO", - "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", - "Accept: application/json" - }) @GET("/aai/v24/network/network-routes") Call<ResponseBody> getNetworkRouteInfo(@Query("route-id") String routeId); - @Headers({ - "X-TransactionId: 9999", - "X-FromAppId: MSO", - "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", - "Accept: application/json" - }) @GET("/aai/v24/network/unis") Call<ResponseBody> getUniInfo(@Query("uni-id") String uniId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @GET("/api/aai-network/v14/vpn-bindings") Call<ResponseBody> getPinterfaceByVpnId(@Query("vpn-id") String vpnId); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @DELETE("/api/aai-network/v14/ext-aai-networks/ext-aai-network/{aai-id}") Call<ResponseBody> deleteExtNetwork(@Path("aai-id") String aaiId,@Query("resource-version") String resourceVersion); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @PUT("/api/aai-query/v19?format=resource") Call<ResponseBody> querynNetworkResourceList(@Body RequestBody body); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-business/v14/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}") Call<ResponseBody> getServiceInstancesForEdge(@Path("global-customer-id") String globalCustomerId,@Path("service-type") String serviceType, @Path("service-instance-id") String serviceinstanceid); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @GET("/api/aai-network/v14/connectivities/connectivity") Call<ResponseBody> getConnectivityInformation(@Query("connectivity-id") String connectivityId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @GET("/api/aai-network/v14/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{tp-id}") Call<ResponseBody> getTerminationPoint(@Path("pnfName") String pnfName,@Path("tp-id") String tpId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @GET("/api/aai-business/v16/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/allotted-resources/allotted-resource/{allotted-resource-id}") Call<ResponseBody> getAllotedResourceFor5G(@Path("global-customer-id") String globalCustomerId,@Path("service-type") String serviceType, @Path("service-instance-id") String serviceinstanceid,@Path("allotted-resource-id") String allottedResourceId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) + @GET("/api/aai-network/v14/site-resources/site-resource/{site-resource-id}") Call<ResponseBody> getSiteResourceInfo(@Path("site-resource-id") String siteResourceId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @GET("/api/aai-cloudInfrastructure/v14/complexes/complex/{complex-id}") Call<ResponseBody> getComplexObject(@Path("complex-id") String complexId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) - @GET("/api/aai-business/v14/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances") Call<ResponseBody> getAllServiceInformation(@Path("global-customer-id") String customerId, @Path("service-type") String serviceType); -// @Headers({ -// "X-TransactionId: 7777", -// "X-FromAppId: uui", -// "Authorization: Basic QUFJOkFBSQ==", -// "Accept: application/json" -// }) -// @GET("/api/aai-network/v14/pnfs/pnf/{pnfName}") -// Call<ResponseBody> getPnfInfo(@Path("pnfName") String pnfName); - - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) @GET("/api/aai-business/v13/customers/customer/{global-customer-id}/service-subscriptions") Call<ResponseBody> getServiceSubscription(@Path("global-customer-id") String customerID); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) - @GET("/aai/v19/network/generic-vnfs/generic-vnf/{vnf-id}") Call<ResponseBody> getVNFsDetail(@Path("vnf-id") String vnfId); - @Headers({ - "X-TransactionId: 7777", - "X-FromAppId: uui", - "Authorization: Basic QUFJOkFBSQ==", - "Accept: application/json" - }) - @GET("/aai/v19/network/unis/uni/{uni-id}") Call<ResponseBody> getUNIInfo(@Path("uni-id") String uniId); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java index 8291307a..59eb4707 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerService.java @@ -26,10 +26,6 @@ import org.onap.usecaseui.server.service.lcm.domain.aai.bean.Results; import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAINetworkInterfaceResponse; import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException; -import org.onap.usecaseui.server.util.RestfulServices; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSONObject; @@ -48,23 +44,15 @@ import java.util.List; import java.util.ArrayList; import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service("CustomerService") -@org.springframework.context.annotation.Configuration -@EnableAspectJAutoProxy +@RequiredArgsConstructor public class DefaultCustomerService implements CustomerService { - private static final Logger logger = LoggerFactory.getLogger(DefaultCustomerService.class); - - private AAIService aaiService; - - public DefaultCustomerService() { - this(RestfulServices.create(AAIService.class)); - } - - public DefaultCustomerService(AAIService aaiService) { - this.aaiService = aaiService; - } + private final AAIService aaiService; @Override public List<AAICustomer> listCustomer() { @@ -73,23 +61,23 @@ public class DefaultCustomerService implements CustomerService { if (response.isSuccessful()) { return response.body().getCustomer(); } else { - logger.info(String.format("Can not get customers[code=%s, message=%s]", response.code(), response.message())); + log.info(String.format("Can not get customers[code=%s, message=%s]", response.code(), response.message())); return Collections.emptyList(); } } catch (IOException e) { - logger.error("list customers occur exception"); + log.error("list customers occur exception"); throw new AAIException("AAI is not available.", e); } } - + @Override public JSONObject createOrUpdateCustomer(HttpServletRequest request,String customerId){ JSONObject result = new JSONObject(); try { - logger.info("aai createOrUpdateCustomer is starting!"); + log.info("aai createOrUpdateCustomer is starting!"); RequestBody requestBody = extractBody(request); Response<ResponseBody> response = this.aaiService.createOrUpdateCustomer(customerId,requestBody).execute(); - logger.info("aai createOrUpdateCustomer is finished!"); + log.info("aai createOrUpdateCustomer is finished!"); if(response.isSuccessful()){ result.put("status", "SUCCESS"); }else{ @@ -102,14 +90,14 @@ public class DefaultCustomerService implements CustomerService { } return result; } - + @Override public JSONObject getCustomerById(String customerId){ JSONObject result = new JSONObject(); try { - logger.info("aai getCustomerById is starting!"); + log.info("aai getCustomerById is starting!"); Response<AAICustomer> response = this.aaiService.getCustomerById(customerId).execute(); - logger.info("aai getCustomerById is finished!"); + log.info("aai getCustomerById is finished!"); if(response.isSuccessful()){ result.put("status", "SUCCESS"); result.put("result",response.body()); @@ -123,14 +111,14 @@ public class DefaultCustomerService implements CustomerService { } return result; } - + @Override public JSONObject deleteCustomer(String customerId,String resourceVersion){ JSONObject result = new JSONObject(); try { - logger.info("aai deleteCustomer is starting!"); + log.info("aai deleteCustomer is starting!"); Response<ResponseBody> response = this.aaiService.deleteCustomer(customerId,resourceVersion).execute(); - logger.info("aai deleteCustomer is finished!"); + log.info("aai deleteCustomer is finished!"); if(response.isSuccessful()){ result.put("status", "SUCCESS"); }else{ @@ -146,7 +134,7 @@ public class DefaultCustomerService implements CustomerService { } return result; } - + @Override public List<AAIServiceSubscription> listServiceSubscriptions(String serviceType) { try { @@ -154,23 +142,23 @@ public class DefaultCustomerService implements CustomerService { if (response.isSuccessful()) { return response.body().getServiceSubscriptions(); } else { - logger.info(String.format("Can not get service-subscriptions[code=%s, message=%s]", response.code(), response.message())); + log.info(String.format("Can not get service-subscriptions[code=%s, message=%s]", response.code(), response.message())); return Collections.emptyList(); } } catch (IOException e) { - logger.error("list customers occur exception"); + log.error("list customers occur exception"); throw new AAIException("AAI is not available.", e); } } - + @Override public JSONObject createOrUpdateServiceType(HttpServletRequest request,String serviceType,String customerId){ JSONObject result = new JSONObject(); try { - logger.info("aai createOrUpdateServiceType is starting!"); + log.info("aai createOrUpdateServiceType is starting!"); RequestBody requestBody = extractBody(request); Response<ResponseBody> response = this.aaiService.createOrUpdateServiceType(customerId,serviceType,requestBody).execute(); - logger.info("aai createOrUpdateServiceType is finished!"); + log.info("aai createOrUpdateServiceType is finished!"); if(response.isSuccessful()){ result.put("status", "SUCCESS"); }else{ @@ -183,14 +171,14 @@ public class DefaultCustomerService implements CustomerService { } return result; } - + @Override public JSONObject deleteServiceType(String customerId,String serviceType,String resourceVersion){ JSONObject result = new JSONObject(); try { - logger.info("aai deleteServiceType is starting!"); + log.info("aai deleteServiceType is starting!"); Response<ResponseBody> response = this.aaiService.deleteServiceType(customerId,serviceType,resourceVersion).execute(); - logger.info("aai deleteServiceType is finished!"); + log.info("aai deleteServiceType is finished!"); if(response.isSuccessful()){ result.put("status", "SUCCESS"); }else{ @@ -206,15 +194,15 @@ public class DefaultCustomerService implements CustomerService { } return result; } - + @Override public JSONObject getServiceTypeById(String customerId, String serviceType) { JSONObject result = new JSONObject(); try { - logger.info("aai getServiceTypeById is starting!"); + log.info("aai getServiceTypeById is starting!"); Response<AAIServiceSubscription> response = this.aaiService.getServiceTypeById(customerId, serviceType).execute(); - logger.info("aai getServiceTypeById is finished!"); + log.info("aai getServiceTypeById is finished!"); if (response.isSuccessful()) { result.put("status", "SUCCESS"); result.put("result", response.body()); @@ -229,7 +217,7 @@ public class DefaultCustomerService implements CustomerService { } return result; } - + @Override public List<String> fetchNIList(String networkInterfaceType) { List<String> niList = new ArrayList<String>(); @@ -237,19 +225,19 @@ public class DefaultCustomerService implements CustomerService { ObjectMapper mapper = new ObjectMapper(); Results[] interfaceList = null; try { - logger.info("aai fetchNIList is starting!"); + log.info("aai fetchNIList is starting!"); String body = "{\r\n" + "\"start\" : [\"network\"],\r\n" + "\"query\" : \"query/getInterfaceTypes?porttype=" + networkInterfaceType + "\"\r\n" + "}"; - logger.info("request body {} for Interface type {}" , body,networkInterfaceType); + log.info("request body {} for Interface type {}" , body,networkInterfaceType); RequestBody request = RequestBody.create(MediaType.parse("application/json"), body); Response<ResponseBody> response = this.aaiService.querynNetworkResourceList(request).execute(); if (response.isSuccessful()) { String jsonResponse = response.body().string(); - logger.info("response json returned {}", jsonResponse); + log.info("response json returned {}", jsonResponse); try { niResponse = mapper.readValue(jsonResponse, AAINetworkInterfaceResponse.class); } catch (IOException ex) { - logger.info("read value exception", ex); + log.info("read value exception", ex); } if (niResponse != null) { interfaceList = niResponse.getResults(); @@ -259,13 +247,13 @@ public class DefaultCustomerService implements CustomerService { niList.add(pInterface.getInterfaceName() + " (" + pInterface.getPortDescription() + ")"); } } else { - logger.error("Request to AAI Fails dues to {} " , response.errorBody()); + log.error("Request to AAI Fails dues to {} " , response.errorBody()); throw new IOException(response.errorBody().toString()); } } catch (Exception e) { niResponse = null; - logger.info("Request to AAI Fails dues to " + e); - logger.info("Mocking Response Data"); + log.info("Request to AAI Fails dues to " + e); + log.info("Mocking Response Data"); String jsonMock = "{\r\n" + " \"results\": [\r\n" + " {\r\n" + " \"p-interface\": {\r\n" @@ -315,7 +303,7 @@ public class DefaultCustomerService implements CustomerService { try { niResponse = mapper.readValue(jsonMock, AAINetworkInterfaceResponse.class); } catch (IOException ex) { - logger.info("ReadValue exception", ex); + log.info("ReadValue exception", ex); } if (niResponse != null) { @@ -325,7 +313,7 @@ public class DefaultCustomerService implements CustomerService { PInterface pInterface = result.getPinterface(); niList.add(pInterface.getInterfaceName()); } - + } Collections.sort(niList); return niList; diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceIntegrationTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceIntegrationTest.java new file mode 100644 index 00000000..a1908a52 --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceIntegrationTest.java @@ -0,0 +1,83 @@ +/** + * Copyright 2025 Deutsche Telekom. + * + * 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. + */ + +package org.onap.usecaseui.server.service.lcm.impl; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.onap.usecaseui.server.config.AAIClientConfig; +import org.onap.usecaseui.server.controller.lcm.CustomerController; +import org.onap.usecaseui.server.service.lcm.CustomerService; +import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.HttpHeaders; +import org.wiremock.spring.EnableWireMock; + +@EnableWireMock +@SpringBootTest( + webEnvironment = WebEnvironment.RANDOM_PORT, + classes = { + AAIClientConfig.class, DefaultCustomerService.class, CustomerController.class + }, + properties = { + "spring.main.web-application-type=none", // only temporary + "client.aai.baseUrl=${wiremock.server.baseUrl}", + "client.aai.username=AAI", + "client.aai.password=AAI" + }) +public class DefaultCustomerServiceIntegrationTest { + + @Autowired + CustomerService customerService; + + @Value("${client.aai.username}") + String username; + + @Value("${client.aai.password}") + String password; + + @Test + void thatAAIRequestsAreCorrect() { + stubFor( + get("/api/aai-business/v13/customers") + .withBasicAuth(username, password) + .withHeader(HttpHeaders.ACCEPT, equalTo("application/json")) + .withHeader("X-TransactionId", equalTo("7777")) + .withHeader("X-FromAppId", equalTo("uui")) + .willReturn( + aResponse().withBodyFile("customersResponse.json") + )); + + List<AAICustomer> customers = customerService.listCustomer(); + assertNotNull(customers); + assertEquals(1, customers.size()); + assertEquals("someCustomer", customers.get(0).getGlobalCustomerId()); + assertEquals("someSubscriber", customers.get(0).getSubscriberName()); + assertEquals("someType", customers.get(0).getSubscriberType()); + assertEquals("abcd", customers.get(0).getResourceVersion()); + } +} diff --git a/server/src/test/resources/__files/customersResponse.json b/server/src/test/resources/__files/customersResponse.json new file mode 100644 index 00000000..6a827fc5 --- /dev/null +++ b/server/src/test/resources/__files/customersResponse.json @@ -0,0 +1,10 @@ +{ + "customer": [ + { + "global-customer-id": "someCustomer", + "subscriber-name": "someSubscriber", + "subscriber-type": "someType", + "resource-version": "abcd" + } + ] +} |