cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r470005 [3/3] - in /incubator/cxf/trunk/rt/ws/rm: ./ src/main/java/org/apache/cxf/ws/rm/ src/main/java/org/apache/cxf/ws/rm/impl/ src/main/java/org/apache/cxf/ws/rm/persistence/ src/main/java/org/apache/cxf/ws/rm/soap/ src/main/resources/ME...
Date Wed, 01 Nov 2006 17:36:09 GMT
Added: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMOutInterceptorTest.java?view=auto&rev=470005
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMOutInterceptorTest.java
(added)
+++ incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMOutInterceptorTest.java
Wed Nov  1 09:36:06 2006
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.rm;
+
+import java.lang.reflect.Method;
+import java.math.BigInteger;
+import java.util.Collections;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.ws.addressing.JAXWSAConstants;
+import org.apache.cxf.ws.addressing.MAPAggregator;
+import org.apache.cxf.ws.addressing.v200408.AttributedURI;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+public class RMOutInterceptorTest extends TestCase {
+    
+    private IMocksControl control;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl();
+    }
+    
+    public void testOrdering() {
+        Phase p = new Phase(Phase.PRE_LOGICAL, 1);
+        PhaseInterceptorChain chain = 
+            new PhaseInterceptorChain(Collections.singletonList(p));
+        MAPAggregator map = new MAPAggregator();
+        RMOutInterceptor rmi = new RMOutInterceptor();        
+        chain.add(rmi);
+        chain.add(map);
+        Iterator it = chain.iterator();
+        assertSame("Unexpected order.", map, it.next());
+        assertSame("Unexpected order.", rmi, it.next());                      
+    } 
+    
+    public void testHandleApplicationMessage() throws NoSuchMethodException, SequenceFault
{
+        AddressingPropertiesImpl maps = createMAPs("greetMe", "localhost:9000/GreeterPort",

+            org.apache.cxf.ws.addressing.Names.WSA_NONE_ADDRESS);
+        Method[] mocked = new Method[] {
+            AbstractRMInterceptor.class.getDeclaredMethod("getManager", new Class[]{}),
+            RMOutInterceptor.class.getDeclaredMethod("addAcknowledgements",
+                new Class[] {Destination.class, RMProperties.class, Identifier.class, 
+                             AttributedURI.class})            
+        };
+        RMOutInterceptor interceptor = control.createMock(RMOutInterceptor.class, mocked);

+        RMManager manager = control.createMock(RMManager.class);
+        EasyMock.expect(interceptor.getManager()).andReturn(manager).times(3);
+        
+        Message message = control.createMock(Message.class);
+
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
       
+        EasyMock.expect(message.get(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND))
+            .andReturn(maps).anyTimes();
+        RMProperties rmpsOut = new RMProperties();
+        EasyMock.expect(message.get(RMMessageConstants.RM_PROPERTIES_OUTBOUND)).andReturn(rmpsOut);
+        EasyMock.expect(message.get(RMMessageConstants.RM_PROPERTIES_INBOUND)).andReturn(null);
+        
+        Source source = control.createMock(Source.class);
+        EasyMock.expect(manager.getSource(message)).andReturn(source);
+        Destination destination = control.createMock(Destination.class);
+        EasyMock.expect(manager.getDestination(message)).andReturn(destination);
+        SourceSequence sseq = control.createMock(SourceSequence.class);
+        EasyMock.expect(manager.getSequence((Identifier)EasyMock.isNull(), EasyMock.same(message),

+                                        EasyMock.same(maps))).andReturn(sseq);
+        EasyMock.expect(sseq.nextMessageNumber((Identifier)EasyMock.isNull(), 
+            (BigInteger)EasyMock.isNull())).andReturn(BigInteger.TEN);
+        EasyMock.expect(sseq.isLastMessage()).andReturn(false).times(2);
+        interceptor.addAcknowledgements(EasyMock.same(destination), EasyMock.same(rmpsOut),

+            (Identifier)EasyMock.isNull(), EasyMock.isA(AttributedURI.class));
+        EasyMock.expectLastCall();
+        Identifier sid = control.createMock(Identifier.class);
+        EasyMock.expect(sseq.getIdentifier()).andReturn(sid);
+        EasyMock.expect(sseq.getCurrentMessageNr()).andReturn(BigInteger.TEN);
+
+        
+        control.replay();
+        interceptor.handleMessage(message, false);
+        assertSame(sid, rmpsOut.getSequence().getIdentifier());        
+        assertEquals(BigInteger.TEN, rmpsOut.getSequence().getMessageNumber());
+        assertNull(rmpsOut.getSequence().getLastMessage());
+        control.verify();
+    }
+    
+    private AddressingPropertiesImpl createMAPs(String action, String to, String replyTo)
{
+        AddressingPropertiesImpl maps = new AddressingPropertiesImpl();
+        org.apache.cxf.ws.addressing.ObjectFactory factory = 
+            new org.apache.cxf.ws.addressing.ObjectFactory();
+        AttributedURIType uri = factory.createAttributedURIType();
+        uri.setValue(action);
+        maps.setAction(uri);
+        uri = factory.createAttributedURIType();
+        uri.setValue(to);
+        maps.setTo(uri);
+        EndpointReferenceType epr = RMUtils.createReference(replyTo);
+        maps.setReplyTo(epr);
+        return maps;
+           
+    }
+}

