Class: Quark::Quark::Mock::MockRuntimeTest

Inherits:
DatawireQuarkCore::QuarkObject show all
Extended by:
DatawireQuarkCore::Static
Defined in:
lib/quark/mock.rb

Constant Summary

Constants included from DatawireQuarkCore::Static

DatawireQuarkCore::Static::Unassigned

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DatawireQuarkCore::Static

_lazy_statics, static, unlazy_statics

Methods inherited from DatawireQuarkCore::QuarkObject

#to_s

Constructor Details

#initializeMockRuntimeTest

Returns a new instance of MockRuntimeTest.



1065
1066
1067
1068
1069
# File 'lib/quark/mock.rb', line 1065

def initialize()
    self.__init_fields__

    nil
end

Instance Attribute Details

#expectIdxObject

Returns the value of attribute expectIdx.



1057
1058
1059
# File 'lib/quark/mock.rb', line 1057

def expectIdx
  @expectIdx
end

#mockObject

Returns the value of attribute mock.



1057
1058
1059
# File 'lib/quark/mock.rb', line 1057

def mock
  @mock
end

#oldObject

Returns the value of attribute old.



1057
1058
1059
# File 'lib/quark/mock.rb', line 1057

def old
  @old
end

#socketsObject

Returns the value of attribute sockets.



1057
1058
1059
# File 'lib/quark/mock.rb', line 1057

def sockets
  @sockets
end

Instance Method Details

#__init_fields__Object



1207
1208
1209
1210
1211
1212
1213
1214
1215
# File 'lib/quark/mock.rb', line 1207

def __init_fields__()
    
    self.mock = nil
    self.old = nil
    self.expectIdx = 0
    self.sockets = nil

    nil
end

#_getClassObject



1163
1164
1165
1166
1167
1168
# File 'lib/quark/mock.rb', line 1163

def _getClass()
    
    return "quark.mock.MockRuntimeTest"

    nil
end

#_getField(name) ⇒ Object



1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File 'lib/quark/mock.rb', line 1170

def _getField(name)
    
    if ((name) == ("mock"))
        return (self).mock
    end
    if ((name) == ("old"))
        return (self).old
    end
    if ((name) == ("expectIdx"))
        return (self).expectIdx
    end
    if ((name) == ("sockets"))
        return (self).sockets
    end
    return nil

    nil
end

#_setField(name, value) ⇒ Object



1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/quark/mock.rb', line 1189

def _setField(name, value)
    
    if ((name) == ("mock"))
        (self).mock = ::DatawireQuarkCore.cast(value) { ::Quark.quark.mock.MockRuntime }
    end
    if ((name) == ("old"))
        (self).old = ::DatawireQuarkCore.cast(value) { ::Quark.quark.concurrent.Context }
    end
    if ((name) == ("expectIdx"))
        (self).expectIdx = ::DatawireQuarkCore.cast(value) { ::Integer }
    end
    if ((name) == ("sockets"))
        (self).sockets = ::DatawireQuarkCore.cast(value) { ::Hash }
    end

    nil
end

#expectEvent(expectedType) ⇒ Object



1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
# File 'lib/quark/mock.rb', line 1113

def expectEvent(expectedType)
    
    result = ::DatawireQuarkCore.cast(nil) { ::Quark.quark.mock.MockEvent }
    if (::Quark.quark.test.check((((@mock).events).size) > (@expectIdx), (("expected ") + (expectedType)) + (" event, got no events")))
        type = ((@mock).events)[@expectIdx].getType()
        if (::Quark.quark.test.check((type) == (expectedType), ((("expected ") + (expectedType)) + (" event, got ")) + (type)))
            result = ((@mock).events)[@expectIdx]
        end
    end
    @expectIdx = (@expectIdx) + (1)
    return result

    nil
end

#expectNoneObject



1104
1105
1106
1107
1108
1109
1110
1111
# File 'lib/quark/mock.rb', line 1104

def expectNone()
    
    delta = (((@mock).events).size) - (@expectIdx)
    ::Quark.quark.test.check((delta) == (0), ("expected no events, got ") + ((delta).to_s))
    return delta

    nil
end

#expectRequest(expectedUrl) ⇒ Object



1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
# File 'lib/quark/mock.rb', line 1128

def expectRequest(expectedUrl)
    
    rev = ::DatawireQuarkCore.cast(self.expectEvent("request")) { ::Quark.quark.mock.RequestEvent }
    if ((rev) != (nil))
        if ((expectedUrl) == (nil))
            return rev
        end
        url = (rev).request.getUrl()
        if (::Quark.quark.test.check((url) == (expectedUrl), (((("expected request event to url(") + (expectedUrl)) + ("), got url(")) + (url)) + (")")))
            return rev
        end
    end
    return ::DatawireQuarkCore.cast(nil) { ::Quark.quark.mock.RequestEvent }

    nil
end

#expectSocket(expectedUrl) ⇒ Object



1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'lib/quark/mock.rb', line 1145

def expectSocket(expectedUrl)
    
    sev = ::DatawireQuarkCore.cast(self.expectEvent("socket")) { ::Quark.quark.mock.SocketEvent }
    if ((sev) != (nil))
        (@sockets)[(sev).url] = (sev)
        if ((expectedUrl) == (nil))
            return sev
        end
        url = (sev).url
        if (::Quark.quark.test.check((url) == (expectedUrl), (((("expected socket event to url(") + (expectedUrl)) + ("), got url(")) + (url)) + (")")))
            return sev
        end
    end
    return ::DatawireQuarkCore.cast(nil) { ::Quark.quark.mock.SocketEvent }

    nil
end

#pumpObject

Execute any pending asynchronous tasks.



1097
1098
1099
1100
1101
1102
# File 'lib/quark/mock.rb', line 1097

def pump()
    
    @mock.pump()

    nil
end

#setupObject



1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
# File 'lib/quark/mock.rb', line 1074

def setup()
    
    @old = ::Quark.quark.concurrent.Context.current()
    ctx = ::Quark.quark.concurrent.Context.new(::Quark.quark.concurrent.Context.current())
    @mock = ::Quark.quark.mock.MockRuntime.new((ctx)._runtime)
    (ctx)._runtime = @mock
    ::Quark.quark.concurrent.Context.swap(ctx)
    @expectIdx = 0
    @sockets = {}

    nil
end

#teardownObject



1087
1088
1089
1090
1091
1092
# File 'lib/quark/mock.rb', line 1087

def teardown()
    
    ::Quark.quark.concurrent.Context.swap(@old)

    nil
end