| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2011 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Bernd Hufmann - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | package org.eclipse.linuxtools.tmf.tests.uml2sd; |
| 13 | |
| 14 | import junit.framework.TestCase; |
| 15 | |
| 16 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
| 17 | import org.eclipse.linuxtools.tmf.event.TmfEventContent; |
| 18 | import org.eclipse.linuxtools.tmf.event.TmfEventReference; |
| 19 | import org.eclipse.linuxtools.tmf.event.TmfEventSource; |
| 20 | import org.eclipse.linuxtools.tmf.event.TmfEventType; |
| 21 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; |
| 22 | import org.eclipse.linuxtools.tmf.uml2sd.TmfSyncSequenceDiagramEvent; |
| 23 | |
| 24 | @SuppressWarnings("nls") |
| 25 | public class TmfSyncSequenceDiagramEventTest extends TestCase { |
| 26 | |
| 27 | private final String fTypeId = "Some type"; |
| 28 | private final String fLabel0 = "label1"; |
| 29 | private final String fLabel1 = "label2"; |
| 30 | private final String[] fLabels = new String[] { fLabel0, fLabel1 }; |
| 31 | |
| 32 | private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5); |
| 33 | private final TmfEventSource fSource = new TmfEventSource("Source"); |
| 34 | private final TmfEventType fType = new TmfEventType(fTypeId, fLabels); |
| 35 | private final TmfEventReference fReference = new TmfEventReference("Some reference"); |
| 36 | |
| 37 | private final TmfEvent fEvent1; |
| 38 | private final TmfEventContent fContent1; |
| 39 | |
| 40 | public TmfSyncSequenceDiagramEventTest () { |
| 41 | fEvent1 = new TmfEvent(fTimestamp1, fSource, fType, fReference); |
| 42 | fContent1 = new TmfEventContent(fEvent1, "Some content"); |
| 43 | fEvent1.setContent(fContent1); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void setUp() throws Exception { |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public void tearDown() throws Exception { |
| 52 | } |
| 53 | |
| 54 | public void testTmfSyncSequenceDiagramEvent() { |
| 55 | TmfSyncSequenceDiagramEvent event = null; |
| 56 | try { |
| 57 | event = new TmfSyncSequenceDiagramEvent(null, null, null, null); |
| 58 | fail(); |
| 59 | } catch (IllegalArgumentException e) { |
| 60 | // success |
| 61 | assertTrue("testTmfSyncSequenceDiagramEvent", e.getMessage().contains("startEvent=null")); |
| 62 | } |
| 63 | |
| 64 | try { |
| 65 | event = new TmfSyncSequenceDiagramEvent(fEvent1, null, null, null); |
| 66 | fail(); |
| 67 | } catch (IllegalArgumentException e) { |
| 68 | // success |
| 69 | assertTrue("testTmfSyncSequenceDiagramEvent", e.getMessage().contains("sender=null")); |
| 70 | } |
| 71 | |
| 72 | try { |
| 73 | event = new TmfSyncSequenceDiagramEvent(fEvent1, "sender", null, null); |
| 74 | fail(); |
| 75 | } catch (IllegalArgumentException e) { |
| 76 | // success |
| 77 | assertTrue("testTmfSyncSequenceDiagramEvent", e.getMessage().contains("receiver=null")); |
| 78 | } |
| 79 | |
| 80 | try { |
| 81 | event = new TmfSyncSequenceDiagramEvent(fEvent1, "sender", "receiver", null); |
| 82 | fail(); |
| 83 | } catch (IllegalArgumentException e) { |
| 84 | // success |
| 85 | assertTrue("testTmfSyncSequenceDiagramEvent", e.getMessage().contains("name=null")); |
| 86 | } |
| 87 | |
| 88 | try { |
| 89 | event = new TmfSyncSequenceDiagramEvent(fEvent1, "sender", "receiver", "signal"); |
| 90 | // success |
| 91 | assertEquals("testTmfSyncSequenceDiagramEvent", 0, event.getStartTime().compareTo(fTimestamp1, true)); |
| 92 | assertEquals("testTmfSyncSequenceDiagramEvent", "sender", event.getSender()); |
| 93 | assertEquals("testTmfSyncSequenceDiagramEvent", "receiver", event.getReceiver()); |
| 94 | assertEquals("testTmfSyncSequenceDiagramEvent", "signal", event.getName()); |
| 95 | |
| 96 | } catch (IllegalArgumentException e) { |
| 97 | fail(); |
| 98 | } |
| 99 | } |
| 100 | } |