blob: 95f8135b4c027c9b31973330b47e75198c0d9b59 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 Progress Software
* 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.jst.ws.jaxb.core.tests;
import javax.xml.bind.annotation.XmlSchema;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
public class RemoveAnnotationFromPackageTest extends AbstractAnnotationTest {
@Override
public String getPackageName() {
return "com.example";
}
@Override
public String getClassName() {
return "package-info.java";
}
@Override
public String getClassContents() {
StringBuilder classContents = new StringBuilder("@XmlSchema\n\n");
classContents.append("package com.example;\n\n");
classContents.append("import javax.xml.bind.annotation.XmlSchema;\n\n");
return classContents.toString();
}
@Override
public Annotation getAnnotation() {
return AnnotationsCore.createAnnotation(ast, XmlSchema.class, XmlSchema.class.getSimpleName(),
null);
}
public void testRemoveAnnotationFromPackage() {
try {
assertNotNull(annotation);
assertEquals(XmlSchema.class.getSimpleName(), AnnotationUtils.getAnnotationName(annotation));
IPackageDeclaration myPackage = source.getPackageDeclaration(getPackageName());
assertNotNull(myPackage);
assertTrue(AnnotationUtils.isAnnotationPresent(myPackage, AnnotationUtils
.getAnnotationName(annotation)));
AnnotationUtils.removeAnnotationFromPackageDeclaration(source, compilationUnit.getPackage(), rewriter, annotation,
textFileChange);
assertTrue(executeChange(new NullProgressMonitor(), textFileChange));
assertFalse(AnnotationUtils.isAnnotationPresent(myPackage, AnnotationUtils
.getAnnotationName(annotation)));
} catch (CoreException ce) {
fail(ce.getLocalizedMessage());
}
}
}