Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.apicatalog.config;


/**
* Enum representing internal API Layer services
* Used to identify services that are part of API Layer itself
*/
public enum ApiLayerServices {
DISCOVERY("discovery"),
GATEWAY("gateway"),
APIML("apiml"),
ZAAS("zaas"),
API_CATALOG("apicatalog"),
CACHING_SERVICE("cachingservice"),
IBMZOSMF("ibmzosmf"),
ZSS("zss");

private final String serviceId;

ApiLayerServices(String serviceId) {
this.serviceId = serviceId;
}

public String getServiceId() {
return serviceId;
}

public static boolean isApiLayerService(String serviceId) {
if (serviceId == null || serviceId.trim().isEmpty()) {
return false;
}
String normalizedServiceId = serviceId.toLowerCase().trim();
for (ApiLayerServices service : ApiLayerServices.values()) {
if (service.serviceId.equals(normalizedServiceId)) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.zowe.apiml.apicatalog.config.ApiLayerServices;
import org.zowe.apiml.apicatalog.model.APIContainer;
import org.zowe.apiml.apicatalog.model.APIService;
import org.zowe.apiml.apicatalog.model.CustomStyleConfig;
Expand Down Expand Up @@ -286,7 +287,9 @@ private String getInstanceHomePageUrl(InstanceInfo instanceInfo) {
routes,
isAttlsEnabled);
} catch (URLTransformationException | IllegalArgumentException e) {
apimlLog.log("org.zowe.apiml.apicatalog.homePageTransformFailed", instanceInfo.getAppName(), e.getMessage());
if (!ApiLayerServices.isApiLayerService(instanceInfo.getAppName())) {
apimlLog.log("org.zowe.apiml.apicatalog.homePageTransformFailed", instanceInfo.getAppName(), e.getMessage());
}
}
}

Expand All @@ -310,7 +313,9 @@ private String getApiBasePath(InstanceInfo instanceInfo) {
instanceInfo.getHomePageUrl(),
routes);
} catch (URLTransformationException e) {
apimlLog.log("org.zowe.apiml.apicatalog.getApiBasePathFailed", instanceInfo.getAppName(), e.getMessage());
if (!ApiLayerServices.isApiLayerService(instanceInfo.getAppName())) {
apimlLog.log("org.zowe.apiml.apicatalog.getApiBasePathFailed", instanceInfo.getAppName(), e.getMessage());
}
}
}
return apiBasePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ messages:

- key: org.zowe.apiml.apicatalog.homePageTransformFailed
number: ZWEAC705
type: WARNING
type: DEBUG
text: "The home page url for service %s was not transformed. %s"
reason: "The home page url for service was not transformed. The original url will be used."
action: "Refer to the specific printed message. Possible causes include:\n
Expand All @@ -111,7 +111,7 @@ messages:

- key: org.zowe.apiml.apicatalog.getApiBasePathFailed
number: ZWEAC708
type: ERROR
type: DEBUG
text: "The API base path for service %s was not retrieved. %s"
reason: "The API base path for service was not retrieved. An empty path will be used."
action: "Refer to the specific printed message. Possible causes include:\n
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.apicatalog.util;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import org.zowe.apiml.apicatalog.config.ApiLayerServices;

import static org.junit.jupiter.api.Assertions.*;

class ApiLayerServicesTest {

@Test
void testEnumConstruction_shouldHaveCorrectServiceIds() {
assertEquals("discovery", ApiLayerServices.DISCOVERY.getServiceId());
assertEquals("gateway", ApiLayerServices.GATEWAY.getServiceId());
assertEquals("apiml", ApiLayerServices.APIML.getServiceId());
assertEquals("zaas", ApiLayerServices.ZAAS.getServiceId());
assertEquals("apicatalog", ApiLayerServices.API_CATALOG.getServiceId());
assertEquals("cachingservice", ApiLayerServices.CACHING_SERVICE.getServiceId());
assertEquals("ibmzosmf", ApiLayerServices.IBMZOSMF.getServiceId());
assertEquals("zss", ApiLayerServices.ZSS.getServiceId());
}

@Test
void testToString_shouldReturnEnumConstantName() {
assertEquals("DISCOVERY", ApiLayerServices.DISCOVERY.toString());
assertEquals("GATEWAY", ApiLayerServices.GATEWAY.toString());
}

@ParameterizedTest
@ValueSource(strings = {"discovery", "DISCOVERY", "Discovery", " discovery ", "DiScOvErY"})
void testIsApiLayerService_withDiscoveryVariants_shouldReturnTrue(String input) {
boolean result = ApiLayerServices.isApiLayerService(input);
assertTrue(result, "Should recognize '" + input + "' as an API Layer service");
}

@ParameterizedTest
@NullAndEmptySource
@ValueSource(strings = {" ", " "})
void testIsApiLayerService_withNullOrEmptyOrBlank_shouldReturnFalse(String input) {
boolean result = ApiLayerServices.isApiLayerService(input);
assertFalse(result, "Should not recognize null or empty string as an API Layer service");
}

@ParameterizedTest
@ValueSource(strings = {"unknown", "discoveryservice", "gateways", "api", "catalog", "caching", "notaservice", "external-service"})
void testIsApiLayerService_withNonApiLayerServices_shouldReturnFalse(String input) {
boolean result = ApiLayerServices.isApiLayerService(input);
assertFalse(result, "Should not recognize '" + input + "' as an API Layer service");
}
}