You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StructureViewManagerTest.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * Helen Hawkins Converted to new interface (bug 148190)
  12. * ******************************************************************/
  13. package org.aspectj.ajde.ui;
  14. import java.io.File;
  15. import java.util.Iterator;
  16. import org.aspectj.ajde.Ajde;
  17. import org.aspectj.ajde.AjdeTestCase;
  18. import org.aspectj.asm.AsmManager;
  19. import org.aspectj.asm.IHierarchy;
  20. import org.aspectj.asm.IProgramElement;
  21. import junit.framework.TestSuite;
  22. /**
  23. * @author Mik Kersten
  24. */
  25. public class StructureViewManagerTest extends AjdeTestCase {
  26. // TODO-path
  27. private final String CONFIG_FILE_PATH = "all.lst";
  28. private final String CONFIG_FILE_PATH_2 = "inheritance.lst";
  29. private FileStructureView currentView;
  30. private final NullIdeStructureViewRenderer renderer = new NullIdeStructureViewRenderer();
  31. private File testFile;
  32. private StructureViewProperties properties;
  33. public static void main(String[] args) {
  34. junit.swingui.TestRunner.run(StructureViewManagerTest.class);
  35. }
  36. public static TestSuite suite() {
  37. TestSuite result = new TestSuite();
  38. result.addTestSuite(StructureViewManagerTest.class);
  39. return result;
  40. }
  41. public void testModelExists() {
  42. assertTrue(Ajde.getDefault().getModel().getHierarchy() != null);
  43. }
  44. public void testNotificationAfterConfigFileChange() {
  45. initialiseProject("inheritance");
  46. doBuild(CONFIG_FILE_PATH_2);
  47. renderer.setHasBeenNotified(false);
  48. assertTrue("not yet notified", !renderer.getHasBeenNotified());
  49. Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(CONFIG_FILE_PATH_2);
  50. assertTrue("notified", renderer.getHasBeenNotified());
  51. renderer.setHasBeenNotified(false);
  52. Ajde.getDefault().getBuildConfigManager().setActiveConfigFile("MumbleDoesNotExist.lst");
  53. assertTrue("notified", renderer.getHasBeenNotified());
  54. assertTrue("no structure", currentView.getRootNode().getStructureNode().getChildren().get(0) == IHierarchy.NO_STRUCTURE);
  55. }
  56. /**
  57. * @todo this should be moved to a StructureModelManager test
  58. */
  59. public void testFreshStructureModelCreation() {
  60. renderer.setHasBeenNotified(false);
  61. String modelPath = genStructureModelExternFilePath(CONFIG_FILE_PATH);
  62. openFile(modelPath).delete();
  63. Ajde.getDefault().getModel().readStructureModel(CONFIG_FILE_PATH);
  64. assertTrue("notified", renderer.getHasBeenNotified());
  65. // AMC should this be currentView, or should we recreate the root... do the latter
  66. // IProgramElement n = currentView.getRootNode().getIProgramElement();
  67. IProgramElement n = Ajde.getDefault().getModel().getHierarchy().getRoot();
  68. assertTrue("no structure",
  69. // currentView.getRootNode().getIProgramElement().getChildren().get(0)
  70. n == IHierarchy.NO_STRUCTURE);
  71. }
  72. public void testModelIntegrity() {
  73. doBuild(CONFIG_FILE_PATH);
  74. IProgramElement modelRoot = Ajde.getDefault().getModel().getHierarchy().getRoot();
  75. assertTrue("root exists", modelRoot != null);
  76. try {
  77. testModelIntegrityHelper(modelRoot);
  78. } catch (Exception e) {
  79. assertTrue(e.toString(), false);
  80. }
  81. }
  82. private void testModelIntegrityHelper(IProgramElement node) throws Exception {
  83. for (IProgramElement child : node.getChildren()) {
  84. if (node == child.getParent()) {
  85. testModelIntegrityHelper(child);
  86. } else {
  87. throw new Exception("parent-child check failed for child: " + child.toString());
  88. }
  89. }
  90. }
  91. public void testNotificationAfterBuild() {
  92. renderer.setHasBeenNotified(false);
  93. doBuild(CONFIG_FILE_PATH);
  94. assertTrue("notified", renderer.getHasBeenNotified());
  95. }
  96. public void testViewCreationWithNullSourceFileAndProperties() {
  97. currentView = Ajde.getDefault().getStructureViewManager().createViewForSourceFile(null, null);
  98. assertTrue("no structure", currentView.getRootNode().getStructureNode() == IHierarchy.NO_STRUCTURE);
  99. }
  100. protected void setUp() throws Exception {
  101. super.setUp();
  102. AsmManager.forceSingletonBehaviour = true;
  103. initialiseProject("figures-coverage");
  104. doBuild(CONFIG_FILE_PATH);
  105. properties = Ajde.getDefault().getStructureViewManager().getDefaultViewProperties();
  106. // TODO-path
  107. testFile = openFile("../examples/figures-coverage/figures/Figure.java");
  108. currentView = Ajde.getDefault().getStructureViewManager().createViewForSourceFile(testFile.getAbsolutePath(), properties);
  109. currentView.setRenderer(renderer);
  110. }
  111. protected void tearDown() throws Exception {
  112. super.tearDown();
  113. AsmManager.forceSingletonBehaviour = false;
  114. }
  115. }