private void procComponents(Component[] compp) { if (compp != null) { for (Component c : compp) { EventType et = null; if (c.getType() == ComponentType.Invoke) { et = EventType.Invoke; } if (c.getType() == ComponentType.ReturnResult) { et = EventType.ReturnResult; } if (c.getType() == ComponentType.ReturnResultLast) { et = EventType.ReturnResultLast; } if (c.getType() == ComponentType.ReturnError) { et = EventType.ReturnError; } if (c.getType() == ComponentType.Reject) { et = EventType.Reject; } TestEvent te = TestEvent.createReceivedEvent(et, c, sequence++); this.observerdEvents.add(te); } } }
public void addNewReturnError(Long invokeId) throws Exception { ReturnError err = this.tcapProvider.getComponentPrimitiveFactory().createTCReturnErrorRequest(); err.setInvokeId(invokeId); ErrorCode ec = this.tcapProvider.getComponentPrimitiveFactory().createErrorCode(); ec.setLocalErrorCode(10L); err.setErrorCode(ec); TestEvent te = TestEvent.createSentEvent(EventType.ReturnError, null, sequence++); this.observerdEvents.add(te); this.dialog.sendComponent(err); }
public void addNewReturnResult(Long invokeId) throws Exception { ReturnResult rr = this.tcapProvider.getComponentPrimitiveFactory().createTCResultRequest(); rr.setInvokeId(invokeId); OperationCode oc = TcapFactory.createOperationCode(); oc.setLocalOperationCode(10L); rr.setOperationCode(oc); TestEvent te = TestEvent.createSentEvent(EventType.ReturnResult, null, sequence++); this.observerdEvents.add(te); this.dialog.sendComponent(rr); }
public void addNewInvoke(Long invokeId, Long timout) throws Exception { Invoke invoke = this.tcapProvider.getComponentPrimitiveFactory().createTCInvokeRequest(); invoke.setInvokeId(invokeId); OperationCode oc = TcapFactory.createOperationCode(); oc.setLocalOperationCode(10L); invoke.setOperationCode(oc); invoke.setTimeout(timout); // Parameter p1 = TcapFactory.createParameter(); // p1.setTagClass(Tag.CLASS_UNIVERSAL); // p1.setTag(Tag.STRING_OCTET); // p1.setData(new byte[]{0x0F}); // // Parameter p2 = TcapFactory.createParameter(); // p2.setTagClass(Tag.CLASS_UNIVERSAL); // p2.setTag(Tag.STRING_OCTET); // p2.setData(new byte[] { (byte) 0xaa, (byte) 0x98, (byte) 0xac, (byte) 0xa6, 0x5a, (byte) // 0xcd, 0x62, 0x36, 0x19, // 0x0e, 0x37, (byte) 0xcb, (byte) 0xe5, // 0x72, (byte) 0xb9, 0x11 }); // // Parameter pm = TcapFactory.createParameter(); // pm.setTagClass(Tag.CLASS_UNIVERSAL); // pm.setTag(Tag.SEQUENCE); // pm.setParameters(new Parameter[]{p1, p2}); // invoke.setParameter(pm); TestEvent te = TestEvent.createSentEvent(EventType.Invoke, null, sequence++); this.observerdEvents.add(te); this.dialog.sendComponent(invoke); lastSentInvoke = invoke; }
/** * Sending BadlyStructuredComponent Component * * <p>TC-BEGIN + Invoke with BadlyStructuredComponent + Invoke TC-END + Reject (mistypedComponent) */ @Test(groups = {"functional.flow"}) public void BadlyStructuredComponentTest() throws Exception { this.client = new ClientComponent(this.tcapStack1, peer1Address, peer2Address) { @Override public void onTCEnd(TCEndIndication ind) { super.onTCEnd(ind); assertEquals(ind.getComponents().length, 1); Component c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); Reject r = (Reject) c; assertNull(r.getInvokeId()); assertEquals( r.getProblem().getGeneralProblemType(), GeneralProblemType.BadlyStructuredComponent); assertFalse(r.isLocalOriginated()); } }; this.server = new ServerComponent(this.tcapStack2, peer2Address, peer1Address) { @Override public void onTCBegin(TCBeginIndication ind) { super.onTCBegin(ind); assertEquals(ind.getComponents().length, 2); Component c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); Reject r = (Reject) c; assertNull(r.getInvokeId()); assertEquals( r.getProblem().getGeneralProblemType(), GeneralProblemType.BadlyStructuredComponent); assertTrue(r.isLocalOriginated()); try { this.sendEnd(TerminationType.Basic); } catch (Exception e) { fail("Exception when sendComponent / send message 1", e); e.printStackTrace(); } } }; long stamp = System.currentTimeMillis(); int cnt = 0; List<TestEvent> clientExpectedEvents = new ArrayList<TestEvent>(); TestEvent te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Begin, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.End, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.DialogRelease, null, cnt++, stamp); clientExpectedEvents.add(te); cnt = 0; List<TestEvent> serverExpectedEvents = new ArrayList<TestEvent>(); te = TestEvent.createReceivedEvent(EventType.Begin, null, cnt++, stamp); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Invoke, null, cnt++, stamp); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.End, null, cnt++, stamp); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.DialogRelease, null, cnt++, stamp); serverExpectedEvents.add(te); client.startClientDialog(); Component badComp = new BadComponentBadlyStructuredComponent(); badComp.setInvokeId(1L); client.dialog.sendComponent(badComp); client.addNewInvoke(2L, 10000L); client.sendBegin(); client.waitFor(WAIT_TIME); client.compareEvents(clientExpectedEvents); server.compareEvents(serverExpectedEvents); }
/** * Testing diplicateInvokeId case All Invokes are with a little invokeTimeout(removed before an * answer from a Server) !!! * * <p>TC-BEGIN + Invoke (invokeId==1) TC-CONTINUE + ReturnResult (invokeId==1) TC-CONTINUE + * Reject(unrecognizedInvokeId) + Invoke (invokeId==1) TC-CONTINUE + Reject (duplicateInvokeId) * TC-CONTINUE + Invoke (invokeId==2) TC-CONTINUE + ReturnResultLast (invokeId==1) + ReturnError * (invokeId==2) TC-CONTINUE + Invoke (invokeId==1, for this message we will invoke * processWithoutAnswer()) + Invoke (invokeId==2) TC-CONTINUE TC-CONTINUE + Invoke (invokeId==1) + * Invoke (invokeId==2) * TC-END + Reject (duplicateInvokeId for invokeId==2) */ @Test(groups = {"functional.flow"}) public void DuplicateInvokeIdTest() throws Exception { this.client = new ClientComponent(this.tcapStack1, peer1Address, peer2Address) { @Override public void onTCContinue(TCContinueIndication ind) { super.onTCContinue(ind); step++; try { switch (step) { case 1: assertEquals(ind.getComponents().length, 1); Component c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); Reject r = (Reject) c; assertEquals((long) r.getInvokeId(), 1); assertEquals( r.getProblem().getReturnResultProblemType(), ReturnResultProblemType.UnrecognizedInvokeID); assertTrue(r.isLocalOriginated()); this.addNewInvoke(1L, 5L); this.sendContinue(); break; case 2: assertEquals(ind.getComponents().length, 1); c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); r = (Reject) c; assertEquals((long) r.getInvokeId(), 1); assertEquals( r.getProblem().getInvokeProblemType(), InvokeProblemType.DuplicateInvokeID); assertFalse(r.isLocalOriginated()); this.addNewInvoke(2L, 5L); this.sendContinue(); break; case 3: assertEquals(ind.getComponents().length, 2); c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); r = (Reject) c; assertEquals((long) r.getInvokeId(), 1); assertEquals( r.getProblem().getReturnResultProblemType(), ReturnResultProblemType.UnrecognizedInvokeID); assertTrue(r.isLocalOriginated()); c = ind.getComponents()[1]; assertEquals(c.getType(), ComponentType.Reject); r = (Reject) c; assertEquals((long) r.getInvokeId(), 2); assertEquals( r.getProblem().getReturnErrorProblemType(), ReturnErrorProblemType.UnrecognizedInvokeID); assertTrue(r.isLocalOriginated()); this.addNewInvoke(1L, 5L); this.addNewInvoke(2L, 5L); this.sendContinue(); break; case 4: this.addNewInvoke(1L, 10000L); this.addNewInvoke(2L, 10000L); this.sendContinue(); break; } } catch (Exception e) { fail("Exception when sendComponent / send message 2", e); e.printStackTrace(); } } @Override public void onTCEnd(TCEndIndication ind) { super.onTCEnd(ind); try { assertEquals(ind.getComponents().length, 1); Component c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); Reject r = (Reject) c; assertEquals((long) r.getInvokeId(), 2); assertEquals( r.getProblem().getInvokeProblemType(), InvokeProblemType.DuplicateInvokeID); assertFalse(r.isLocalOriginated()); } catch (Exception e) { fail("Exception when sendComponent / send message 3", e); e.printStackTrace(); } } }; this.server = new ServerComponent(this.tcapStack2, peer2Address, peer1Address) { @Override public void onTCBegin(TCBeginIndication ind) { super.onTCBegin(ind); // waiting for Invoke timeout at a client side client.waitFor(MINI_WAIT_TIME); try { this.addNewReturnResult(1L); this.sendContinue(); } catch (Exception e) { fail("Exception when sendComponent / send message 1", e); e.printStackTrace(); } } @Override public void onTCContinue(TCContinueIndication ind) { super.onTCContinue(ind); // waiting for Invoke timeout at a client side client.waitFor(MINI_WAIT_TIME); step++; try { switch (step) { case 1: assertEquals(ind.getComponents().length, 2); Component c = ind.getComponents()[0]; assertEquals(c.getType(), ComponentType.Reject); Reject r = (Reject) c; assertEquals((long) r.getInvokeId(), 1); assertEquals( r.getProblem().getReturnResultProblemType(), ReturnResultProblemType.UnrecognizedInvokeID); assertFalse(r.isLocalOriginated()); c = ind.getComponents()[1]; assertEquals(c.getType(), ComponentType.Reject); r = (Reject) c; assertEquals((long) r.getInvokeId(), 1); assertEquals( r.getProblem().getInvokeProblemType(), InvokeProblemType.DuplicateInvokeID); assertTrue(r.isLocalOriginated()); this.sendContinue(); break; case 2: this.addNewReturnResultLast(1L); this.addNewReturnError(2L); this.sendContinue(); break; case 3: this.dialog.processInvokeWithoutAnswer(1L); this.sendContinue(); break; case 4: assertEquals(ind.getComponents().length, 2); c = ind.getComponents()[1]; assertEquals(c.getType(), ComponentType.Reject); r = (Reject) c; assertEquals((long) r.getInvokeId(), 2); assertEquals( r.getProblem().getInvokeProblemType(), InvokeProblemType.DuplicateInvokeID); assertTrue(r.isLocalOriginated()); this.sendEnd(TerminationType.Basic); break; } } catch (Exception e) { fail("Exception when sendComponent / send message 2", e); e.printStackTrace(); } } }; long stamp = System.currentTimeMillis(); int cnt = 0; List<TestEvent> clientExpectedEvents = new ArrayList<TestEvent>(); TestEvent te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Begin, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.InvokeTimeout, null, cnt++, stamp); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.InvokeTimeout, null, cnt++, stamp + MINI_WAIT_TIME); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 2); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 2); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 2); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 2); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent( EventType.InvokeTimeout, null, cnt++, stamp + MINI_WAIT_TIME * 2); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent( EventType.InvokeTimeout, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent( EventType.InvokeTimeout, null, cnt++, stamp + MINI_WAIT_TIME * 3); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 4); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 4); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 4); clientExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 4); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.End, null, cnt++, stamp + MINI_WAIT_TIME * 5); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 5); clientExpectedEvents.add(te); te = TestEvent.createReceivedEvent( EventType.DialogRelease, null, cnt++, stamp + MINI_WAIT_TIME * 5); clientExpectedEvents.add(te); cnt = 0; List<TestEvent> serverExpectedEvents = new ArrayList<TestEvent>(); te = TestEvent.createReceivedEvent(EventType.Begin, null, cnt++, stamp); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Invoke, null, cnt++, stamp); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.ReturnResult, null, cnt++, stamp + MINI_WAIT_TIME); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 2); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 2); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 2); serverExpectedEvents.add(te); te = TestEvent.createSentEvent( EventType.ReturnResultLast, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.ReturnError, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 3); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 4); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Continue, null, cnt++, stamp + MINI_WAIT_TIME * 4); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Invoke, null, cnt++, stamp + MINI_WAIT_TIME * 4); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent(EventType.Reject, null, cnt++, stamp + MINI_WAIT_TIME * 4); serverExpectedEvents.add(te); te = TestEvent.createSentEvent(EventType.End, null, cnt++, stamp + MINI_WAIT_TIME * 5); serverExpectedEvents.add(te); te = TestEvent.createReceivedEvent( EventType.DialogRelease, null, cnt++, stamp + MINI_WAIT_TIME * 5); serverExpectedEvents.add(te); client.startClientDialog(); client.addNewInvoke(1L, 5L); client.sendBegin(); client.waitFor(WAIT_TIME * 2); client.compareEvents(clientExpectedEvents); server.compareEvents(serverExpectedEvents); }