aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainerTest.java
blob: cbaa37b15e3d889f7c944f68a305736faf059103 (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
70
71
72
73
74
75
76
77
// Copyright 2018 Yahoo Holdings. 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.User;
import com.yahoo.vespa.hosted.controller.tenant.AthenzTenant;
import com.yahoo.vespa.hosted.controller.tenant.Contact;
import org.junit.Before;
import org.junit.Test;

import java.net.URI;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

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

    private ControllerTester tester;
    private ContactInformationMaintainer maintainer;

    @Before
    public void before() {
        tester = new ControllerTester();
        maintainer = new ContactInformationMaintainer(tester.controller(), Duration.ofDays(1),
                                                      new JobControl(tester.controller().curator()),
                                                      tester.organization());
    }

    @Test
    public void updates_contact_information() {
        long propertyId = 1;
        TenantName name = tester.createTenant("tenant1", "domain1", propertyId);
        Supplier<AthenzTenant> tenant = () -> tester.controller().tenants().requireAthenzTenant(name);
        assertFalse("No contact information initially", tenant.get().contact().isPresent());

        Contact contact = testContact();
        registerContact(propertyId, contact);
        maintainer.run();

        assertTrue("Contact information added", tenant.get().contact().isPresent());
        assertEquals(contact, tenant.get().contact().get());
    }

    private void registerContact(long propertyId, Contact contact) {
        PropertyId p = new PropertyId(String.valueOf(propertyId));
        tester.organization().addProperty(p)
              .setContactsUrl(p, contact.url())
              .setIssueUrl(p, contact.issueTrackerUrl())
              .setPropertyUrl(p, contact.propertyUrl())
              .setContactsFor(p, contact.persons().stream().map(persons -> persons.stream()
                                                                                  .map(User::from)
                                                                                  .collect(Collectors.toList()))
                                        .collect(Collectors.toList()));
    }

    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 = Arrays.asList(Collections.singletonList("alice"),
                                                   Collections.singletonList("bob"));
        return new Contact(contactUrl, propertyUrl, issueTrackerUrl, persons);
    }

}