Search in sources :

Example 6 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType in project hub-alert by blackducksoftware.

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorsByTypeMissingDescriptorTypeTest.

@Test
public void getRegisteredDescriptorsByTypeMissingDescriptorTypeTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final DescriptorType descriptorType = DescriptorType.CHANNEL;
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name());
    descriptorTypeEntity.setId(1L);
    Mockito.when(descriptorTypeRepository.findFirstByType(descriptorType.name())).thenReturn(Optional.empty());
    Mockito.when(descriptorTypeRepository.save(Mockito.any())).thenReturn(descriptorTypeEntity);
    Mockito.when(registeredDescriptorRepository.findByTypeId(Mockito.any())).thenReturn(List.of(registeredDescriptorEntity));
    Mockito.when(descriptorTypeRepository.findById(registeredDescriptorEntity.getTypeId())).thenReturn(Optional.of(descriptorTypeEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository);
    List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptorsByType(descriptorType);
    assertEquals(1, registeredDescriptorModelList.size());
    RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelList.get(0);
    assertEquals(name, registeredDescriptorModel.getName());
    assertEquals(descriptorType, registeredDescriptorModel.getType());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) DescriptorTypeRepository(com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository) RegisteredDescriptorRepository(com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository) Test(org.junit.jupiter.api.Test)

Example 7 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType in project hub-alert by blackducksoftware.

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorsTest.

@Test
public void getRegisteredDescriptorsTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final DescriptorType descriptorType = DescriptorType.CHANNEL;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name());
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findAll()).thenReturn(List.of(registeredDescriptorEntity));
    Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository);
    List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptors();
    assertEquals(1, registeredDescriptorModelList.size());
    RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelList.get(0);
    assertEquals(name, registeredDescriptorModel.getName());
    assertEquals(descriptorType, registeredDescriptorModel.getType());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) DescriptorTypeRepository(com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository) RegisteredDescriptorRepository(com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository) Test(org.junit.jupiter.api.Test)

Example 8 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType 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)

Aggregations

DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)8 Test (org.junit.jupiter.api.Test)8 DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)6 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)6 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)5 DescriptorTypeRepository (com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository)5 RegisteredDescriptorRepository (com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository)5 DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)2 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)1 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)1 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)1 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1