1 /******************************************************************************* 2 * Copyright (c) 2008, 2017 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.pde.internal.ua.tests.cheatsheet; 15 16 import org.eclipse.pde.internal.ua.core.cheatsheet.simple.ISimpleCS; 17 import org.eclipse.pde.internal.ua.core.cheatsheet.simple.ISimpleCSItem; 18 import org.eclipse.pde.internal.ua.core.cheatsheet.simple.ISimpleCSSubItemObject; 19 import org.eclipse.pde.internal.ua.core.cheatsheet.simple.text.SimpleCSSubItem; 20 import org.junit.Test; 21 22 /** 23 * Cheatsheet subitems tests for XML-generated models. 24 */ 25 public class SimpleCSSubItemTestCase extends CheatSheetModelTestCase { 26 27 @Test testSimpleSubItemTestCase()28 public void testSimpleSubItemTestCase() { 29 simpleSubItemTestCase(1, LF); 30 } 31 32 @Test testSimpleSubItemCommandTestCase()33 public void testSimpleSubItemCommandTestCase() { 34 simpleSubItemCommandTestCase(1, LF); 35 } 36 37 @Test testSimpleSubItemActionTestCase()38 public void testSimpleSubItemActionTestCase() { 39 simpleSubItemActionTestCase(1, LF); 40 } 41 42 @Test testSimpleRepeatedSubItemTestCase()43 public void testSimpleRepeatedSubItemTestCase() { 44 simpleRepeatedSubItemTestCase(1, LF); 45 } 46 47 @Test testSimpleConditionalSubItemTestCase()48 public void testSimpleConditionalSubItemTestCase() { 49 simpleConditionalSubItemTestCase(1, LF); 50 } 51 52 @Test testSimpleSubItemTestCase3()53 public void testSimpleSubItemTestCase3() { 54 simpleSubItemTestCase(3, LF); 55 } 56 57 @Test testSimpleSubItemCommandTestCase3()58 public void testSimpleSubItemCommandTestCase3() { 59 simpleSubItemCommandTestCase(3, LF); 60 } 61 62 @Test testSimpleSubItemActionTestCase3()63 public void testSimpleSubItemActionTestCase3() { 64 simpleSubItemActionTestCase(3, LF); 65 } 66 67 @Test testSimpleRepeatedSubItemTestCase3()68 public void testSimpleRepeatedSubItemTestCase3() { 69 simpleRepeatedSubItemTestCase(3, LF); 70 } 71 72 @Test testSimpleConditionalSubItemTestCase3()73 public void testSimpleConditionalSubItemTestCase3() { 74 simpleConditionalSubItemTestCase(3, LF); 75 } 76 simpleSubItemTestCase(int subitemsCount, String newline)77 public void simpleSubItemTestCase(int subitemsCount, String newline) { 78 StringBuilder buffer = new StringBuilder(); 79 80 for (int i =0; i < subitemsCount; i++) { 81 String action = createAction(newline); 82 buffer.append(createSubItem(action, newline)); 83 } 84 85 ISimpleCSItem item = process(buffer.toString(), newline); 86 validateSubItemsCount(subitemsCount, item); 87 88 for (int i = 0; i < subitemsCount; i++) { 89 ISimpleCSSubItemObject subitem = item.getSubItems()[i]; 90 validateSubItem(subitem); 91 } 92 } 93 simpleSubItemCommandTestCase(int subitemsCount, String newline)94 public void simpleSubItemCommandTestCase(int subitemsCount, String newline) { 95 StringBuilder buffer = new StringBuilder(); 96 97 for (int i =0; i < subitemsCount; i++) { 98 String action = createCommand(newline); 99 buffer.append(createSubItem(action, newline)); 100 } 101 102 ISimpleCSItem item = process(buffer.toString(), newline); 103 validateSubItemsCount(subitemsCount, item); 104 105 for (int i = 0; i < subitemsCount; i++) { 106 ISimpleCSSubItemObject subitem = item.getSubItems()[i]; 107 validateSubItem(subitem); 108 109 SimpleCSSubItem simpleSubitem = (SimpleCSSubItem) subitem; 110 validateCommand(simpleSubitem.getExecutable()); 111 } 112 } 113 simpleSubItemActionTestCase(int subitemsCount, String newline)114 public void simpleSubItemActionTestCase(int subitemsCount, String newline) { 115 StringBuilder buffer = new StringBuilder(); 116 117 for (int i =0; i < subitemsCount; i++) { 118 String action = createAction(newline); 119 buffer.append(createSubItem(action, newline)); 120 } 121 122 ISimpleCSItem item = process(buffer.toString(), newline); 123 validateSubItemsCount(subitemsCount, item); 124 125 for (int i = 0; i < subitemsCount; i++) { 126 ISimpleCSSubItemObject subitem = item.getSubItems()[i]; 127 validateSubItem(subitem); 128 129 SimpleCSSubItem simpleSubitem = (SimpleCSSubItem) subitem; 130 validateAction(simpleSubitem.getExecutable()); 131 } 132 } 133 simpleRepeatedSubItemTestCase(int subitemsCount, String newline)134 public void simpleRepeatedSubItemTestCase(int subitemsCount, String newline) { 135 StringBuilder buffer = new StringBuilder(); 136 137 for (int i =0; i < subitemsCount; i++) { 138 buffer.append(createRepeatedSubItem("", newline)); 139 } 140 141 ISimpleCSItem item = process(buffer.toString(), newline); 142 143 validateSubItemsCount(subitemsCount, item); 144 145 for (int i = 0; i < subitemsCount; i++) { 146 validateRepeatedSubItem(item.getSubItems()[i]); 147 } 148 } 149 simpleConditionalSubItemTestCase(int subitemsCount, String newline)150 public void simpleConditionalSubItemTestCase(int subitemsCount, String newline) { 151 StringBuilder buffer = new StringBuilder(); 152 153 for (int i =0; i < subitemsCount; i++) { 154 buffer.append(createConditionalSubItem("", newline)); 155 } 156 157 ISimpleCSItem item = process(buffer.toString(), newline); 158 159 validateSubItemsCount(subitemsCount, item); 160 161 for (int i = 0; i < subitemsCount; i++) { 162 validateConditionalSubItem(item.getSubItems()[i]); 163 } 164 } 165 process(String subitems, String newline)166 public ISimpleCSItem process(String subitems, String newline) { 167 StringBuilder buffer = createSimpleCSItem(subitems, newline); 168 169 setXMLContents(buffer, newline); 170 load(); 171 172 ISimpleCS model = fModel.getSimpleCS(); 173 174 validateItemsCount(1, model); 175 return model.getItems()[0]; 176 } 177 178 179 } 180