blob: 4f821fc9f81e8c3cc9179e017c4b4ccfe9199fc3 [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
*
* Contributors:
* Shane Clarke - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.ws.jaxb.core.tests;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlSchema;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jst.ws.annotations.core.AnnotationsCore;
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
public class AddAnnotationToPackageTest extends AbstractAnnotationTest {
@Override
public String getPackageName() {
return "com.example";
}
@Override
public String getClassName() {
return "package-info.java";
}
@Override
public String getClassContents() {
return "package com.example;\n";
}
@Override
public Annotation getAnnotation() {
List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
MemberValuePair locationVP = AnnotationsCore.createStringMemberValuePair(ast,
"location", "uri:someSchema");
MemberValuePair namespaceVP = AnnotationsCore.createStringMemberValuePair(ast,
"namespace", "uri:testNS");
memberValuePairs.add(locationVP);
memberValuePairs.add(namespaceVP);
return AnnotationsCore.createAnnotation(ast, XmlSchema.class, XmlSchema.class.getSimpleName(),
memberValuePairs);
}
public void testAddAnnotationToPackage() {
try {
assertNotNull(annotation);
assertEquals(XmlSchema.class.getSimpleName(), AnnotationUtils.getAnnotationName(annotation));
IPackageDeclaration myPackage = source.getPackageDeclaration(getPackageName());
assertNotNull(myPackage);
AnnotationUtils.addAnnotationToPackageDeclaration(source, compilationUnit.getPackage(), rewriter, annotation, textFileChange);
AnnotationUtils.addImportEdit(compilationUnit, XmlSchema.class, textFileChange, true);
assertTrue(executeChange(new NullProgressMonitor(), textFileChange));
assertTrue(AnnotationUtils.isAnnotationPresent(myPackage, AnnotationUtils
.getAnnotationName(annotation)));
} catch (CoreException ce) {
fail(ce.getLocalizedMessage());
}
}
}