Search in sources :

Example 6 with DescriptorMetadata

use of com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata in project hub-alert by blackducksoftware.

the class AboutModelTest method testWithValues.

@Test
public void testWithValues() {
    String version = "1.2.3";
    String created = "date";
    String description = "description";
    String projectUrl = "https://www.google.com";
    String documentationUrl = "https://www.google.com";
    boolean initialized = true;
    String startupTime = "startup time is now";
    DescriptorMetadata providerMetadata = Mockito.mock(DescriptorMetadata.class);
    DescriptorMetadata channelMetadata = Mockito.mock(DescriptorMetadata.class);
    Set<DescriptorMetadata> providers = Set.of(providerMetadata);
    Set<DescriptorMetadata> channels = Set.of(channelMetadata);
    AboutModel model = new AboutModel(version, created, description, projectUrl, documentationUrl, initialized, startupTime, providers, channels);
    assertEquals(version, model.getVersion());
    assertEquals(description, model.getDescription());
    assertEquals(projectUrl, model.getProjectUrl());
    assertEquals(documentationUrl, model.getDocumentationUrl());
    assertEquals(initialized, model.isInitialized());
    assertEquals(startupTime, model.getStartupTime());
    assertEquals(providers, model.getProviders());
    assertEquals(channels, model.getChannels());
}
Also used : DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) AboutModel(com.synopsys.integration.alert.web.api.about.AboutModel) Test(org.junit.jupiter.api.Test)

Example 7 with DescriptorMetadata

use of com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata in project hub-alert by blackducksoftware.

the class AboutActionsTest method testGetAboutModel.

@Test
public void testGetAboutModel() {
    String version = "1.2.3";
    String created = "date";
    String description = "description";
    String aUrl = "https://www.google.com";
    boolean initialized = true;
    String startupTime = "startup time is now";
    DescriptorMetadata providerMetadata = Mockito.mock(DescriptorMetadata.class);
    DescriptorMetadata channelMetadata = Mockito.mock(DescriptorMetadata.class);
    Set<DescriptorMetadata> providers = Set.of(providerMetadata);
    Set<DescriptorMetadata> channels = Set.of(channelMetadata);
    AboutModel model = new AboutModel(version, created, description, aUrl, aUrl, initialized, startupTime, providers, channels);
    AboutReader aboutReader = Mockito.mock(AboutReader.class);
    Mockito.when(aboutReader.getAboutModel()).thenReturn(Optional.of(model));
    AboutActions aboutActions = new AboutActions(aboutReader);
    ActionResponse<AboutModel> resultModel = aboutActions.getAboutModel();
    assertTrue(resultModel.isSuccessful());
    assertTrue(resultModel.hasContent());
    assertEquals(model, resultModel.getContent().orElse(null));
}
Also used : DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) Test(org.junit.jupiter.api.Test)

Example 8 with DescriptorMetadata

use of com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata 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)

Example 9 with DescriptorMetadata

use of com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata 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 10 with DescriptorMetadata

use of com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata 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)

Aggregations

DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)10 DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)7 Test (org.junit.jupiter.api.Test)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)4 AccessOperation (com.synopsys.integration.alert.common.enumeration.AccessOperation)2 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)2 Gson (com.google.gson.Gson)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1 AboutModel (com.synopsys.integration.alert.web.api.about.AboutModel)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1