|
| 1 | +/* |
| 2 | + * Copyright 2012-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.actuate.sbom.SbomEndpoint; |
| 22 | +import org.springframework.boot.actuate.sbom.SbomEndpointWebExtension; |
| 23 | +import org.springframework.boot.actuate.sbom.SbomProperties; |
| 24 | +import org.springframework.context.annotation.Bean; |
| 25 | +import org.springframework.context.annotation.Configuration; |
| 26 | +import org.springframework.context.annotation.Import; |
| 27 | +import org.springframework.core.io.ResourceLoader; |
| 28 | +import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; |
| 29 | + |
| 30 | +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; |
| 31 | +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; |
| 32 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 33 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 34 | + |
| 35 | +/** |
| 36 | + * Tests for generating documentation describing the {@link SbomEndpoint}. |
| 37 | + * |
| 38 | + * @author Moritz Halbritter |
| 39 | + */ |
| 40 | +class SbomEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { |
| 41 | + |
| 42 | + @Test |
| 43 | + void sbom() throws Exception { |
| 44 | + this.mockMvc.perform(get("/actuator/sbom")) |
| 45 | + .andExpect(status().isOk()) |
| 46 | + .andDo(MockMvcRestDocumentation.document("sbom", |
| 47 | + responseFields(fieldWithPath("ids").description("An array of available SBOM ids.")))); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void sboms() throws Exception { |
| 52 | + this.mockMvc.perform(get("/actuator/sbom/application")) |
| 53 | + .andExpect(status().isOk()) |
| 54 | + .andDo(MockMvcRestDocumentation.document("sbom/id")); |
| 55 | + } |
| 56 | + |
| 57 | + @Configuration(proxyBeanMethods = false) |
| 58 | + @Import(BaseDocumentationConfiguration.class) |
| 59 | + static class TestConfiguration { |
| 60 | + |
| 61 | + @Bean |
| 62 | + SbomProperties sbomProperties() { |
| 63 | + SbomProperties properties = new SbomProperties(); |
| 64 | + properties.getApplication().setLocation("classpath:sbom/cyclonedx.json"); |
| 65 | + return properties; |
| 66 | + } |
| 67 | + |
| 68 | + @Bean |
| 69 | + SbomEndpoint endpoint(SbomProperties properties, ResourceLoader resourceLoader) { |
| 70 | + return new SbomEndpoint(properties, resourceLoader); |
| 71 | + } |
| 72 | + |
| 73 | + @Bean |
| 74 | + SbomEndpointWebExtension sbomEndpointWebExtension(SbomEndpoint endpoint, SbomProperties properties) { |
| 75 | + return new SbomEndpointWebExtension(endpoint, properties); |
| 76 | + } |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | +} |
0 commit comments