Search in sources :

Example 11 with DescriptorsResponseModel

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

the class DescriptorMetadataActionsTest method getDescriptorsWithTypeAndContextTest.

@Test
public void getDescriptorsWithTypeAndContextTest() {
    DescriptorType type1 = DescriptorType.CHANNEL;
    ConfigContextEnum context1 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response1 = actions.getDescriptorsByPermissions(null, type1.name(), context1.name());
    int expectedSize = descriptors.size() / (DescriptorType.values().length);
    assertTrue(response1.isSuccessful());
    assertTrue(response1.hasContent());
    Set<DescriptorMetadata> descriptorMetadata1 = response1.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata1.size());
    DescriptorType type2 = DescriptorType.COMPONENT;
    ConfigContextEnum context2 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response2 = actions.getDescriptorsByPermissions(null, type2.name(), context2.name());
    assertTrue(response2.isSuccessful());
    assertTrue(response2.hasContent());
    Set<DescriptorMetadata> descriptorMetadata2 = response2.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata2.size());
    DescriptorType type3 = DescriptorType.PROVIDER;
    ConfigContextEnum context3 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response3 = actions.getDescriptorsByPermissions(null, type3.name(), context3.name());
    assertTrue(response3.isSuccessful());
    assertTrue(response3.hasContent());
    Set<DescriptorMetadata> descriptorMetadata3 = response3.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata3.size());
    DescriptorType type4 = DescriptorType.CHANNEL;
    ConfigContextEnum context4 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response4 = actions.getDescriptorsByPermissions(null, type4.name(), context4.name());
    assertTrue(response4.isSuccessful());
    assertTrue(response4.hasContent());
    Set<DescriptorMetadata> descriptorMetadata4 = response4.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata4.size());
    DescriptorType type5 = DescriptorType.COMPONENT;
    ConfigContextEnum context5 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response5 = actions.getDescriptorsByPermissions(null, type5.name(), context5.name());
    assertTrue(response5.isSuccessful());
    assertTrue(response5.hasContent());
    Set<DescriptorMetadata> descriptorMetadata5 = response5.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata5.size());
    DescriptorType type6 = DescriptorType.PROVIDER;
    ConfigContextEnum context6 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response6 = actions.getDescriptorsByPermissions(null, type6.name(), context6.name());
    assertTrue(response6.isSuccessful());
    assertTrue(response6.hasContent());
    Set<DescriptorMetadata> descriptorMetadata6 = response6.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata6.size());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) 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)

Example 12 with DescriptorsResponseModel

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

the class DescriptorMetadataActionsTest method getDescriptorsWithoutPermissionTest.

@Test
public void getDescriptorsWithoutPermissionTest() {
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.doReturn(true).when(authorizationManager).hasPermissions(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(false).when(authorizationManager).hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    DescriptorMetadataActions actions = new DescriptorMetadataActions(descriptors, authorizationManager);
    ActionResponse<DescriptorsResponseModel> response = actions.getDescriptorsByPermissions(null, null, null);
    assertTrue(response.isSuccessful());
    assertTrue(response.hasContent());
    List<AccessOperation> allAccessOperations = response.getContent().stream().map(DescriptorsResponseModel::getDescriptors).flatMap(Set::stream).map(DescriptorMetadata::getOperations).flatMap(Set::stream).collect(Collectors.toList());
    assertEquals(0, allAccessOperations.size());
}
Also used : AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test)

Example 13 with DescriptorsResponseModel

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

the class UpdateCheckerTest method getUpdateModelTest.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void getUpdateModelTest() {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    DefaultSystemStatusAccessor defaultSystemStatusUtility = Mockito.mock(DefaultSystemStatusAccessor.class);
    Mockito.when(defaultSystemStatusUtility.isSystemInitialized()).thenReturn(Boolean.TRUE);
    Mockito.when(defaultSystemStatusUtility.getStartupTime()).thenReturn(DateUtils.createCurrentDateTimestamp());
    DescriptorMetadataActions descriptorMetadataActions = Mockito.mock(DescriptorMetadataActions.class);
    Mockito.when(descriptorMetadataActions.getDescriptorsByType(Mockito.anyString())).thenReturn(new ActionResponse<>(HttpStatus.OK, new DescriptorsResponseModel()));
    AlertWebServerUrlManager alertWebServerUrlManager = Mockito.mock(AlertWebServerUrlManager.class);
    Mockito.when(alertWebServerUrlManager.getServerComponentsBuilder()).thenReturn(UriComponentsBuilder.newInstance());
    AlertProperties alertProperties = Mockito.mock(AlertProperties.class);
    Mockito.when(alertProperties.getAlertTrustCertificate()).thenReturn(Optional.of(Boolean.TRUE));
    AboutReader reader = new AboutReader(gson, alertWebServerUrlManager, defaultSystemStatusUtility, descriptorMetadataActions);
    UpdateChecker updateChecker = new UpdateChecker(gson, reader, proxyManager, alertProperties);
    UpdateModel updateModel = updateChecker.getUpdateModel();
    assertNotNull(updateModel);
}
Also used : AboutReader(com.synopsys.integration.alert.web.api.about.AboutReader) DefaultSystemStatusAccessor(com.synopsys.integration.alert.database.api.DefaultSystemStatusAccessor) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) DescriptorMetadataActions(com.synopsys.integration.alert.web.api.metadata.DescriptorMetadataActions) AlertWebServerUrlManager(com.synopsys.integration.alert.common.rest.AlertWebServerUrlManager) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) UpdateModel(com.synopsys.integration.alert.update.model.UpdateModel) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

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