Package org.easymock

Examples of org.easymock.MockControl


    }
   
    public void testServerClass()
        throws Exception
    {
        MockControl control = MockControl.createControl(WebAnnotations.class);
        WebAnnotations webAnnotations = (WebAnnotations) control.getMock();
       
        WebServiceAnnotation serviceAnnotation = new WebServiceAnnotation();
        webAnnotations.getWebServiceAnnotation(Echo.class);
        control.setDefaultReturnValue(serviceAnnotation);
       
        webAnnotations.hasWebServiceAnnotation(Echo.class);
        control.setDefaultReturnValue(true);
       
        webAnnotations.hasWebServiceAnnotation(EchoImpl.class);
        control.setDefaultReturnValue(true);
        webAnnotations.hasHandlerChainAnnotation(EchoImpl.class);
        control.setReturnValue(false);
        webAnnotations.hasSOAPBindingAnnotation(Echo.class);
        control.setReturnValue(false);
        webAnnotations.hasWebServiceAnnotation(EchoImpl.class);
        control.setReturnValue(true);
       
        serviceAnnotation = new WebServiceAnnotation();
        serviceAnnotation.setServiceName("Echo");
        serviceAnnotation.setTargetNamespace("urn:Echo");
        serviceAnnotation.setEndpointInterface(Echo.class.getName());
        webAnnotations.getWebServiceAnnotation(EchoImpl.class);
        control.setReturnValue(serviceAnnotation);
        webAnnotations.getWebServiceAnnotation(EchoImpl.class);
        control.setReturnValue(serviceAnnotation);
       
        Method echoMethod = EchoImpl.class.getMethod("echo", new Class[]{String.class});
        webAnnotations.hasWebMethodAnnotation(echoMethod);
        control.setDefaultReturnValue(true);
       
        webAnnotations.hasWebMethodAnnotation(echoMethod);
        control.setDefaultReturnValue(false);
        webAnnotations.hasWebParamAnnotation(echoMethod, 0);
        control.setDefaultReturnValue(false);
        webAnnotations.hasWebResultAnnotation(echoMethod);
        control.setDefaultReturnValue(false);
        webAnnotations.hasOnewayAnnotation(echoMethod);
        control.setDefaultReturnValue(false);
        webAnnotations.getServiceProperties(EchoImpl.class);
        control.setDefaultReturnValue(new Properties());
        webAnnotations.getInHandlers(EchoImpl.class);
        control.setDefaultReturnValue(Collections.EMPTY_LIST);
        webAnnotations.getOutHandlers(EchoImpl.class);
        control.setDefaultReturnValue(Collections.EMPTY_LIST);
        webAnnotations.getFaultHandlers(EchoImpl.class);
        control.setDefaultReturnValue(Collections.EMPTY_LIST);
       
        control.replay();
       
        factory.setServiceFactory(new AnnotationServiceFactory(webAnnotations,
                                                               getTransportManager()));
        factory.setServiceClass(EchoImpl.class);
       
        factory.afterPropertiesSet();
       
        control.verify();
    }
View Full Code Here


   

    public void testInterface()
        throws Exception
    {
        MockControl control = MockControl.createControl(WebAnnotations.class);
        WebAnnotations webAnnotations = (WebAnnotations) control.getMock();
       
        WebServiceAnnotation serviceAnnotation = new WebServiceAnnotation();
        webAnnotations.getWebServiceAnnotation(Echo.class);
        control.setDefaultReturnValue(serviceAnnotation);
       
        webAnnotations.hasWebServiceAnnotation(Echo.class);
        control.setDefaultReturnValue(true);
       
        webAnnotations.hasSOAPBindingAnnotation(Echo.class);
        control.setReturnValue(false);
       
        serviceAnnotation = new WebServiceAnnotation();
        serviceAnnotation.setServiceName("Echo");
        serviceAnnotation.setTargetNamespace("urn:Echo");
        webAnnotations.getWebServiceAnnotation(Echo.class);
        control.setDefaultReturnValue(serviceAnnotation);
       
        Method echoMethod = EchoImpl.class.getMethod("echo", new Class[]{String.class});
        webAnnotations.hasWebMethodAnnotation(echoMethod);
        control.setDefaultReturnValue(true);
       
        webAnnotations.hasWebMethodAnnotation(echoMethod);
        control.setDefaultReturnValue(false);
        webAnnotations.hasWebParamAnnotation(echoMethod, 0);
        control.setDefaultReturnValue(false);
        webAnnotations.hasWebResultAnnotation(echoMethod);
        control.setDefaultReturnValue(false);
        webAnnotations.hasOnewayAnnotation(echoMethod);
        control.setDefaultReturnValue(false);
        webAnnotations.getServiceProperties(Echo.class);
        control.setDefaultReturnValue(new Properties());
        webAnnotations.hasHandlerChainAnnotation(Echo.class);
        control.setDefaultReturnValue(false);
        webAnnotations.getInHandlers(Echo.class);
        control.setDefaultReturnValue(Collections.EMPTY_LIST);
        webAnnotations.getOutHandlers(Echo.class);
        control.setDefaultReturnValue(Collections.EMPTY_LIST);
        webAnnotations.getFaultHandlers(Echo.class);
        control.setDefaultReturnValue(Collections.EMPTY_LIST);
        control.replay();
       
        factory.setServiceFactory(new AnnotationServiceFactory(webAnnotations,
                                                               getTransportManager()));
        factory.setServiceClass(Echo.class);
       
        factory.afterPropertiesSet();
       
        control.verify();
    }
