Skip to content

Commit

Permalink
fix: merge and cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Salac <[email protected]>
  • Loading branch information
richard-salac committed Feb 4, 2025
1 parent eb297df commit 7f3f1b0
Show file tree
Hide file tree
Showing 67 changed files with 800 additions and 856 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
image: ghcr.io/balhar-jakub/api-catalog-services-standalone:${{ github.run_id }}-${{ github.run_number }}
volumes:
- /api-defs:/api-defs
env:
APIML_SERVICE_HOSTNAME: api-catalog-services-2
APIML_HEALTH_PROTECTED: false
api-catalog-services:
image: ghcr.io/balhar-jakub/api-catalog-services:${{ github.run_id }}-${{ github.run_number }}
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

package org.zowe.apiml.apicatalog.config;

import org.zowe.apiml.message.core.MessageService;
import org.zowe.apiml.product.gateway.GatewayClient;
import org.zowe.apiml.product.routing.transform.TransformService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.zowe.apiml.message.core.MessageService;
import org.zowe.apiml.message.yaml.YamlMessageServiceInstance;
import org.zowe.apiml.product.gateway.GatewayClient;
import org.zowe.apiml.product.routing.transform.TransformService;

/**
* General configuration of the API Catalog.
Expand All @@ -25,7 +26,9 @@ public class BeanConfig {

@Bean
@Primary
public MessageService messageServiceCatalog(MessageService messageService) {
public MessageService messageServiceCatalog() {
MessageService messageService = YamlMessageServiceInstance.getInstance();
messageService.loadMessages("/security-client-log-messages.yml");
messageService.loadMessages("/utility-log-messages.yml");
messageService.loadMessages("/common-log-messages.yml");
messageService.loadMessages("/security-common-log-messages.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public ResponseEntity<List<String>> getOidcProvider() {
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "204", description = "No service available"),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "403", description = "Forbidden"),
@ApiResponse(responseCode = "404", description = "URI not found"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -68,6 +69,7 @@
@EnableApimlAuth
@EnableMethodSecurity
@EnableConfigurationProperties(SafSecurityConfigurationProperties.class)
@ConditionalOnProperty(value = "apiml.catalog.standalone.enabled", havingValue = "false", matchIfMissing = true)
public class SecurityConfiguration {
private static final String APIDOC_ROUTES = "/apidoc/**";
private static final String STATIC_REFRESH_ROUTE = "/static-api/refresh";
Expand Down Expand Up @@ -130,7 +132,7 @@ private UserDetailsService x509UserDetailsService() {
}

private CategorizeCertsFilter reversedCategorizeCertFilter() {
CategorizeCertsFilter out = new CategorizeCertsFilter(publicKeyCertificatesBase64, certificateValidator, handlerInitializer.getUnAuthorizedHandler().getHandler(), false);
CategorizeCertsFilter out = new CategorizeCertsFilter(publicKeyCertificatesBase64, certificateValidator);
out.setCertificateForClientAuth(crt -> out.getPublicKeyCertificatesBase64().contains(CategorizeCertsFilter.base64EncodePublicKey(crt)));
out.setApimlCertificate(crt -> !out.getPublicKeyCertificatesBase64().contains(CategorizeCertsFilter.base64EncodePublicKey(crt)));
return out;
Expand Down Expand Up @@ -299,4 +301,5 @@ private OidcContentFilter oidcFilter(AuthenticationManager authenticationManager
public LogoutSuccessHandler logoutSuccessHandler() {
return new ApiCatalogLogoutSuccessHandler(authConfigurationProperties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
package org.zowe.apiml.apicatalog.services.status.listeners;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.zowe.apiml.apicatalog.instance.InstanceInitializeService;
import org.zowe.apiml.product.gateway.GatewayLookupCompleteEvent;
import org.zowe.apiml.product.registry.CannotRegisterServiceException;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* This class fires on GatewayLookupCompleteEvent event
* Initializes Catalog instances from Eureka
*/
@Slf4j
@Component
@ConditionalOnProperty(
value = "apiml.catalog.standalone.enabled",
Expand All @@ -39,10 +40,15 @@ public class GatewayLookupEventListener {
private final AtomicBoolean hasRun = new AtomicBoolean(false);

@EventListener(GatewayLookupCompleteEvent.class)
public void onApplicationEvent() throws CannotRegisterServiceException {
public void onApplicationEvent() {
if (!hasRun.get()) {
hasRun.set(true);
instanceInitializeService.retrieveAndRegisterAllInstancesWithCatalog();
try {
instanceInitializeService.retrieveAndRegisterAllInstancesWithCatalog();
} catch (Exception e) {
hasRun.set(false);
log.debug("Unexpected error occurred while initial retrieving of services: {}", e.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package org.zowe.apiml.apicatalog.controllers.api;

import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.zowe.apiml.apicatalog.controllers.handlers.ApiCatalogControllerExceptionHandler;
import org.zowe.apiml.apicatalog.services.cached.CachedProductFamilyService;
Expand All @@ -21,11 +20,13 @@

class ApiCatalogControllerContainerRetrievalTestContextConfiguration {

@MockBean
private CachedProductFamilyService cachedProductFamilyService;
@Bean
public CachedProductFamilyService cachedProductFamilyService() {
return mock(CachedProductFamilyService.class);
}

@Bean
public ApiCatalogController apiCatalogController() {
public ApiCatalogController apiCatalogController(CachedProductFamilyService cachedProductFamilyService) {
when(cachedProductFamilyService.getAllContainers())
.thenThrow(new NullPointerException());

Expand All @@ -43,4 +44,5 @@ public MessageService messageService() {
public ApiCatalogControllerExceptionHandler apiCatalogControllerExceptionHandler() {
return new ApiCatalogControllerExceptionHandler(messageService());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package org.zowe.apiml.apicatalog.controllers.api;

import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.zowe.apiml.apicatalog.controllers.handlers.CatalogApiDocControllerExceptionHandler;
import org.zowe.apiml.apicatalog.services.status.APIServiceStatusService;
Expand All @@ -22,11 +21,13 @@

class CatalogApiDocControllerApiDocNotFoundTestContextConfiguration {

@MockBean
private APIServiceStatusService apiServiceStatusService;
@Bean
public APIServiceStatusService apiServiceStatusService() {
return mock(APIServiceStatusService.class);
}

@Bean
public CatalogApiDocController catalogApiDocController() {
public CatalogApiDocController catalogApiDocController(APIServiceStatusService apiServiceStatusService) {
when(apiServiceStatusService.getServiceCachedApiDocInfo("service2", "v1"))
.thenThrow(new ApiDocNotFoundException("Really bad stuff happened"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package org.zowe.apiml.apicatalog.controllers.api;

import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.zowe.apiml.apicatalog.controllers.handlers.CatalogApiDocControllerExceptionHandler;
import org.zowe.apiml.apicatalog.services.status.APIServiceStatusService;
Expand All @@ -22,11 +21,13 @@

class CatalogApiDocControllerServiceNotFoundTestContextConfiguration {

@MockBean
private APIServiceStatusService apiServiceStatusService;
@Bean
public APIServiceStatusService apiServiceStatusService() {
return mock(APIServiceStatusService.class);
}

@Bean
public CatalogApiDocController catalogApiDocController() {
public CatalogApiDocController catalogApiDocController(APIServiceStatusService apiServiceStatusService) {
when(apiServiceStatusService.getServiceCachedApiDocInfo("service1", "v1"))
.thenThrow(new ServiceNotFoundException("API Documentation not retrieved, The service is running."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
Expand All @@ -27,6 +26,7 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand Down Expand Up @@ -72,9 +72,13 @@ void whenPostRequest() throws Exception {

@Configuration
@Profile("test")
@SpyBean(ExampleService.class)
static class Context {

@Bean
public ExampleService exampleService() {
return spy(new ExampleService());
}

@Bean
public MockController mockController(ExampleService exampleService) {
return new MockController(exampleService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
Expand All @@ -26,11 +25,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

@ExtendWith(SpringExtension.class)
@ActiveProfiles("test")
Expand Down Expand Up @@ -82,11 +77,13 @@ private ConfigurableApplicationContext mockContext(ApplicationReadyEvent event,
@Profile("test")
public static class TestConfiguration {

@MockBean
private StandaloneLoaderService standaloneLoaderService;
@Bean
public StandaloneLoaderService standaloneLoaderService() {
return mock(StandaloneLoaderService.class);
}

@Bean
public StandaloneInitializer getStandaloneInitializer() {
public StandaloneInitializer getStandaloneInitializer(StandaloneLoaderService standaloneLoaderService) {
return new StandaloneInitializer(standaloneLoaderService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.zowe.apiml.apicatalog.staticapi;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,6 +26,7 @@
import org.zowe.apiml.apicatalog.services.status.model.ServiceNotFoundException;

import static org.hamcrest.Matchers.hasSize;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand All @@ -46,6 +48,11 @@ class StaticAPIRefreshControllerTest {
@Autowired
private StaticAPIService staticAPIService;

@BeforeEach
void setUp() {
reset(staticAPIService);
}

@Test
void givenServiceNotFoundException_whenCallRefreshAPI_thenResponseShouldBe503WithSpecificMessage() throws Exception {
when(staticAPIService.refresh()).thenThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

package org.zowe.apiml.apicatalog.staticapi;

import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.zowe.apiml.message.core.MessageService;
import org.zowe.apiml.message.yaml.YamlMessageService;

import static org.mockito.Mockito.mock;

public class StaticApiContextConfiguration {

@MockBean
private StaticAPIService staticAPIService;
@Bean
public StaticAPIService staticAPIService() {
return mock(StaticAPIService.class);
}

@Bean
public MessageService messageService() {
Expand All @@ -31,20 +34,22 @@ public StaticAPIRefreshControllerExceptionHandler staticAPIRefreshControllerExce
}

@Bean
public StaticAPIRefreshController apiCatalogController() {
public StaticAPIRefreshController apiCatalogController(StaticAPIService staticAPIService) {
return new StaticAPIRefreshController(staticAPIService);
}

@MockBean
private StaticDefinitionGenerator staticDefinitionGenerator;
@Bean
public StaticDefinitionGenerator staticDefinitionGenerator() {
return mock(StaticDefinitionGenerator.class);
}

@Bean
public StaticDefinitionControllerExceptionHandler staticDefinitionControllerExceptionHandler(MessageService messageService) {
return new StaticDefinitionControllerExceptionHandler(messageService);
}

@Bean
public StaticDefinitionController staticAPIRefreshController() {
public StaticDefinitionController staticAPIRefreshController(StaticDefinitionGenerator staticDefinitionGenerator) {
return new StaticDefinitionController(staticDefinitionGenerator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("Swagger rendering", () => {
.should('exist');

cy.get('@swaggerContainer')
.get('div.information-container > section > div > div.info > .main')
.get('div.information-container > section div.info .main')
.as('mainInfo');

cy.get('@mainInfo').should('exist');
Expand Down
Loading

0 comments on commit 7f3f1b0

Please sign in to comment.