Search in sources :

Example 6 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorMetadataActions method createDescriptorResponse.

private ActionResponse<DescriptorsResponseModel> createDescriptorResponse(Predicate<Descriptor> descriptorFilter, Set<ConfigContextEnum> requestedContexts) {
    Set<DescriptorMetadata> descriptorMetadata = descriptors.stream().filter(descriptorFilter).map(descriptor -> createDescriptorMetadata(descriptor, requestedContexts)).flatMap(Set::stream).collect(Collectors.toSet());
    DescriptorsResponseModel responseModel = new DescriptorsResponseModel(descriptorMetadata);
    return new ActionResponse<>(HttpStatus.OK, responseModel);
}
Also used : DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)

Example 7 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorControllerTestIT method getDescriptorsWithNameAndContextTest.

@Test
public void getDescriptorsWithNameAndContextTest() throws Exception {
    String msTeams = ChannelKeys.MS_TEAMS.getUniversalKey();
    URI descriptorPath = new URIBuilder(DescriptorController.BASE_PATH).addParameter("name", msTeams).addParameter("context", ConfigContextEnum.GLOBAL.name()).build();
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(descriptorPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    DescriptorsResponseModel descriptorsResponseModel = assertValidResponse(request);
    assertEquals(1, descriptorsResponseModel.getDescriptors().size());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorControllerTestIT method getDescriptorsWithNoParametersTest.

@Test
public void getDescriptorsWithNoParametersTest() throws Exception {
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(new URI(DescriptorController.BASE_PATH)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    DescriptorsResponseModel descriptorsResponseModel = assertValidResponse(request);
    assertEquals(21, descriptorsResponseModel.getDescriptors().size());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) URI(java.net.URI) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class AboutReaderTest method initialize.

@BeforeEach
public void initialize() {
    alertWebServerUrlManager = Mockito.mock(AlertWebServerUrlManager.class);
    Mockito.when(alertWebServerUrlManager.getServerComponentsBuilder()).thenReturn(UriComponentsBuilder.newInstance());
    defaultSystemStatusUtility = Mockito.mock(DefaultSystemStatusAccessor.class);
    Mockito.when(defaultSystemStatusUtility.isSystemInitialized()).thenReturn(Boolean.TRUE);
    Mockito.when(defaultSystemStatusUtility.getStartupTime()).thenReturn(DateUtils.createCurrentDateTimestamp());
    defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    Mockito.when(defaultSystemMessageUtility.getSystemMessages()).thenReturn(Collections.singletonList(new SystemMessageModel("1", RestConstants.formatDate(new Date()), "ERROR", "startup errors", "type")));
    descriptorMetadataActions = Mockito.mock(DescriptorMetadataActions.class);
    DescriptorsResponseModel descriptorsResponseModel = new DescriptorsResponseModel(Set.of(Mockito.mock(DescriptorMetadata.class), Mockito.mock(DescriptorMetadata.class)));
    Mockito.when(descriptorMetadataActions.getDescriptorsByType(Mockito.anyString())).thenReturn(new ActionResponse<>(HttpStatus.OK, descriptorsResponseModel));
}
Also used : DefaultSystemStatusAccessor(com.synopsys.integration.alert.database.api.DefaultSystemStatusAccessor) SystemMessageModel(com.synopsys.integration.alert.common.persistence.model.SystemMessageModel) DescriptorMetadataActions(com.synopsys.integration.alert.web.api.metadata.DescriptorMetadataActions) AlertWebServerUrlManager(com.synopsys.integration.alert.common.rest.AlertWebServerUrlManager) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) Date(java.util.Date) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with DescriptorsResponseModel

use of com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel in project hub-alert by blackducksoftware.

the class DescriptorMetadataActionsTest method getDescriptorsWithNameAndContextTest.

@Test
public void getDescriptorsWithNameAndContextTest() {
    String componentName1 = getNamePrefix(DescriptorType.CHANNEL) + "_4";
    ConfigContextEnum context1 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response1 = actions.getDescriptorsByPermissions(componentName1, null, context1.name());
    assertTrue(response1.isSuccessful());
    assertTrue(response1.hasContent());
    Set<DescriptorMetadata> descriptorMetadata1 = response1.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata1.size());
    String componentName2 = getNamePrefix(DescriptorType.COMPONENT) + "_4";
    ConfigContextEnum context2 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response2 = actions.getDescriptorsByPermissions(componentName2, null, context2.name());
    assertTrue(response2.isSuccessful());
    assertTrue(response2.hasContent());
    Set<DescriptorMetadata> descriptorMetadata2 = response2.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata2.size());
    String componentName3 = getNamePrefix(DescriptorType.PROVIDER) + "_4";
    ConfigContextEnum context3 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response3 = actions.getDescriptorsByPermissions(componentName3, null, context3.name());
    assertTrue(response3.isSuccessful());
    assertTrue(response3.hasContent());
    Set<DescriptorMetadata> descriptorMetadata3 = response3.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata3.size());
    ConfigContextEnum context4 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response4 = actions.getDescriptorsByPermissions(componentName1, null, context4.name());
    assertTrue(response4.isSuccessful());
    assertTrue(response4.hasContent());
    Set<DescriptorMetadata> descriptorMetadata4 = response4.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata4.size());
    ConfigContextEnum context5 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response5 = actions.getDescriptorsByPermissions(componentName2, null, context5.name());
    assertTrue(response5.isSuccessful());
    assertTrue(response5.hasContent());
    Set<DescriptorMetadata> descriptorMetadata5 = response5.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata5.size());
    ConfigContextEnum context6 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response6 = actions.getDescriptorsByPermissions(componentName3, null, context6.name());
    assertTrue(response6.isSuccessful());
    assertTrue(response6.hasContent());
    Set<DescriptorMetadata> descriptorMetadata6 = response6.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata6.size());
}
Also used : DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test)

Aggregations

DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)13 DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)8 Test (org.junit.jupiter.api.Test)8 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)3 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)3 URI (java.net.URI)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)2 AccessOperation (com.synopsys.integration.alert.common.enumeration.AccessOperation)2 AlertWebServerUrlManager (com.synopsys.integration.alert.common.rest.AlertWebServerUrlManager)2 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)2 DefaultSystemStatusAccessor (com.synopsys.integration.alert.database.api.DefaultSystemStatusAccessor)2 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)2 DescriptorMetadataActions (com.synopsys.integration.alert.web.api.metadata.DescriptorMetadataActions)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 Gson (com.google.gson.Gson)1 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)1 Descriptor (com.synopsys.integration.alert.common.descriptor.Descriptor)1 SystemMessageModel (com.synopsys.integration.alert.common.persistence.model.SystemMessageModel)1