Skip to content

Commit

Permalink
GH2883 Move ServicesInfoService to the apiml-common (#3056)
Browse files Browse the repository at this point in the history
Signed-off-by: alexandr cumarav <alexandr.cumarav@broadcom.com>
Co-authored-by: alexandr cumarav <alexandr.cumarav@broadcom.com>
  • Loading branch information
cumarav and cumarav authored Aug 30, 2023
1 parent fabb80f commit 281d543
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.services;
package org.zowe.apiml.product.services;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.netflix.appinfo.InstanceInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.services;
package org.zowe.apiml.product.services;

import com.fasterxml.jackson.core.Version;
import com.netflix.appinfo.InstanceInfo;
Expand All @@ -17,7 +17,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.zowe.apiml.auth.Authentication;
import org.zowe.apiml.config.ApiInfo;
Expand All @@ -28,7 +27,14 @@
import org.zowe.apiml.product.routing.transform.TransformService;
import org.zowe.apiml.product.routing.transform.URLTransformationException;

import java.util.*;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.groupingBy;
Expand All @@ -37,16 +43,15 @@
import static org.zowe.apiml.constants.EurekaMetadataDefinition.SERVICE_TITLE;

@Slf4j
@Service
@RequiredArgsConstructor
public class ServicesInfoService {

public static final String VERSION_HEADER = "Content-Version";
public static final String CURRENT_VERSION = "1";

private final EurekaClient eurekaClient;
private final GatewayConfigProperties gatewayConfigProperties;
private final EurekaMetadataParser eurekaMetadataParser;
private final GatewayConfigProperties gatewayConfigProperties;
private final TransformService transformService;

public List<ServiceInfo> getServicesInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.services;
package org.zowe.apiml.product.services;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
Expand All @@ -21,24 +21,37 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.env.ConfigurableEnvironment;
import org.zowe.apiml.auth.AuthenticationScheme;
import org.zowe.apiml.config.ApiInfo;
import org.zowe.apiml.eurekaservice.client.util.EurekaMetadataParser;
import org.zowe.apiml.gateway.config.GatewayConfig;
import org.zowe.apiml.product.gateway.GatewayClient;
import org.zowe.apiml.product.gateway.GatewayConfigProperties;
import org.zowe.apiml.product.routing.transform.TransformService;

import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.*;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.AUTHENTICATION_APPLID;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.AUTHENTICATION_SCHEME;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.ROUTES;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.ROUTES_GATEWAY_URL;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.ROUTES_SERVICE_URL;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.SERVICE_DESCRIPTION;
import static org.zowe.apiml.constants.EurekaMetadataDefinition.SERVICE_TITLE;

@ExtendWith(MockitoExtension.class)
class ServicesInfoServiceTest {
Expand Down Expand Up @@ -81,23 +94,20 @@ class ServicesInfoServiceTest {
private static final String SERVICE_SERVICE_ID = "serviceId";
private static final String SERVICE_API_ID = "apiId";
private static final String SERVICE_API_VERSION = "version";

@Mock
private EurekaClient eurekaClient;

@Mock
ConfigurableEnvironment env;
private final GatewayConfigProperties gatewayConfigProperties = GatewayConfigProperties.builder()
.scheme(GW_SCHEME).hostname(GW_HOSTNAME + ":" + GW_PORT).build();

private final GatewayConfigProperties gatewayConfigProperties = new GatewayConfig(env)
.getGatewayConfigProperties(GW_HOSTNAME, GW_PORT, GW_SCHEME);
private final EurekaMetadataParser eurekaMetadataParser = new EurekaMetadataParser();
private final TransformService transformService = new TransformService(new GatewayClient(gatewayConfigProperties));

private ServicesInfoService servicesInfoService;

@BeforeEach
void setUp() {
servicesInfoService = new ServicesInfoService(eurekaClient, gatewayConfigProperties, eurekaMetadataParser, transformService);
servicesInfoService = new ServicesInfoService(eurekaClient, eurekaMetadataParser, gatewayConfigProperties, transformService);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@

package org.zowe.apiml.gateway.services;

import com.netflix.discovery.EurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zowe.apiml.eurekaservice.client.util.EurekaMetadataParser;
import org.zowe.apiml.product.gateway.GatewayConfigProperties;
import org.zowe.apiml.product.routing.transform.TransformService;
import org.zowe.apiml.product.services.ServicesInfoService;

@Configuration
public class ServerInfoConfig {
Expand All @@ -22,4 +26,11 @@ public EurekaMetadataParser getEurekaMetadataParser() {
return new EurekaMetadataParser();
}


@Bean
public ServicesInfoService servicesInfoService(EurekaClient eurekaClient,
EurekaMetadataParser eurekaMetadataParser, GatewayConfigProperties gatewayConfigProperties, TransformService transformService) {
return new ServicesInfoService(eurekaClient, eurekaMetadataParser, gatewayConfigProperties, transformService);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.RequiredArgsConstructor;
import org.springframework.http.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.zowe.apiml.product.services.ServiceInfo;
import org.zowe.apiml.product.services.ServicesInfoService;

import java.util.List;

import static org.zowe.apiml.gateway.services.ServicesInfoService.CURRENT_VERSION;
import static org.zowe.apiml.gateway.services.ServicesInfoService.VERSION_HEADER;
import static org.zowe.apiml.product.services.ServicesInfoService.CURRENT_VERSION;
import static org.zowe.apiml.product.services.ServicesInfoService.VERSION_HEADER;


@RestController
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpStatus;
import org.zowe.apiml.product.services.ServiceInfo;
import org.zowe.apiml.product.services.ServicesInfoService;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -24,8 +26,8 @@
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.when;
import static org.zowe.apiml.gateway.services.ServicesInfoController.SERVICES_URL;
import static org.zowe.apiml.gateway.services.ServicesInfoService.CURRENT_VERSION;
import static org.zowe.apiml.gateway.services.ServicesInfoService.VERSION_HEADER;
import static org.zowe.apiml.product.services.ServicesInfoService.CURRENT_VERSION;
import static org.zowe.apiml.product.services.ServicesInfoService.VERSION_HEADER;

@ExtendWith(MockitoExtension.class)
class ServicesInfoControllerTest {
Expand Down

0 comments on commit 281d543

Please sign in to comment.