X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tmf%2Forg.eclipse.tracecompass.tmf.ui.tests%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Ftmf%2Fui%2Ftests%2Fviews%2FTmfViewFactoryTest.java;fp=tmf%2Forg.eclipse.tracecompass.tmf.ui.tests%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Ftmf%2Fui%2Ftests%2Fviews%2FTmfViewFactoryTest.java;h=d0e71b4bc6e52f30db1e3b19ce984bba790117b6;hb=fe231cf6edbeea0fabce88e3bf249ce3e5186fe3;hp=0000000000000000000000000000000000000000;hpb=c389833c3f47a594d1e70b5d5244d25e3724f7f0;p=deliverable%2Ftracecompass.git diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/views/TmfViewFactoryTest.java b/tmf/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/views/TmfViewFactoryTest.java new file mode 100644 index 0000000000..d0e71b4bc6 --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/views/TmfViewFactoryTest.java @@ -0,0 +1,125 @@ +/********************************************************************** + * Copyright (c) 2016 EfficiOS Inc. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + **********************************************************************/ + +package org.eclipse.tracecompass.tmf.ui.tests.views; + +import static org.junit.Assert.*; +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + +import java.util.Arrays; + +import org.eclipse.tracecompass.tmf.ui.tests.stubs.views.TmfViewStub; +import org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.junit.Test; + +/** + * Test the {@link org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory} class + * and its utility method. + * + * @author Jonathan Rajotte Julien + */ +public class TmfViewFactoryTest { + + /* The internal separator */ + private static final String SEPARATOR = TmfViewFactory.INTERNAL_SECONDARY_ID_SEPARATOR; + private static final String UUID = "90148656-2bd7-4f3e-8513-4def0ac76b1f"; + + BaseSecIdTestCase[] baseSecIdTestCases = { + new BaseSecIdTestCase(null, null), + new BaseSecIdTestCase(UUID, null), + new BaseSecIdTestCase(SEPARATOR + UUID, ""), + new BaseSecIdTestCase(SEPARATOR + "1-1-1-1-1", SEPARATOR + "1-1-1-1-1"), + new BaseSecIdTestCase("sec_id", "sec_id"), + new BaseSecIdTestCase("sec_id" + SEPARATOR, "sec_id" + SEPARATOR), + new BaseSecIdTestCase("sec_id" + SEPARATOR + UUID, "sec_id"), + new BaseSecIdTestCase("sec_id" + SEPARATOR + SEPARATOR + UUID, "sec_id" + SEPARATOR), + new BaseSecIdTestCase("sec_id" + SEPARATOR + "third_id", "sec_id" + SEPARATOR + "third_id"), + new BaseSecIdTestCase("sec_id" + SEPARATOR + "third_id" + SEPARATOR + UUID, "sec_id" + SEPARATOR + "third_id"), + new BaseSecIdTestCase("sec_id" + SEPARATOR + "third_id" + SEPARATOR + "fourth_id", "sec_id" + SEPARATOR + "third_id" + SEPARATOR + "fourth_id"), + }; + + private static class BaseSecIdTestCase { + private String input; + private String output; + + public BaseSecIdTestCase(String input, String secondaryId) { + this.input = input; + this.output = secondaryId; + } + + public String getInput() { + return input; + } + + public String getOutput() { + return output; + } + } + + /** + * Test method for + * {@link org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory#getBaseSecId(java.lang.String)}. + */ + @Test + public void testGetBaseSecId() { + for (BaseSecIdTestCase testCase : baseSecIdTestCases) { + String input = testCase.getInput(); + String expect = testCase.getOutput(); + String result = TmfViewFactory.getBaseSecId(input); + String message = String.format("Input:%s Output: %s Expected: %s", input, result, expect); + + assertEquals(message, expect, result); + } + } + + /** + * Test method for + * {@link org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory#newView(java.lang.String, boolean)}. + */ + @Test + public void testNewView() { + IViewPart firstView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), false); + IViewPart sameAsFirstView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), false); + IViewPart secondView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), true); + IViewPart failView1 = TmfViewFactory.newView("this.is.a.failing.view.id", false); + IViewPart failView2 = TmfViewFactory.newView("this.is.a.failing.view.id", true); + + assertNotNull("Failed to spawn first view", firstView); + assertEquals("Same id returned different instance", sameAsFirstView, firstView); + assertNotNull("Failed to open second view with suffix", secondView); + assertNull("Expected to fail on dummy view id", failView1); + assertNull("Expected to fail on dummy view id with suffix", failView2); + + /** Test for new view from a duplicate view */ + /* Fetch duplicate view complete id */ + IWorkbench wb = PlatformUI.getWorkbench(); + IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); + IWorkbenchPage page = win.getActivePage(); + IViewReference[] viewRefs = page.getViewReferences(); + + String fullId = null; + for (IViewReference view : viewRefs) { + if (view.getSecondaryId() != null && view.getId().equals(TmfViewStub.TMF_VIEW_STUB_ID)) { + assertTrue("Instanceof a TMfViewStub", view.getView(false) instanceof TmfViewStub); + fullId = ((TmfViewStub) view.getView(false)).getViewId(); + break; + } + } + assertNotNull(fullId); + IViewPart thirdView = TmfViewFactory.newView(fullId, true); + assertNotNull("Creation from a view id with suffix failed", fullId); + assertFalse("New view from view id with suffix was not created", Arrays.asList(viewRefs).contains(thirdView)); + } +}