示例#1
0
class ReflectorTestCase(unittest.TestCase):

    def setUp(self):
        self.reflector = MockReflector(None)

    def testItShouldConstructAClass(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.construct(object)

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.CONSTRUCT
        assert self.reflector.sent.reflection_request.construct.object.reference == 987654321
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldConstructAClassWithArguments(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.construct(object, reflection.ReflectedType.fromNative(1, reflector=self.reflector), reflection.ReflectedType.fromNative("Joe", reflector=self.reflector))

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.CONSTRUCT
        assert self.reflector.sent.reflection_request.construct.object.reference == 987654321
        assert len(self.reflector.sent.reflection_request.construct.argument) == 2
        assert self.reflector.sent.reflection_request.construct.argument[0].type == Message.Argument.PRIMITIVE
        assert self.reflector.sent.reflection_request.construct.argument[1].type == Message.Argument.STRING
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfThereIsNoConstructor(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("no matching constructor for those parameters"))

        try:
            self.reflector.construct(object, reflection.ReflectedType.fromNative(1, reflector=self.reflector), reflection.ReflectedType.fromNative("Joe", reflector=self.reflector))

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "no matching constructor for those parameters"

    def testItShouldDeleteFromTheObjectStore(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildSuccessReply())

        response = self.reflector.delete(object)

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE
        assert self.reflector.sent.reflection_request.delete.object.reference == 987654321
        assert response == True

    def testItShouldReturnFalseIfThereIsNoObjectToDelete(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("nothing to delete"))

        response = self.reflector.delete(object)

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE
        assert self.reflector.sent.reflection_request.delete.object.reference == 987654321
        assert response == False

    def testItShouldClearTheObjectStore(self):
        self.reflector.replyWith(self.reflector.buildSuccessReply())

        response = self.reflector.deleteAll()

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE_ALL
        assert response == True

    def testItShouldClearTheObjectStore(self):
        self.reflector.replyWith(self.reflector.buildSuccessReply())

        response = self.reflector.deleteAll()

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE_ALL
        assert response == True

    def testItShouldGetAnObjectProperty(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 1))

        response = self.reflector.getProperty(object, "id")

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.GET_PROPERTY
        assert self.reflector.sent.reflection_request.get_property.object.reference == 987654321
        assert self.reflector.sent.reflection_request.get_property.property == "id"
        assert isinstance(response, reflection.ReflectedPrimitive)
        assert response.type() == 'int'
        assert response.native() == 1

    def testItShouldRaiseReflectionExceptionIfThereIsNoPropertyToGet(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("no property"))

        try:
            self.reflector.getProperty(object, "id")

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "no property"

    def testItShouldInvokeAMethod(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.invoke(object, "callMe")

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"
        assert len(self.reflector.sent.reflection_request.invoke.argument) == 0
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldInvokeAMethodWithArguments(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.invoke(object, "callMe", reflection.ReflectedType.fromNative(1, reflector=self.reflector), reflection.ReflectedType.fromNative("Joe", reflector=self.reflector))

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"
        assert len(self.reflector.sent.reflection_request.invoke.argument) == 2
        assert self.reflector.sent.reflection_request.invoke.argument[0].type == Message.Argument.PRIMITIVE
        assert self.reflector.sent.reflection_request.invoke.argument[1].type == Message.Argument.STRING
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfThereIsNoMatchingMethod(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("no matching method for those parameters"))

        try:
            self.reflector.construct(object, reflection.ReflectedType.fromNative(1, reflector=self.reflector), reflection.ReflectedType.fromNative("Joe", reflector=self.reflector))

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "no matching method for those parameters"

    def testItShouldResolveAClass(self):
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.resolve("java.lang.String")

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.RESOLVE
        assert self.reflector.sent.reflection_request.resolve.classname == "java.lang.String"
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfThereIsNoMatchingClass(self):
        self.reflector.replyWith(self.reflector.buildErrorReply("could not resolve"))

        try:
            response = self.reflector.resolve("java.lang.String")

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "could not resolve"

    def testItShouldSetAnObjectProperty(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 1))

        response = self.reflector.setProperty(object, "id", reflection.ReflectedType.fromNative(1, reflector=self.reflector))

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.SET_PROPERTY
        assert self.reflector.sent.reflection_request.set_property.object.reference == 987654321
        assert self.reflector.sent.reflection_request.set_property.property == "id"
        assert self.reflector.sent.reflection_request.set_property.value.primitive.type == Message.Primitive.INT
        assert self.reflector.sent.reflection_request.set_property.value.primitive.int == 1
        assert response.reflection_response.status == Message.ReflectionResponse.SUCCESS

    def testItShouldRaiseReflectionExceptionIfThereIsNoPropertyToSet(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("could not set property"))

        try:
            self.reflector.setProperty(object, "id", reflection.ReflectedType.fromNative(1, reflector=self.reflector))

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "could not set property"
示例#2
0
class ReflectedObjectTestCase(unittest.TestCase):
    def setUp(self):
        self.reflector = MockReflector(None)

    def testItShouldGetAPropertyValue(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(
            self.reflector.buildPrimitiveReply(Message.Primitive.INT, 42))

        object.getProperty

        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.GET_PROPERTY
        assert self.reflector.sent.reflection_request.get_property.property == "getProperty"

    def testItShouldRaiseReflectionExceptionIfGettingNonExistentProperty(self):
        assert False, "not implemented"

    def testItShouldSetAPropertyValue(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(
            self.reflector.buildPrimitiveReply(Message.Primitive.INT, 42))

        object.setProperty = 42

        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.SET_PROPERTY
        assert self.reflector.sent.reflection_request.set_property.property == "setProperty"

    def testItShouldRaiseReflectionExceptionIfSettingNonExistentProperty(self):
        assert False, "not implemented"

    def testItShouldInvokeAMethod(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        object.callMe()

        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"

    def testItShouldInvokeAMethodWithArguments(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        object.callMe(1, "Joe")

        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"
        assert len(self.reflector.sent.reflection_request.invoke.argument) == 2
        assert self.reflector.sent.reflection_request.invoke.argument[
            0].type == Message.Argument.PRIMITIVE
        assert self.reflector.sent.reflection_request.invoke.argument[
            0].primitive.type == Message.Primitive.INT
        assert self.reflector.sent.reflection_request.invoke.argument[
            0].primitive.int == 1
        assert self.reflector.sent.reflection_request.invoke.argument[
            1].type == Message.Argument.STRING
        assert self.reflector.sent.reflection_request.invoke.argument[
            1].string == "Joe"

    def testItShouldGetAPrimitiveReturnedByAMethod(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(
            self.reflector.buildPrimitiveReply(Message.Primitive.INT, 1))

        response = object.callMe()

        assert isinstance(response, reflection.types.ReflectedPrimitive)
        assert response.type() == "int"
        assert response.native() == 1

    def testItShouldGetAnObjectReturnedByAMethod(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = object.callMe()

        assert isinstance(response, reflection.types.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfInvokingNonExistentMethod(self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(
            self.reflector.buildErrorReply("no method callMe"))

        try:
            object.callMe()

            assert False, "should have raised NameError"
        except reflection.ReflectionException as e:
            assert str(e) == "no method callMe"

    def testItShouldRaiseReflectionExceptionIfInvokingMethodWithInappropriateArguments(
            self):
        object = reflection.types.ReflectedObject(987654321,
                                                  reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(
            self.reflector.buildErrorReply(
                "no method callMe compatible with those arguments"))

        try:
            object.callMe()

            assert False, "should have raised NameError"
        except reflection.ReflectionException as e:
            assert str(e) == "no method callMe compatible with those arguments"
示例#3
0
class ReflectorTestCase(unittest.TestCase):
    def setUp(self):
        self.reflector = MockReflector(None)

    def testItShouldConstructAClass(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.construct(object)

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.CONSTRUCT
        assert self.reflector.sent.reflection_request.construct.object.reference == 987654321
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldConstructAClassWithArguments(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.construct(
            object,
            reflection.ReflectedType.fromNative(1, reflector=self.reflector),
            reflection.ReflectedType.fromNative("Joe", reflector=self.reflector),
        )

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.CONSTRUCT
        assert self.reflector.sent.reflection_request.construct.object.reference == 987654321
        assert len(self.reflector.sent.reflection_request.construct.argument) == 2
        assert self.reflector.sent.reflection_request.construct.argument[0].type == Message.Argument.PRIMITIVE
        assert self.reflector.sent.reflection_request.construct.argument[1].type == Message.Argument.STRING
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfThereIsNoConstructor(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("no matching constructor for those parameters"))

        try:
            self.reflector.construct(
                object,
                reflection.ReflectedType.fromNative(1, reflector=self.reflector),
                reflection.ReflectedType.fromNative("Joe", reflector=self.reflector),
            )

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "no matching constructor for those parameters"

    def testItShouldDeleteFromTheObjectStore(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildSuccessReply())

        response = self.reflector.delete(object)

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE
        assert self.reflector.sent.reflection_request.delete.object.reference == 987654321
        assert response == True

    def testItShouldReturnFalseIfThereIsNoObjectToDelete(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("nothing to delete"))

        response = self.reflector.delete(object)

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE
        assert self.reflector.sent.reflection_request.delete.object.reference == 987654321
        assert response == False

    def testItShouldClearTheObjectStore(self):
        self.reflector.replyWith(self.reflector.buildSuccessReply())

        response = self.reflector.deleteAll()

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE_ALL
        assert response == True

    def testItShouldClearTheObjectStore(self):
        self.reflector.replyWith(self.reflector.buildSuccessReply())

        response = self.reflector.deleteAll()

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.DELETE_ALL
        assert response == True

    def testItShouldGetAnObjectProperty(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 1))

        response = self.reflector.getProperty(object, "id")

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.GET_PROPERTY
        assert self.reflector.sent.reflection_request.get_property.object.reference == 987654321
        assert self.reflector.sent.reflection_request.get_property.property == "id"
        assert isinstance(response, reflection.ReflectedPrimitive)
        assert response.type() == "int"
        assert response.native() == 1

    def testItShouldRaiseReflectionExceptionIfThereIsNoPropertyToGet(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("no property"))

        try:
            self.reflector.getProperty(object, "id")

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "no property"

    def testItShouldInvokeAMethod(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.invoke(object, "callMe")

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"
        assert len(self.reflector.sent.reflection_request.invoke.argument) == 0
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldInvokeAMethodWithArguments(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.invoke(
            object,
            "callMe",
            reflection.ReflectedType.fromNative(1, reflector=self.reflector),
            reflection.ReflectedType.fromNative("Joe", reflector=self.reflector),
        )

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"
        assert len(self.reflector.sent.reflection_request.invoke.argument) == 2
        assert self.reflector.sent.reflection_request.invoke.argument[0].type == Message.Argument.PRIMITIVE
        assert self.reflector.sent.reflection_request.invoke.argument[1].type == Message.Argument.STRING
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfThereIsNoMatchingMethod(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("no matching method for those parameters"))

        try:
            self.reflector.construct(
                object,
                reflection.ReflectedType.fromNative(1, reflector=self.reflector),
                reflection.ReflectedType.fromNative("Joe", reflector=self.reflector),
            )

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "no matching method for those parameters"

    def testItShouldResolveAClass(self):
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        response = self.reflector.resolve("java.lang.String")

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.RESOLVE
        assert self.reflector.sent.reflection_request.resolve.classname == "java.lang.String"
        assert isinstance(response, reflection.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfThereIsNoMatchingClass(self):
        self.reflector.replyWith(self.reflector.buildErrorReply("could not resolve"))

        try:
            response = self.reflector.resolve("java.lang.String")

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "could not resolve"

    def testItShouldSetAnObjectProperty(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 1))

        response = self.reflector.setProperty(
            object, "id", reflection.ReflectedType.fromNative(1, reflector=self.reflector)
        )

        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.SET_PROPERTY
        assert self.reflector.sent.reflection_request.set_property.object.reference == 987654321
        assert self.reflector.sent.reflection_request.set_property.property == "id"
        assert self.reflector.sent.reflection_request.set_property.value.primitive.type == Message.Primitive.INT
        assert self.reflector.sent.reflection_request.set_property.value.primitive.int == 1
        assert response.reflection_response.status == Message.ReflectionResponse.SUCCESS

    def testItShouldRaiseReflectionExceptionIfThereIsNoPropertyToSet(self):
        object = reflection.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildErrorReply("could not set property"))

        try:
            self.reflector.setProperty(object, "id", reflection.ReflectedType.fromNative(1, reflector=self.reflector))

            assert False, "expected a ReflectionException"
        except reflection.ReflectionException as e:
            assert e.message == "could not set property"
示例#4
0
class ReflectedObjectTestCase(unittest.TestCase):

    def setUp(self):
        self.reflector = MockReflector(None)

    def testItShouldGetAPropertyValue(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 42))

        object.getProperty
        
        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.GET_PROPERTY
        assert self.reflector.sent.reflection_request.get_property.property == "getProperty"

    def testItShouldRaiseReflectionExceptionIfGettingNonExistentProperty(self):
        assert False, "not implemented"

    def testItShouldSetAPropertyValue(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 42))

        object.setProperty = 42
        
        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.SET_PROPERTY
        assert self.reflector.sent.reflection_request.set_property.property == "setProperty"

    def testItShouldRaiseReflectionExceptionIfSettingNonExistentProperty(self):
        assert False, "not implemented"

    def testItShouldInvokeAMethod(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))

        object.callMe()
        
        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"

    def testItShouldInvokeAMethodWithArguments(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))
        
        object.callMe(1, "Joe")
        
        assert isinstance(self.reflector.sent, Message)
        assert self.reflector.sent.type == Message.REFLECTION_REQUEST
        assert self.reflector.sent.reflection_request.type == Message.ReflectionRequest.INVOKE
        assert self.reflector.sent.reflection_request.invoke.object.reference == 987654321
        assert self.reflector.sent.reflection_request.invoke.method == "callMe"
        assert len(self.reflector.sent.reflection_request.invoke.argument) == 2
        assert self.reflector.sent.reflection_request.invoke.argument[0].type == Message.Argument.PRIMITIVE
        assert self.reflector.sent.reflection_request.invoke.argument[0].primitive.type == Message.Primitive.INT
        assert self.reflector.sent.reflection_request.invoke.argument[0].primitive.int == 1
        assert self.reflector.sent.reflection_request.invoke.argument[1].type == Message.Argument.STRING
        assert self.reflector.sent.reflection_request.invoke.argument[1].string == "Joe"

    def testItShouldGetAPrimitiveReturnedByAMethod(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildPrimitiveReply(Message.Primitive.INT, 1))
        
        response = object.callMe()

        assert isinstance(response, reflection.types.ReflectedPrimitive)
        assert response.type() == "int"
        assert response.native() == 1

    def testItShouldGetAnObjectReturnedByAMethod(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildObjectReply(55512345))
        
        response = object.callMe()

        assert isinstance(response, reflection.types.ReflectedObject)
        assert response._ref == 55512345

    def testItShouldRaiseReflectionExceptionIfInvokingNonExistentMethod(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildErrorReply("no method callMe"))
        
        try:
            object.callMe()

            assert False, "should have raised NameError"
        except reflection.ReflectionException as e:
            assert e.message == "no method callMe"

    def testItShouldRaiseReflectionExceptionIfInvokingMethodWithInappropriateArguments(self):
        object = reflection.types.ReflectedObject(987654321, reflector=self.reflector)

        self.reflector.replyWith(None)
        self.reflector.replyWith(self.reflector.buildErrorReply("no method callMe compatible with those arguments"))
        
        try:
            object.callMe()

            assert False, "should have raised NameError"
        except reflection.ReflectionException as e:
            assert e.message == "no method callMe compatible with those arguments"