summaryrefslogtreecommitdiff
path: root/swift/test/Ice/services/Client.swift
blob: c3efe618e5357bffb3dfe99fb67c207646c3da9e (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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import Glacier2
import Ice
import IceGrid
import IceStorm
import TestCommon

public class Client: TestHelperI {
    public override func run(args: [String]) throws {
        var initData = Ice.InitializationData()
        initData.properties = try createTestProperties(args)
        let communicator = try initialize(initData)
        defer {
            communicator.destroy()
        }
        let out = getWriter()

        do {
            out.write("Testing Glacier2 stub... ")
            let router = uncheckedCast(prx: try communicator.stringToProxy("test:\(getTestEndpoint(num: 0))")!,
                                       type: Glacier2.RouterPrx.self)
            do {
                _ = try router.createSession(userId: "foo", password: "bar")
                try test(false)
            } catch is LocalException {
                // expected
            }
            out.writeLine("ok")
        }

        do {
            out.write("Testing IceStorm stub... ")
            let manager = uncheckedCast(prx: try communicator.stringToProxy("test:\(getTestEndpoint(num: 0))")!,
                                                 type: TopicManagerPrx.self)

            let topicName = "time"
            var topic: TopicPrx?
            do {
                topic = try manager.retrieve(topicName)
                try test(false)
            } catch is NoSuchTopic {
                try test(false)
            } catch is LocalException {
                // expected
            }

            // topic is always nil, we're just checking the API compiling/linking here
            let publisher = try topic?.subscribeAndGetPublisher(theQoS: QoS(), subscriber: nil)
            try test(publisher == nil)
            out.writeLine("ok")
        }

        do {
            out.write("Testing IceGrid stub... ")
            let registry = uncheckedCast(prx: try communicator.stringToProxy("test:\(getTestEndpoint(num: 0))")!,
                                        type: RegistryPrx.self)

            var session: AdminSessionPrx?
            do {
                session = try registry.createAdminSession(userId: "foo", password: "bar")
                try test(false)
            } catch is LocalException {
                // expected
            }

            // session is always nil, we're just checking the API
            let admin = try session?.getAdmin()
            try test(admin == nil)
            out.writeLine("ok")
        }
    }
}