View Full Code Here

        TypeMapping tm = registry.getDefaultTypeMapping();

        Type type = tm.getType(XMLGregorianCalendar.class);
        assertEquals("dateTime", type.getSchemaType().getLocalPart());
       
        MockControl readerControl = MockControl.createControl(MessageReader.class);
        MessageReader reader = (MessageReader) readerControl.getMock();
       
        reader.getValue();
        readerControl.setDefaultReturnValue("---28");
       
        readerControl.replay();
       
        XMLGregorianCalendarType xType = (XMLGregorianCalendarType) tm.getType(XMLGregorianCalendar.class);
        assertNotNull(xType);
        XMLGregorianCalendar cal = (XMLGregorianCalendar) xType.readObject(reader, new MessageContext());
        assertEquals(28, cal.getDay());
       
        readerControl.verify();
       
        // test writing
        MockControl writerControl = MockControl.createControl(MessageWriter.class);
        MessageWriter writer = (MessageWriter) writerControl.getMock();
       
        writer.writeValue("---28");
        writerControl.setVoidCallable();
       
        writerControl.replay();
       
        xType.writeObject(cal, writer, new MessageContext());
       
        writerControl.verify();
    }
View Full Code Here

        DefaultTypeMappingRegistry registry = new DefaultTypeMappingRegistry();
        registry.createDefaultMappings();
       
        TypeMapping tm = registry.getDefaultTypeMapping();
       
        MockControl readerControl = MockControl.createControl(MessageReader.class);
        MessageReader reader = (MessageReader) readerControl.getMock();
       
        reader.getValue();
        readerControl.setDefaultReturnValue("-P120D");
       
        readerControl.replay();
       
        DurationType dType = (DurationType) tm.getType(Duration.class);
        assertNotNull(dType);
        Duration d = (Duration) dType.readObject(reader, new MessageContext());
        assertEquals(120, d.getDays());
       
        readerControl.verify();
       
        // test writing
        MockControl writerControl = MockControl.createControl(MessageWriter.class);
        MessageWriter writer = (MessageWriter) writerControl.getMock();
       
        writer.writeValue("-P120D");
        writerControl.setVoidCallable();
       
        writerControl.replay();
       
        dType.writeObject(d, writer, new MessageContext());
        assertEquals(120, d.getDays());
       
        writerControl.verify();
    }
View Full Code Here

    private EasymockContainer mocks = new EasymockContainer();

    private ConflictResolverFactoryBean factory = new ConflictResolverFactoryBean();

    private MockControl setMockResolverStrategy() throws Exception {
        MockControl resolverControl = mocks.createControl(ConflictResolver.class);
        final ConflictResolver resolverMock = (ConflictResolver) resolverControl.getMock();
        factory.setResolverStrategies(new ArrayList() {{
            add(resolverMock);
        }});
        return resolverControl;
    }
