Search in sources :

Example 1 with ArtifactoryClientFactory

use of net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientFactory in project ontrack by nemerosa.

the class ArtifactoryPromotionSyncServiceImplTest method setup.

@Before
public void setup() {
    structureService = mock(StructureService.class);
    propertyService = mock(PropertyService.class);
    ArtifactoryClientFactory artifactoryClientFactory = mock(ArtifactoryClientFactory.class);
    ArtifactoryConfigurationService configurationService = mock(ArtifactoryConfigurationService.class);
    ArtifactoryConfProperties artifactoryConfProperties = new ArtifactoryConfProperties();
    SecurityService securityService = mock(SecurityService.class);
    doAnswer(invocation -> {
        Supplier run = (Supplier) invocation.getArguments()[0];
        return run.get();
    }).when(securityService).asAdmin(any(Supplier.class));
    service = new ArtifactoryPromotionSyncServiceImpl(structureService, propertyService, artifactoryClientFactory, configurationService, artifactoryConfProperties, securityService);
    // Fake Artifactory client
    artifactoryClient = mock(ArtifactoryClient.class);
    when(artifactoryClientFactory.getClient(any())).thenReturn(artifactoryClient);
    // Branch to sync
    project = Project.of(new NameDescription("P", "Project")).withId(ID.of(1));
    branch = Branch.of(project, new NameDescription("B", "Branch")).withId(ID.of(10));
    // Existing build
    build = Build.of(branch, new NameDescription("1.0.0", "Build 1.0.0"), Signature.of("test")).withId(ID.of(100));
    when(structureService.findBuildByName("P", "B", "1.0.0")).thenReturn(Optional.of(build));
    // Existing promotions
    when(artifactoryClient.getStatuses(any())).thenReturn(Collections.singletonList(new ArtifactoryStatus("COPPER", "x", Time.now())));
    // Existing promotion level
    promotionLevel = PromotionLevel.of(branch, new NameDescription("COPPER", "Copper level")).withId(ID.of(100));
    when(structureService.findPromotionLevelByName("P", "B", "COPPER")).thenReturn(Optional.of(promotionLevel));
}
Also used : ArtifactoryConfProperties(net.nemerosa.ontrack.extension.artifactory.ArtifactoryConfProperties) ArtifactoryClientFactory(net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientFactory) ArtifactoryConfigurationService(net.nemerosa.ontrack.extension.artifactory.configuration.ArtifactoryConfigurationService) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) Supplier(java.util.function.Supplier) ArtifactoryStatus(net.nemerosa.ontrack.extension.artifactory.model.ArtifactoryStatus) ArtifactoryClient(net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClient) Before(org.junit.Before)

Aggregations

Supplier (java.util.function.Supplier)1 ArtifactoryConfProperties (net.nemerosa.ontrack.extension.artifactory.ArtifactoryConfProperties)1 ArtifactoryClient (net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClient)1 ArtifactoryClientFactory (net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientFactory)1 ArtifactoryConfigurationService (net.nemerosa.ontrack.extension.artifactory.configuration.ArtifactoryConfigurationService)1 ArtifactoryStatus (net.nemerosa.ontrack.extension.artifactory.model.ArtifactoryStatus)1 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)1 Before (org.junit.Before)1