summaryrefslogtreecommitdiffstats
path: root/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantTest.java
blob: 930787361af90730adfdca75def38bc547afc29d (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http.v2;

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.Executor;

import com.yahoo.vespa.config.server.*;
import com.yahoo.vespa.config.server.http.SessionResponse;
import com.yahoo.vespa.config.server.monitoring.Metrics;
import org.junit.After;
import org.junit.Before;

/**
 * Supertype for tests in the multi tenant application API
 * 
 * @author vegardh
 *
 */
public class TenantTest extends TestWithCurator {

    protected Tenants tenants;

    @Before
    public void setupTenants() throws Exception {
        tenants = createTenants();
    }

    @After
    public void closeTenants() throws IOException {
        tenants.close();
    }

    protected Tenants createTenants() throws Exception {
        return new Tenants(new TestComponentRegistry(curator), Metrics.createTestMetrics());
    }

    protected Executor testExecutor() {
        return new Executor() {            
            @Override
            public void execute(Runnable command) {
                command.run();
            }
        };
    }
    
    protected void assertResponseEquals(SessionResponse response, String payload) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        response.render(baos);
        assertEquals(baos.toString("UTF-8"), payload);
    }

}