Propchange: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/SourceSequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/SourceSequenceTest.java?view=auto&rev=470005
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/SourceSequenceTest.java
(added)
+++ incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/SourceSequenceTest.java
Wed Nov  1 09:36:06 2006
@@ -0,0 +1,320 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.rm;
+
+import java.math.BigInteger;
+import java.util.Date;
+
+import javax.xml.datatype.Duration;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.jaxb.DatatypeFactory;
+import org.apache.cxf.ws.rm.manager.SequenceTerminationPolicyType;
+import org.apache.cxf.ws.rm.manager.SourcePolicyType;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+public class SourceSequenceTest extends TestCase {
+
+    private IMocksControl control;
+    private ObjectFactory factory;
+    private Identifier id;
+
+    private Source source;
+    private RMManager manager;
+    private SourcePolicyType sp;
+    private SequenceTerminationPolicyType stp;
+  
+    public void setUp() {        
+        factory = new ObjectFactory();
+        id = factory.createIdentifier();
+        id.setValue("seq");
+        
+        control = EasyMock.createNiceControl();
+    }
+    
+    public void tearDown() {
+        source = null;
+        manager = null;
+        sp = null;
+        stp = null;
+    }
+    
+    void setUpSource() {
+        source = control.createMock(Source.class); 
+        manager = control.createMock(RMManager.class);
+        EasyMock.expect(source.getManager()).andReturn(manager).anyTimes();
+
+        // default termination policy
+        
+        org.apache.cxf.ws.rm.manager.ObjectFactory cfgFactory = 
+            new org.apache.cxf.ws.rm.manager.ObjectFactory();
+        sp = cfgFactory.createSourcePolicyType();
+        stp = cfgFactory
+            .createSequenceTerminationPolicyType(); 
+        sp.setSequenceTerminationPolicy(stp);
+        EasyMock.expect(manager.getSourcePolicy()).andReturn(sp).anyTimes();
+    }
+    
+
+    public void testConstructors() {
+
+        Identifier otherId = factory.createIdentifier();
+        otherId.setValue("otherSeq");
+       
+        SourceSequence seq = null;
+        
+        seq = new SourceSequence(id);
+        assertEquals(id, seq.getIdentifier());
+        assertTrue(!seq.isLastMessage());
+        assertTrue(!seq.isExpired());
+        assertEquals(BigInteger.ZERO, seq.getCurrentMessageNr());
+        assertNotNull(seq.getAcknowledgement());
+        assertEquals(0, seq.getAcknowledgement().getAcknowledgementRange().size());
+        assertTrue(!seq.allAcknowledged());
+        assertFalse(seq.offeredBy(otherId));
+        
+        Date expiry = new Date(System.currentTimeMillis() + 3600 * 1000);
+        
+        seq = new SourceSequence(id, expiry, null);
+        assertEquals(id, seq.getIdentifier());
+        assertTrue(!seq.isLastMessage());
+        assertTrue(!seq.isExpired());
+        assertEquals(BigInteger.ZERO, seq.getCurrentMessageNr());
+        assertNotNull(seq.getAcknowledgement());
+        assertEquals(0, seq.getAcknowledgement().getAcknowledgementRange().size());
+        assertTrue(!seq.allAcknowledged());
+        assertFalse(seq.offeredBy(otherId));
+        
+        seq = new SourceSequence(id, expiry, otherId);
+        assertTrue(seq.offeredBy(otherId));
+        assertFalse(seq.offeredBy(id));
+    }
+    
+    public void testSetExpires() {
+        SourceSequence seq = new SourceSequence(id);
+        
+        Expires expires = factory.createExpires();
+        seq.setExpires(expires);
+            
+        assertTrue(!seq.isExpired());
+        
+        Duration d = DatatypeFactory.PT0S;          
+        expires.setValue(d); 
+        seq.setExpires(expires);
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException ex) {
+            assertTrue(!seq.isExpired());
+        }
+        
+        d = DatatypeFactory.createDuration("PT1S");        
+        expires.setValue(d);
+        seq.setExpires(expires);
+        assertTrue(!seq.isExpired());
+        
+        d = DatatypeFactory.createDuration("-PT1S");  
+        expires.setValue(d);
+        seq.setExpires(expires);
+        assertTrue(seq.isExpired());   
+    }
+
+    public void testEqualsAndHashCode() {
+        SourceSequence seq = new SourceSequence(id);
+        SourceSequence otherSeq = null;
+        assertTrue(!seq.equals(otherSeq));
+        otherSeq = new SourceSequence(id);
+        assertEquals(seq, otherSeq);
+        assertEquals(seq.hashCode(), otherSeq.hashCode());
+        Identifier otherId = factory.createIdentifier();
+        otherId.setValue("otherSeq");
+        otherSeq = new SourceSequence(otherId);
+        assertTrue(!seq.equals(otherSeq));
+        assertTrue(seq.hashCode() != otherSeq.hashCode()); 
+        assertTrue(!seq.equals(this));
+    }
+    
+
+    public void testSetAcknowledged() {
+        SourceSequence seq = new SourceSequence(id);
+        SequenceAcknowledgement ack = seq.getAcknowledgement();
+        ack = factory.createSequenceAcknowledgement();
+        SequenceAcknowledgement.AcknowledgementRange r = 
+            factory.createSequenceAcknowledgementAcknowledgementRange();
+        r.setLower(new BigInteger("1"));
+        r.setUpper(new BigInteger("2"));
+        ack.getAcknowledgementRange().add(r);
+        r = factory.createSequenceAcknowledgementAcknowledgementRange();
+        r.setLower(new BigInteger("4"));
+        r.setUpper(new BigInteger("6"));
+        ack.getAcknowledgementRange().add(r);
+        r = factory.createSequenceAcknowledgementAcknowledgementRange();
+        r.setLower(new BigInteger("8"));
+        r.setUpper(new BigInteger("10"));
+        ack.getAcknowledgementRange().add(r);
+        seq.setAcknowledged(ack);
+        assertSame(ack, seq.getAcknowledgement());
+        assertEquals(3, ack.getAcknowledgementRange().size());
+        assertTrue(!seq.isAcknowledged(new BigInteger("3")));  
+        assertTrue(seq.isAcknowledged(new BigInteger("5")));
+    } 
+
+    public void testAllAcknowledged() throws SequenceFault {
+        
+        SourceSequence seq = new SourceSequence(id, null, null, new BigInteger("4"), false);
       
+        
+        assertTrue(!seq.allAcknowledged());
+        seq.setLastMessage(true);
+        assertTrue(!seq.allAcknowledged());
+        SequenceAcknowledgement ack = factory.createSequenceAcknowledgement();
+        SequenceAcknowledgement.AcknowledgementRange r = 
+            factory.createSequenceAcknowledgementAcknowledgementRange();
+        r.setLower(BigInteger.ONE);
+        r.setUpper(new BigInteger("2"));
+        ack.getAcknowledgementRange().add(r);
+        seq.setAcknowledged(ack);
+        assertTrue(!seq.allAcknowledged());
+        r.setUpper(new BigInteger("4"));
+        assertTrue(seq.allAcknowledged());
+    }
+    
+    public void testNextMessageNumber() {     
+        SourceSequence seq = null;        
+        setUpSource();
+        control.replay();
+        
+        // default termination policy
+
+        seq = new SourceSequence(id);  
+        seq.setSource(source);
+        assertTrue(!nextMessages(seq, 10));
+        control.verify();
+        
+        // termination policy max length = 1
+        
+        seq = new SourceSequence(id); 
+        seq.setSource(source);
+        stp.setMaxLength(BigInteger.ONE);
+        assertTrue(nextMessages(seq, 10));
+        assertEquals(BigInteger.ONE, seq.getCurrentMessageNr());
+        control.verify();
+        
+        // termination policy max length = 5
+        seq = new SourceSequence(id); 
+        seq.setSource(source);
+        stp.setMaxLength(new BigInteger("5"));
+        assertTrue(!nextMessages(seq, 2));
+        control.verify();
+        
+        // termination policy max range exceeded
+        
+        seq = new SourceSequence(id); 
+        seq.setSource(source);
+        stp.setMaxLength(null);
+        stp.setMaxRanges(new Integer(3));
+        acknowledge(seq, 1, 2, 4, 5, 6, 8, 9, 10);
+        assertTrue(nextMessages(seq, 10));
+        assertEquals(BigInteger.ONE, seq.getCurrentMessageNr());
+        control.verify();
+        
+        // termination policy max range not exceeded
+        
+        seq = new SourceSequence(id); 
+        seq.setSource(source);
+        stp.setMaxLength(null);
+        stp.setMaxRanges(new Integer(4));
+        acknowledge(seq, 1, 2, 4, 5, 6, 8, 9, 10);
+        assertTrue(!nextMessages(seq, 10));
+        control.verify();
+        
+        // termination policy max unacknowledged 
+    }
+    
+    public void testGetEndpointIdentfier() {
+        setUpSource();
+        QName qn = new QName("abc", "xyz");
+        EasyMock.expect(source.getName()).andReturn(qn);
+        control.replay();
+        
+        SourceSequence seq = new SourceSequence(id);
+        seq.setSource(source);
+        assertEquals("Unexpected endpoint identifier", "{abc}xyz", seq.getEndpointIdentifier());
+        control.verify();
+    }
+    
+    public void testCheckOfferingSequenceClosed() {
+        SourceSequence seq = null;
+        
+        setUpSource();
+ 
+        RMEndpoint rme = control.createMock(RMEndpoint.class);
+        EasyMock.expect(source.getReliableEndpoint()).andReturn(rme).anyTimes();
+        Destination destination = control.createMock(Destination.class);
+        EasyMock.expect(rme.getDestination()).andReturn(destination).anyTimes();
+        DestinationSequence dseq = control.createMock(DestinationSequence.class); 
+        Identifier did = control.createMock(Identifier.class);
+        EasyMock.expect(destination.getSequence(did)).andReturn(dseq).anyTimes();
+        EasyMock.expect(dseq.getLastMessageNumber()).andReturn(BigInteger.ONE).anyTimes();
+        EasyMock.expect(did.getValue()).andReturn("dseq").anyTimes();
+        
+        control.replay();
+        
+        seq = new SourceSequence(id, null, did);  
+        seq.setSource(source);        
+        seq.nextMessageNumber(did, BigInteger.ONE);
+        assertTrue(seq.isLastMessage());
+        
+        control.verify();
+    }
+   
+    private boolean nextMessages(SourceSequence seq, 
+                                 int n) {
+        int i = 0;
+        while ((i < n) && !seq.isLastMessage()) {            
+            assertNotNull(seq.nextMessageNumber());
+            i++;
+        }
+        return seq.isLastMessage();
+    }
+    
+    protected void acknowledge(SourceSequence seq, int... messageNumbers) {
+        SequenceAcknowledgement ack = factory.createSequenceAcknowledgement();
+        int i = 0;
+        while (i < messageNumbers.length) {
+            SequenceAcknowledgement.AcknowledgementRange r = 
+                factory.createSequenceAcknowledgementAcknowledgementRange();
+            Integer li = new Integer(messageNumbers[i]);
+            BigInteger l = new BigInteger(li.toString());
+            r.setLower(l);
+            i++;
+            
+            while (i < messageNumbers.length && (messageNumbers[i] - messageNumbers[i
- 1]) == 1) {
+                i++;
+            }
+            Integer ui = new Integer(messageNumbers[i - 1]);
+            BigInteger u = new BigInteger(ui.toString());
+            r.setUpper(u);
+            ack.getAcknowledgementRange().add(r);
+        }
+        seq.setAcknowledged(ack);
+    }
+}

Propchange: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/SourceSequenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/SourceSequenceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptorTest.java?view=diff&rev=470005&r1=470004&r2=470005
==============================================================================
--- incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptorTest.java
(original)
+++ incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInterceptorTest.java
Wed Nov  1 09:36:06 2006
@@ -195,7 +195,6 @@
                                              RMConstants.WSRM_ACK_REQUESTED_NAME});
     }
 
-
     public void testDecodeSequence() throws XMLStreamException {
         SoapMessage message = setUpInboundMessage("resources/Message1.xml");
         RMSoapInterceptor codec = new RMSoapInterceptor();



Mime
View raw message