summaryrefslogtreecommitdiff
path: root/swift/test/Ice/servantLocator/TestAMDI.swift
blob: 950dd2cd2f573d029908b6f537702ed998e18d6e (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Ice
import PromiseKit
import TestCommon

class TestI: TestIntf {
    func requestFailedExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func unknownUserExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func unknownLocalExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func unknownExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func localExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func userExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func unknownExceptionWithServantExceptionAsync(current: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(ObjectNotExistException(id: current.id, facet: current.facet, operation: current.operation))
        }
    }

    func impossibleExceptionAsync(throw t: Bool, current _: Current) -> Promise<String> {
        return Promise<String> { seal in
            if t {
                seal.reject(TestImpossibleException())
            } else {
                //
                // Return a value so we can be sure that the stream position
                // is reset correctly if finished() throws.
                //
                seal.fulfill("Hello")
            }
        }
    }

    func intfUserExceptionAsync(throw t: Bool, current _: Current) -> Promise<String> {
        return Promise<String> { seal in
            if t {
                seal.reject(TestIntfUserException())
            } else {
                //
                // Return a value so we can be sure that the stream position
                // is reset correctly if finished() throws.
                //
                seal.fulfill("Hello")
            }
        }
    }

    func asyncResponseAsync(current _: Current) -> Promise<Void> {
        return Promise.value(())
    }

    func asyncExceptionAsync(current _: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            seal.reject(TestIntfUserException())
        }
    }

    func shutdownAsync(current: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            current.adapter!.deactivate()
            seal.fulfill(())
        }
    }
}

class TestActivationI: TestActivation {
    var _helper: TestHelper

    init(_ helper: TestHelper) {
        _helper = helper
    }

    func activateServantLocatorAsync(activate: Bool, current: Current) -> Promise<Void> {
        return Promise<Void> { seal in
            if activate {
                try current.adapter!.addServantLocator(locator: ServantLocatorI("", _helper), category: "")
                try current.adapter!.addServantLocator(locator: ServantLocatorI("category", _helper),
                                                       category: "category")
            } else {
                var locator = try current.adapter!.removeServantLocator("")
                locator.deactivate("")
                locator = try current.adapter!.removeServantLocator("category")
                locator.deactivate("category")
            }
            seal.fulfill(())
        }
    }
}