View Full Code Here

            // expected
        }
    }

    public void testSetResolverStraties() throws Exception {
        MockControl leftActivationControl = mocks.createControl(Activation.class);
        Activation leftActivationMock = (Activation) leftActivationControl.getMock();
        MockControl rightActivationControl = mocks.createControl(Activation.class);
        Activation rightActivationMock = (Activation) rightActivationControl.getMock();

        MockControl resolverControl_1 = mocks.createControl(ConflictResolver.class);
        final ConflictResolver resolverMock_1 = (ConflictResolver) resolverControl_1.getMock();
        MockControl resolverControl_2 = mocks.createControl(ConflictResolver.class);
        final ConflictResolver resolverMock_2 = (ConflictResolver) resolverControl_2.getMock();

        // Return value needs to be zero for the next resolver to be invoked
        resolverControl_1.expectAndReturn(resolverMock_1.compare(leftActivationMock, rightActivationMock), 0);
        resolverControl_2.expectAndReturn(resolverMock_2.compare(leftActivationMock, rightActivationMock), 0);

        factory.setResolverStrategies(new ArrayList() {{
            add(resolverMock_1);
            add(resolverMock_2);
        }});
View Full Code Here

        Pojo pojo = new Pojo();
        Method pojoMethod = Pojo.class.getMethod("method", new Class[] { KnowledgeHelper.class,
                String.class, Object.class });

        Rule rule = new Rule("test");
        MockControl controlKnowledgeHelperArgument = mocks.createControl(Argument.class);
        Argument mockKnowledgeHelperArgument = (Argument) controlKnowledgeHelperArgument.getMock();
        MockControl controlFactArgument = mocks.createControl(Argument.class);
        Argument mockFactArgument = (Argument) controlFactArgument.getMock();
        MockControl controlApplicationDataArgument = mocks.createControl(Argument.class);
        Argument mockApplicationDataArgument = (Argument) controlApplicationDataArgument.getMock();

        MockControl controlTuple = mocks.createControl(Tuple.class);
        Tuple mockTuple = (Tuple)controlTuple.getMock();
        MockControl controlKnowledgeHelper = mocks.createControl(KnowledgeHelper.class);
        KnowledgeHelper mockKnowledgeHelper = (KnowledgeHelper) controlKnowledgeHelper.getMock();
        String p1 = "p1";
        Object a1 = new Object();

        controlKnowledgeHelperArgument.expectAndReturn(
                mockKnowledgeHelperArgument.getValue(mockTuple),
View Full Code Here

    }

    public void testGetRequiredTupleMembers() throws Exception {
        Rule rule = new Rule("for-test.declaration-factory");
        Argument[] parameterValues = new Argument[3];
        MockControl controlObjectType_1 = mocks.createControl(ObjectType.class);
        MockControl controlObjectType_2 = mocks.createControl(ObjectType.class);
        Declaration expectedDeclaration_1 = rule.addParameterDeclaration(
                "id-1", (ObjectType) controlObjectType_1.getMock());
        Declaration expectedDeclaration_2 = rule.addParameterDeclaration(
                "id-2", (ObjectType) controlObjectType_2.getMock());

        parameterValues[0] = new ApplicationDataArgument("name", Object.class);
        parameterValues[1] = new FactArgument(expectedDeclaration_1);
        parameterValues[2] = new FactArgument(expectedDeclaration_2);

        MockControl controlRuleMethod = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod = (RuleReflectMethod) controlRuleMethod.getMock();
        controlRuleMethod.expectAndReturn(mockRuleMethod.getArguments(), parameterValues);

        mocks.replay();

        PojoCondition pojoCondition = new PojoCondition(mockRuleMethod);
View Full Code Here

        assertSame(expectedDeclaration_1, requiredTupleMembers[0]);
        assertSame(expectedDeclaration_2, requiredTupleMembers[1]);
    }

    public void testPojoMethodThrowsException() throws Exception {
        MockControl controlRuleMethod = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod = (RuleReflectMethod) controlRuleMethod.getMock();
        controlRuleMethod.expectAndReturn(mockRuleMethod.getArguments(), new Argument[] {});
        controlRuleMethod.expectAndThrow(mockRuleMethod.invokeMethod(null), new RuntimeException("test"));

        mocks.replay();

        PojoCondition pojoCondition = new PojoCondition(mockRuleMethod);
        try {
View Full Code Here

        mocks.verify();
    }

    public void testIsAllowed() throws Exception {
        MockControl controlTuple = mocks.createControl(Tuple.class);
        Tuple mockTuple = (Tuple)controlTuple.getMock();
        MockControl controlRuleMethod = newMockRuleMethod();
        RuleReflectMethod mockRuleMethod = (RuleReflectMethod) controlRuleMethod.getMock();
        controlRuleMethod.expectAndReturn(mockRuleMethod.getArguments(), new Argument[] {});
        controlRuleMethod.expectAndReturn(mockRuleMethod.invokeMethod(mockTuple), Boolean.TRUE);

        mocks.replay();

        PojoCondition pojoCondition = new PojoCondition(mockRuleMethod);
        pojoCondition.isAllowed(mockTuple);
View Full Code Here

TOP

Related Classes of org.easymock.MockControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.