aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainerTest.java
blob: 2c54c0c9fb6935e39d55efda29ddc125b3bc6edb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.maintenance;

import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.hosted.controller.ControllerTester;
import com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId;
import com.yahoo.vespa.hosted.controller.api.integration.organization.Contact;
import com.yahoo.vespa.hosted.controller.tenant.AthenzTenant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
 * @author mpolden
 */
public class ContactInformationMaintainerTest {

    private ControllerTester tester;
    private ContactInformationMaintainer maintainer;

    @BeforeEach
    public void before() {
        tester = new ControllerTester();
        maintainer = new ContactInformationMaintainer(tester.controller(), Duration.ofDays(1), 1.0);
    }

    @Test
    void updates_contact_information() {
        PropertyId propertyId1 = new PropertyId("1");
        PropertyId propertyId2 = new PropertyId("2");
        TenantName name1 = tester.createTenant("tenant1", "domain1", 1L);
        TenantName name2 = tester.createTenant("zenant1", "domain2", 2L);
        Supplier<AthenzTenant> tenant1 = () -> (AthenzTenant) tester.controller().tenants().require(name1);
        Supplier<AthenzTenant> tenant2 = () -> (AthenzTenant) tester.controller().tenants().require(name2);
        assertFalse(tenant1.get().contact().isPresent(), "No contact information initially");
        assertFalse(tenant2.get().contact().isPresent(), "No contact information initially");

        Contact contact = testContact();
        tester.serviceRegistry().contactRetriever().addContact(propertyId1, () -> {
            throw new RuntimeException("ERROR");
        });
        tester.serviceRegistry().contactRetriever().addContact(propertyId2, () -> contact);
        maintainer.maintain();

        assertEquals(Optional.empty(), tenant1.get().contact(), "No contact information added due to error");
        assertEquals(Optional.of(contact), tenant2.get().contact(), "Contact information added");
    }

    private static Contact testContact() {
        URI contactUrl = URI.create("http://contact1.test");
        URI issueTrackerUrl = URI.create("http://issue-tracker1.test");
        URI propertyUrl = URI.create("http://property1.test");
        List<List<String>> persons = List.of(Collections.singletonList("alice"),
                                             Collections.singletonList("bob"));
        String queue = "queue";
        Optional<String> component = Optional.empty();
        return new Contact(contactUrl, propertyUrl, issueTrackerUrl, persons, queue, component);
    }

}