1 /******************************************************************************* 2 * Copyright (c) 2007, 2018 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.api.tools.comparator.tests; 15 16 import static org.junit.Assert.assertEquals; 17 import static org.junit.Assert.assertFalse; 18 import static org.junit.Assert.assertNotNull; 19 import static org.junit.Assert.assertTrue; 20 21 import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; 22 import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiComparator; 23 import org.eclipse.pde.api.tools.internal.provisional.comparator.DeltaProcessor; 24 import org.eclipse.pde.api.tools.internal.provisional.comparator.IDelta; 25 import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; 26 import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent; 27 import org.junit.Test; 28 29 /** 30 * Delta tests for annotation 31 */ 32 public class AnnotationDeltaTests extends DeltaTestSetup { 33 34 @Override getTestRoot()35 public String getTestRoot() { 36 return "annotation"; //$NON-NLS-1$ 37 } 38 39 /** 40 * Add element to annotation type 41 */ 42 @Test test1()43 public void test1() { 44 deployBundles("test1"); //$NON-NLS-1$ 45 IApiBaseline before = getBeforeState(); 46 IApiBaseline after = getAfterState(); 47 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 48 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 49 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 50 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 51 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 52 assertNotNull("No delta", delta); //$NON-NLS-1$ 53 IDelta[] allLeavesDeltas = collectLeaves(delta); 54 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 55 IDelta child = allLeavesDeltas[0]; 56 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 57 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 58 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 59 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 60 } 61 62 /** 63 * remove element to annotation type 64 */ 65 @Test test2()66 public void test2() { 67 deployBundles("test2"); //$NON-NLS-1$ 68 IApiBaseline before = getBeforeState(); 69 IApiBaseline after = getAfterState(); 70 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 71 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 72 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 73 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 74 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 75 assertNotNull("No delta", delta); //$NON-NLS-1$ 76 IDelta[] allLeavesDeltas = collectLeaves(delta); 77 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 78 IDelta child = allLeavesDeltas[0]; 79 assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ 80 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 81 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 82 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 83 } 84 85 /** 86 * Add element to annotation type 87 */ 88 @Test test3()89 public void test3() { 90 deployBundles("test3"); //$NON-NLS-1$ 91 IApiBaseline before = getBeforeState(); 92 IApiBaseline after = getAfterState(); 93 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 94 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 95 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 96 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 97 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 98 assertNotNull("No delta", delta); //$NON-NLS-1$ 99 IDelta[] allLeavesDeltas = collectLeaves(delta); 100 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 101 IDelta child = allLeavesDeltas[0]; 102 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 103 assertEquals("Wrong flag", IDelta.METHOD_WITHOUT_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 104 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 105 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 106 } 107 108 /** 109 * Add elements with all different types 110 */ 111 @Test test4()112 public void test4() { 113 deployBundles("test4"); //$NON-NLS-1$ 114 IApiBaseline before = getBeforeState(); 115 IApiBaseline after = getAfterState(); 116 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 117 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 118 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 119 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 120 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 121 assertNotNull("No delta", delta); //$NON-NLS-1$ 122 IDelta[] allLeavesDeltas = collectLeaves(delta); 123 assertEquals("Wrong size", 11, allLeavesDeltas.length); //$NON-NLS-1$ 124 IDelta child = allLeavesDeltas[0]; 125 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 126 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 127 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 128 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 129 child = allLeavesDeltas[1]; 130 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 131 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 132 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 133 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 134 child = allLeavesDeltas[2]; 135 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 136 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 137 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 138 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 139 child = allLeavesDeltas[3]; 140 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 141 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 142 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 143 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 144 child = allLeavesDeltas[4]; 145 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 146 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 147 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 148 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 149 child = allLeavesDeltas[5]; 150 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 151 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 152 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 153 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 154 child = allLeavesDeltas[6]; 155 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 156 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 157 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 158 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 159 child = allLeavesDeltas[7]; 160 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 161 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 162 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 163 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 164 child = allLeavesDeltas[8]; 165 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 166 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 167 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 168 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 169 child = allLeavesDeltas[9]; 170 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 171 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 172 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 173 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 174 child = allLeavesDeltas[10]; 175 assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ 176 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 177 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 178 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 179 } 180 /** 181 * Add elements with all different types (array) 182 */ 183 @Test test5()184 public void test5() { 185 deployBundles("test5"); //$NON-NLS-1$ 186 IApiBaseline before = getBeforeState(); 187 IApiBaseline after = getAfterState(); 188 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 189 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 190 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 191 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 192 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 193 assertNotNull("No delta", delta); //$NON-NLS-1$ 194 IDelta[] allLeavesDeltas = collectLeaves(delta); 195 assertEquals("Wrong size", 13, allLeavesDeltas.length); //$NON-NLS-1$ 196 IDelta child = allLeavesDeltas[0]; 197 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 198 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 199 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 200 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 201 child = allLeavesDeltas[1]; 202 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 203 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 204 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 205 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 206 child = allLeavesDeltas[2]; 207 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 208 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 209 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 210 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 211 child = allLeavesDeltas[3]; 212 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 213 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 214 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 215 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 216 child = allLeavesDeltas[4]; 217 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 218 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 219 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 220 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 221 child = allLeavesDeltas[5]; 222 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 223 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 224 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 225 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 226 child = allLeavesDeltas[6]; 227 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 228 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 229 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 230 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 231 child = allLeavesDeltas[7]; 232 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 233 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 234 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 235 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 236 child = allLeavesDeltas[8]; 237 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 238 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 239 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 240 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 241 child = allLeavesDeltas[9]; 242 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 243 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 244 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 245 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 246 child = allLeavesDeltas[10]; 247 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 248 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 249 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 250 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 251 child = allLeavesDeltas[11]; 252 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 253 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 254 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 255 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 256 child = allLeavesDeltas[12]; 257 assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ 258 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 259 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 260 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 261 } 262 263 /** 264 * Changed default values 265 */ 266 @Test test6()267 public void test6() { 268 deployBundles("test6"); //$NON-NLS-1$ 269 IApiBaseline before = getBeforeState(); 270 IApiBaseline after = getAfterState(); 271 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 272 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 273 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 274 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 275 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 276 assertNotNull("No delta", delta); //$NON-NLS-1$ 277 IDelta[] allLeavesDeltas = collectLeaves(delta); 278 assertEquals("Wrong size", 12, allLeavesDeltas.length); //$NON-NLS-1$ 279 IDelta child = allLeavesDeltas[0]; 280 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 281 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 282 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 283 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 284 child = allLeavesDeltas[1]; 285 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 286 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 287 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 288 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 289 child = allLeavesDeltas[2]; 290 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 291 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 292 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 293 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 294 child= allLeavesDeltas[3]; 295 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 296 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 297 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 298 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 299 child = allLeavesDeltas[4]; 300 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 301 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 302 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 303 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 304 child = allLeavesDeltas[5]; 305 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 306 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 307 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 308 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 309 child = allLeavesDeltas[6]; 310 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 311 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 312 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 313 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 314 child = allLeavesDeltas[7]; 315 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 316 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 317 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 318 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 319 child = allLeavesDeltas[8]; 320 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 321 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 322 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 323 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 324 child = allLeavesDeltas[9]; 325 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 326 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 327 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 328 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 329 child = allLeavesDeltas[10]; 330 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 331 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 332 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 333 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 334 child = allLeavesDeltas[11]; 335 assertEquals("Wrong kind", IDelta.CHANGED, child.getKind()); //$NON-NLS-1$ 336 assertEquals("Wrong flag", IDelta.ANNOTATION_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 337 assertEquals("Wrong element type", IDelta.METHOD_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 338 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 339 } 340 341 /** 342 * Remove method with default value 343 */ 344 @Test test7()345 public void test7() { 346 deployBundles("test7"); //$NON-NLS-1$ 347 IApiBaseline before = getBeforeState(); 348 IApiBaseline after = getAfterState(); 349 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 350 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 351 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 352 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 353 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 354 assertNotNull("No delta", delta); //$NON-NLS-1$ 355 IDelta[] allLeavesDeltas = collectLeaves(delta); 356 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 357 IDelta child = allLeavesDeltas[0]; 358 assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ 359 assertEquals("Wrong flag", IDelta.METHOD_WITH_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 360 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 361 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 362 } 363 364 /** 365 * Remove method with no default value 366 */ 367 @Test test8()368 public void test8() { 369 deployBundles("test8"); //$NON-NLS-1$ 370 IApiBaseline before = getBeforeState(); 371 IApiBaseline after = getAfterState(); 372 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 373 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 374 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 375 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 376 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 377 assertNotNull("No delta", delta); //$NON-NLS-1$ 378 IDelta[] allLeavesDeltas = collectLeaves(delta); 379 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 380 IDelta child = allLeavesDeltas[0]; 381 assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ 382 assertEquals("Wrong flag", IDelta.METHOD_WITHOUT_DEFAULT_VALUE, child.getFlags()); //$NON-NLS-1$ 383 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 384 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 385 } 386 387 /** 388 * Add a field 389 */ 390 @Test test9()391 public void test9() { 392 deployBundles("test9"); //$NON-NLS-1$ 393 IApiBaseline before = getBeforeState(); 394 IApiBaseline after = getAfterState(); 395 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 396 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 397 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 398 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 399 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.ALL_VISIBILITIES, null); 400 assertNotNull("No delta", delta); //$NON-NLS-1$ 401 IDelta[] allLeavesDeltas = collectLeaves(delta); 402 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 403 IDelta child = allLeavesDeltas[0]; 404 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 405 assertEquals("Wrong flag", IDelta.FIELD, child.getFlags()); //$NON-NLS-1$ 406 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 407 assertFalse("Is compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 408 } 409 /** 410 * Added deprecation 411 */ 412 @Test test10()413 public void test10() { 414 deployBundles("test10"); //$NON-NLS-1$ 415 IApiBaseline before = getBeforeState(); 416 IApiBaseline after = getAfterState(); 417 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 418 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 419 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 420 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 421 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.API, null); 422 assertNotNull("No delta", delta); //$NON-NLS-1$ 423 IDelta[] allLeavesDeltas = collectLeaves(delta); 424 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 425 IDelta child = allLeavesDeltas[0]; 426 assertEquals("Wrong kind", IDelta.ADDED, child.getKind()); //$NON-NLS-1$ 427 assertEquals("Wrong flag", IDelta.DEPRECATION, child.getFlags()); //$NON-NLS-1$ 428 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 429 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 430 } 431 /** 432 * Removed deprecation 433 */ 434 @Test test11()435 public void test11() { 436 deployBundles("test11"); //$NON-NLS-1$ 437 IApiBaseline before = getBeforeState(); 438 IApiBaseline after = getAfterState(); 439 IApiComponent beforeApiComponent = before.getApiComponent(BUNDLE_NAME); 440 assertNotNull("no api component", beforeApiComponent); //$NON-NLS-1$ 441 IApiComponent afterApiComponent = after.getApiComponent(BUNDLE_NAME); 442 assertNotNull("no api component", afterApiComponent); //$NON-NLS-1$ 443 IDelta delta = ApiComparator.compare(beforeApiComponent, afterApiComponent, before, after, VisibilityModifiers.API, null); 444 assertNotNull("No delta", delta); //$NON-NLS-1$ 445 IDelta[] allLeavesDeltas = collectLeaves(delta); 446 assertEquals("Wrong size", 1, allLeavesDeltas.length); //$NON-NLS-1$ 447 IDelta child = allLeavesDeltas[0]; 448 assertEquals("Wrong kind", IDelta.REMOVED, child.getKind()); //$NON-NLS-1$ 449 assertEquals("Wrong flag", IDelta.DEPRECATION, child.getFlags()); //$NON-NLS-1$ 450 assertEquals("Wrong element type", IDelta.ANNOTATION_ELEMENT_TYPE, child.getElementType()); //$NON-NLS-1$ 451 assertTrue("Not compatible", DeltaProcessor.isCompatible(child)); //$NON-NLS-1$ 452 } 453 } 454